Esempio n. 1
0
        public void CreateScope_1()
        {
            var accessor     = Substitute.For <IHttpContextAccessor>();
            var scopeFactory = Substitute.For <IServiceScopeFactory>();
            var factory      = new HttpContextServiceScopeFactory(accessor, scopeFactory);

            using (var scope = Should.NotThrow(() => factory.CreateScope()))
            {
                scope.ServiceProvider.ShouldBe(accessor.HttpContext.RequestServices);
            }
        }
Esempio n. 2
0
        public void CreateScope_2()
        {
            var accessor = Substitute.For <IHttpContextAccessor>();

            accessor.HttpContext.Returns((HttpContext)null);
            var scopeFactory = Substitute.For <IServiceScopeFactory>();
            var serviceScope = Substitute.For <IServiceScope>();

            scopeFactory.CreateScope().Returns(serviceScope);
            var factory = new HttpContextServiceScopeFactory(accessor, scopeFactory);

            Should.NotThrow(() => factory.CreateScope()).ShouldBe(serviceScope);
        }