コード例 #1
0
        public void AllowsCreatingContextWithoutSettingAccessor()
        {
            // Arrange
            var services = new ServiceCollection()
                           .AddOptions()
                           .BuildServiceProvider();
            var contextFactory = new DefaultProtoContextFactory(services);

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

            contextFactory.Dispose(context);
        }
コード例 #2
0
        public void CreateProtoContextSetsProtoContextAccessor()
        {
            // Arrange
            var services = new ServiceCollection()
                           .AddOptions()
                           .AddProtoContextAccessor()
                           .BuildServiceProvider();
            var accessor       = services.GetRequiredService <IProtoContextAccessor>();
            var contextFactory = new DefaultProtoContextFactory(services);

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

            // Assert
            Assert.Same(context, accessor.ProtoContext);
        }
コード例 #3
0
        public void SetsDefaultPropertiesOnProtoContext()
        {
            // Arrange
            var services = new ServiceCollection()
                           .AddOptions()
                           .BuildServiceProvider();
            var contextFactory = new DefaultProtoContextFactory(services);

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

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

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