Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }