public async Task InvokesMiddleware() { var invocationCount = 0; _app.UseOwin(pipeline => pipeline .Use(environment => { invocationCount++; return(Task.CompletedTask); })); var requestDelegate = _app.Build(); await requestDelegate.Invoke(new DefaultHttpContext()); invocationCount.Should().Be(1); }
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."); }