public async void AddsAutofacDependencyScopeToHttpRequestMessage()
        {
            var request = new HttpRequestMessage();
            var context = new OwinContext();
            request.Properties.Add("MS_OwinContext", context);

            var container = new ContainerBuilder().Build();
            context.Set(Constants.OwinLifetimeScopeKey, container);

            var fakeHandler = new FakeInnerHandler { Message = new HttpResponseMessage(HttpStatusCode.OK) };
            var handler = new DependencyScopeHandler { InnerHandler = fakeHandler };
            var invoker = new HttpMessageInvoker(handler);
            await invoker.SendAsync(request, new CancellationToken());

            var scope = (AutofacWebApiDependencyScope)request.Properties[HttpPropertyKeys.DependencyScope];

            Assert.Equal(container, scope.LifetimeScope);
        }
Пример #2
0
        public async void AddsAutofacDependencyScopeToHttpRequestMessage()
        {
            var request = new HttpRequestMessage();
            var context = new OwinContext();

            request.Properties.Add("MS_OwinContext", context);

            var container = new ContainerBuilder().Build();

            context.Set(Constants.OwinLifetimeScopeKey, container);

            var fakeHandler = new FakeInnerHandler {
                Message = new HttpResponseMessage(HttpStatusCode.OK)
            };
            var handler = new DependencyScopeHandler {
                InnerHandler = fakeHandler
            };
            var invoker = new HttpMessageInvoker(handler);
            await invoker.SendAsync(request, new CancellationToken());

            var scope = (AutofacWebApiDependencyScope)request.Properties[HttpPropertyKeys.DependencyScope];

            Assert.Equal(container, scope.LifetimeScope);
        }