public void DisposeScopeOnAppDisposingDoesNothingWhenNoTokenPresent() { var app = new AppBuilder(); var scope = new TestableLifetimeScope(); // XUnit doesn't have Assert.DoesNotThrow app.DisposeScopeOnAppDisposing(scope); }
public void DisposeScopeOnAppDisposing() { var app = new AppBuilder(); var tcs = new CancellationTokenSource(); var scope = new TestableLifetimeScope(); app.Properties.Add("host.OnAppDisposing", tcs.Token); app.DisposeScopeOnAppDisposing(scope); tcs.Cancel(); Assert.True(scope.ScopeIsDisposed); }
public async void UseAutofacLifetimeScopeInjectorWithExternalScopeDoesntDisposeIt() { var lifetimeScope = new TestableLifetimeScope(); using (var server = TestServer.Create(app => { app.UseAutofacLifetimeScopeInjector(ctx => lifetimeScope); app.Run(context => context.Response.WriteAsync("Hello, world!")); })) { await server.HttpClient.GetAsync("/"); } Assert.False(lifetimeScope.ScopeIsDisposed); }
public async void UseAutofacLifetimeScopeInjectorWithExternalScopeAddsItToOwinContext() { var lifetimeScope = new TestableLifetimeScope(); using (var server = TestServer.Create(app => { app.UseAutofacLifetimeScopeInjector(ctx => lifetimeScope); app.Use <TestMiddleware>(); app.Run(context => context.Response.WriteAsync("Hello, world!")); })) { await server.HttpClient.GetAsync("/"); Assert.Same(lifetimeScope, TestMiddleware.LifetimeScope); } }
public async void UseAutofacLifetimeScopeInjectorDoesntDisposeScopeSetBySetAutofacLifetimeScope() { var lifetimeScope = new TestableLifetimeScope(); using (var server = TestServer.Create(app => { app.Use((ctx, next) => { ctx.SetAutofacLifetimeScope(lifetimeScope); return(next()); }); app.UseAutofacLifetimeScopeInjector(new Mock <ILifetimeScope>(MockBehavior.Strict).Object); app.Use <TestMiddleware>(); app.Run(context => context.Response.WriteAsync("Hello, world!")); })) { await server.HttpClient.GetAsync("/"); } Assert.False(lifetimeScope.ScopeIsDisposed); }
public async void UseAutofacLifetimeScopeInjectorDoesntOverrideScopeSetBySetAutofacLifetimeScope() { var lifetimeScope = new TestableLifetimeScope(); using (var server = TestServer.Create(app => { app.Use((ctx, next) => { ctx.SetAutofacLifetimeScope(lifetimeScope); return(next()); }); //we don't expect anything to be called on this one, so we want it to fail app.UseAutofacLifetimeScopeInjector(new Mock <ILifetimeScope>(MockBehavior.Strict).Object); app.Use <TestMiddleware>(); app.Run(context => context.Response.WriteAsync("Hello, world!")); })) { await server.HttpClient.GetAsync("/"); Assert.Same(lifetimeScope, TestMiddleware.LifetimeScope); } }