public void AddRazorPagesOptions_AddsConventions()
        {
            // Arrange
            var services = new ServiceCollection().AddOptions()
                           .AddSingleton <IConfigureOptions <RazorPagesOptions>, RazorPagesOptionsSetup>();
            var applicationModelConvention = Mock.Of <IPageApplicationModelConvention>();
            var routeModelConvention       = Mock.Of <IPageRouteModelConvention>();
            var builder = new MvcBuilder(services, new ApplicationPartManager());

            builder.AddRazorPagesOptions(options =>
            {
                options.Conventions.Add(applicationModelConvention);
                options.Conventions.Add(routeModelConvention);
            });
            var serviceProvider = services.BuildServiceProvider();
            var accessor        = serviceProvider.GetRequiredService <IOptions <RazorPagesOptions> >();

            // Act & Assert
            var conventions = accessor.Value.Conventions;

            // Assert
            Assert.Collection(
                conventions,
                convention => Assert.Same(applicationModelConvention, convention),
                convention => Assert.Same(routeModelConvention, convention));
        }
예제 #2
0
        public void AddViewComponentsAsServices_RegistersDiscoveredViewComponents()
        {
            // Arrange
            var services = new ServiceCollection();

            var manager = new ApplicationPartManager();

            manager.ApplicationParts.Add(new TestApplicationPart(
                                             typeof(ConventionsViewComponent),
                                             typeof(AttributeViewComponent)));

            manager.FeatureProviders.Add(new TestProvider());

            var builder = new MvcBuilder(services, manager);

            // Act
            builder.AddViewComponentsAsServices();

            // Assert
            var collection = services.ToList();

            Assert.Equal(3, collection.Count);

            Assert.Equal(typeof(ConventionsViewComponent), collection[0].ServiceType);
            Assert.Equal(typeof(ConventionsViewComponent), collection[0].ImplementationType);
            Assert.Equal(ServiceLifetime.Transient, collection[0].Lifetime);

            Assert.Equal(typeof(AttributeViewComponent), collection[1].ServiceType);
            Assert.Equal(typeof(AttributeViewComponent), collection[1].ImplementationType);
            Assert.Equal(ServiceLifetime.Transient, collection[1].Lifetime);

            Assert.Equal(typeof(IViewComponentActivator), collection[2].ServiceType);
            Assert.Equal(typeof(ServiceBasedViewComponentActivator), collection[2].ImplementationType);
            Assert.Equal(ServiceLifetime.Singleton, collection[2].Lifetime);
        }
예제 #3
0
        private static MvcBuilder CreateBuilder()
        {
            var services = new ServiceCollection();
            var manager  = new ApplicationPartManager();
            var builder  = new MvcBuilder(services, manager);

            return(builder);
        }