Example #1
0
        public void ConfigureApiBehaviorOptions_InvokesSetupAction()
        {
            // Arrange
            var serviceCollection = new ServiceCollection()
                                    .AddOptions();

            var builder = new MvcCoreBuilder(
                serviceCollection,
                new ApplicationPartManager());

            var part = new TestApplicationPart();

            // Act
            var result = builder.ConfigureApiBehaviorOptions(o =>
            {
                o.SuppressMapClientErrors = true;
            });

            // Assert
            var options = serviceCollection.
                          BuildServiceProvider()
                          .GetRequiredService <IOptions <ApiBehaviorOptions> >()
                          .Value;

            Assert.True(options.SuppressMapClientErrors);
        }
            public void ConfigureServices(IServiceCollection services)
            {
                var testControllers = new TestApplicationPart(
                    typeof(VersionedMetadataController),
                    typeof(TestsController),
                    typeof(TestsController2),
                    typeof(TestsController3));

                services.AddMvc()
                .ConfigureApplicationPartManager(m => m.ApplicationParts.Add(testControllers));

                services.AddApiVersioning()
                .AddOData()
                .EnableApiVersioning();
            }
Example #3
0
            public void ConfigureServices(IServiceCollection services)
            {
                var testControllers = new TestApplicationPart(
                    typeof(VersionedMetadataController),
                    typeof(TestsController),
                    typeof(Tests2Controller),
                    typeof(Tests3Controller));

                services.AddMvc(options => options.EnableEndpointRouting = false)
                .ConfigureApplicationPartManager(m => m.ApplicationParts.Add(testControllers));

                services.AddApiVersioning()
                .AddOData()
                .EnableApiVersioning();
            }
Example #4
0
        static ApplicationBuilder NewApplicationBuilder()
        {
            var services        = new ServiceCollection();
            var testControllers = new TestApplicationPart(
                typeof(TestsController),
                typeof(TestsController2),
                typeof(TestsController3));

            services.AddLogging();
            services.Add(Singleton(new DiagnosticListener("test")));
            services.AddMvcCore(options => options.EnableEndpointRouting = false)
            .ConfigureApplicationPartManager(apm => apm.ApplicationParts.Add(testControllers));
            services.AddApiVersioning();
            services.AddOData().EnableApiVersioning();

            return(new ApplicationBuilder(services.BuildServiceProvider()));
        }
Example #5
0
        static ApplicationBuilder NewApplicationBuilder()
        {
            var services        = new ServiceCollection();
            var testControllers = new TestApplicationPart(
                typeof(TestsController),
                typeof(TestsController2),
                typeof(TestsController3));

            services.AddLogging();
            services.Add(Singleton <DiagnosticSource>(new DiagnosticListener("test")));
            services.Add(Singleton(Options.Create(new MvcOptions())));
            services.AddMvcCore().ConfigureApplicationPartManager(m => m.ApplicationParts.Add(testControllers));
            services.AddApiVersioning();
            services.AddOData().EnableApiVersioning();

            return(new ApplicationBuilder(services.BuildServiceProvider()));
        }
Example #6
0
        public void ConfigureApplicationParts_InvokesSetupAction()
        {
            // Arrange
            var builder = new MvcCoreBuilder(
                Mock.Of <IServiceCollection>(),
                new ApplicationPartManager());

            var part = new TestApplicationPart();

            // Act
            var result = builder.ConfigureApplicationPartManager(manager =>
            {
                manager.ApplicationParts.Add(part);
            });

            // Assert
            Assert.Same(result, builder);
            Assert.Equal(new ApplicationPart[] { part }, builder.PartManager.ApplicationParts.ToArray());
        }
        public void ConfigureApplicationParts_InvokesSetupAction()
        {
            // Arrange
            var builder = new MvcCoreBuilder(
                Mock.Of<IServiceCollection>(),
                new ApplicationPartManager());

            var part = new TestApplicationPart();

            // Act
            var result = builder.ConfigureApplicationPartManager(manager =>
            {
                manager.ApplicationParts.Add(part);
            });

            // Assert
            Assert.Same(result, builder);
            Assert.Equal(new ApplicationPart[] { part }, builder.PartManager.ApplicationParts.ToArray());
        }
Example #8
0
        public void populate_feature_should_discover_valid_model_configurations()
        {
            // arrange
            var part = new TestApplicationPart(
                typeof(ValueTypeModelConfiguration),
                typeof(PrivateModelConfiguration),
                typeof(AbstractModelConfiguration),
                typeof(GenericModelConfiguration <>),
                typeof(PublicModelConfiguration));
            var partManager = new ApplicationPartManager();
            var provider    = new ModelConfigurationFeatureProvider();
            var feature     = new ModelConfigurationFeature();

            partManager.ApplicationParts.Add(part);

            // act
            provider.PopulateFeature(partManager.ApplicationParts, feature);

            // assert
            feature.ModelConfigurations.Should().Equal(new[] { typeof(PublicModelConfiguration).GetTypeInfo() });
        }