Example #1
0
        public void DisposeScopeOnAppDisposingDoesNothingWhenNoTokenPresent()
        {
            var app   = new AppBuilder();
            var scope = new TestableLifetimeScope();

            // XUnit doesn't have Assert.DoesNotThrow
            app.DisposeScopeOnAppDisposing(scope);
        }
        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);
        }
Example #4
0
        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);
        }
Example #5
0
        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);
        }
Example #6
0
        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);
            }
        }
Example #7
0
        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);
        }
Example #8
0
        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);
            }
        }