public void GivenNullOptions_UsesDefaultOptions() { OwinRequestScopeContextOptions nullOptions = null; _app.UseRequestScopeContext(nullOptions); A.CallTo(() => _app.Use(typeof(OwinRequestScopeContextMiddleware), OwinRequestScopeContextOptions.Default)) .MustHaveHappened(); }
public virtual void SetUp() { _next = owinEnvironment => Task.CompletedTask; _options = new OwinRequestScopeContextOptions { ItemKeyEqualityComparer = StringComparer.OrdinalIgnoreCase }; _sut = new OwinRequestScopeContextMiddleware(_next, _options); }
public void UsesExpectedMiddlewareWithSpecifiedOptions() { var options = new OwinRequestScopeContextOptions { ItemKeyEqualityComparer = StringComparer.Ordinal }; _app.UseRequestScopeContext(options); A.CallTo(() => _app.Use(typeof(OwinRequestScopeContextMiddleware), options)).MustHaveHappened(); }
private static MidFunc UseRequestScopeContext(OwinRequestScopeContextOptions options = null) { options = options ?? OwinRequestScopeContextOptions.Default; return (next => async environment => { var middleware = new OwinRequestScopeContextMiddleware(next, options); await middleware.Invoke(environment); }); }
public async Task GivenNullOptions_UseDefaultOptions() { OwinRequestScopeContextOptions nullOptions = null; _app.UseOwin(pipeline => pipeline .UseRequestScopeContext(nullOptions) .Use(environment => { var typed = OwinRequestScopeContext.Current as OwinRequestScopeContext; typed.Options.Should().Be(OwinRequestScopeContextOptions.Default); return(Task.CompletedTask); })); var requestDelegate = _app.Build(); await requestDelegate.Invoke(new DefaultHttpContext()); }
public async Task GivenOptions_InitializesContextWithGivenOptions() { OwinRequestScopeContextOptions interceptedOptions = null; IEqualityComparer <string> interceptedKeyComparer = null; var sut = new OwinRequestScopeContextMiddleware(owinEnvironment => { interceptedOptions = ((OwinRequestScopeContext)OwinRequestScopeContext.Current).Options; interceptedKeyComparer = ((OwinRequestScopeContextItems)OwinRequestScopeContext.Current.Items).KeyComparer; return(Task.CompletedTask); }, _options); await sut.Invoke(_owinEnvironment).ConfigureAwait(false); interceptedOptions.Should().NotBeNull(); interceptedOptions.ItemKeyEqualityComparer.Should().Be(_options.ItemKeyEqualityComparer); interceptedKeyComparer.Should().NotBeNull(); interceptedKeyComparer.Should().Be(_options.ItemKeyEqualityComparer); }
public async Task UseSpecifiedOptions() { var options = new OwinRequestScopeContextOptions { ItemKeyEqualityComparer = StringComparer.Ordinal }; _app.UseOwin(pipeline => pipeline .UseRequestScopeContext(options) .Use(environment => { var typed = OwinRequestScopeContext.Current as OwinRequestScopeContext; typed.Options.Should().Be(options); return(Task.CompletedTask); })); var requestDelegate = _app.Build(); await requestDelegate.Invoke(new DefaultHttpContext()); }
internal OwinRequestScopeContext( IDictionary <string, object> owinEnvironment, IOwinRequestScopeContextItems items, OwinRequestScopeContextOptions options) { if (items == null) { throw new ArgumentNullException(nameof(items)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } Items = items; Options = options; OwinEnvironment = new ReadOnlyDictionary <string, object>(owinEnvironment); }
public async Task CreatesRequestScopeContext() { var options = new OwinRequestScopeContextOptions { ItemKeyEqualityComparer = StringComparer.Ordinal }; _app.UseOwin(pipeline => pipeline .Use(environment => { OwinRequestScopeContext.Current.Should().BeNull("No current context should exist before the middleware is called."); return(Task.CompletedTask); }) .UseRequestScopeContext(options) .Use(environment => { OwinRequestScopeContext.Current.Should().NotBeNull("The middleware should initialize the current context."); return(Task.CompletedTask); })); var requestDelegate = _app.Build(); await requestDelegate.Invoke(new DefaultHttpContext()); OwinRequestScopeContext.Current.Should().BeNull("The current context should be null when not in the context of a request."); }
public static IAppBuilder UseRequestScopeContext(this IAppBuilder app, OwinRequestScopeContextOptions options = null) { return(app.Use(typeof(OwinRequestScopeContextMiddleware), options ?? OwinRequestScopeContextOptions.Default)); }
public static Action <MidFunc> UseRequestScopeContext(this Action <MidFunc> builder, OwinRequestScopeContextOptions options = null) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } builder(UseRequestScopeContext(options).Invoke); return(builder); }
public OwinRequestScopeContextMiddleware(Func <IDictionary <string, object>, Task> next, OwinRequestScopeContextOptions options) { _next = next; _options = options; }