Esempio n. 1
0
        public void AllowsCreatingContextWithoutSettingAccessor()
        {
            // Arrange
            var services = new ServiceCollection()
                           .AddOptions()
                           .BuildServiceProvider();
            var contextFactory = new DefaultHttpContextFactory(services);

            // Act & Assert
            var context = contextFactory.Create(new FeatureCollection());

            contextFactory.Dispose(context);
        }
Esempio n. 2
0
        public void CreateHttpContextSetsHttpContextAccessor()
        {
            // Arrange
            var services = new ServiceCollection()
                           .AddOptions()
                           .AddHttpContextAccessor()
                           .BuildServiceProvider();
            var accessor       = services.GetRequiredService <IHttpContextAccessor>();
            var contextFactory = new DefaultHttpContextFactory(services);

            // Act
            var context = contextFactory.Create(new FeatureCollection());

            // Assert
            Assert.Same(context, accessor.HttpContext);
        }
Esempio n. 3
0
        public void SetsDefaultPropertiesOnHttpContext()
        {
            // Arrange
            var services = new ServiceCollection()
                           .AddOptions()
                           .BuildServiceProvider();
            var contextFactory = new DefaultHttpContextFactory(services);

            // Act & Assert
            var context = contextFactory.Create(new FeatureCollection()) as DefaultHttpContext;

            Assert.NotNull(context);
            Assert.NotNull(context.FormOptions);
            Assert.NotNull(context.ServiceScopeFactory);

            Assert.Same(services.GetRequiredService <IServiceScopeFactory>(), context.ServiceScopeFactory);
        }