Exemple #1
0
        public void Make_sure_filter_is_added_to_mvc()
        {
            MvcOptions mvcOptions = null;

            // Arrange
            var factory = new SelfContainedWebApplicationFactoryWithWebHost <When_configuring_Mvc_support>
                          (
                configureServices: services =>
            {
                services.AddMvc(options => mvcOptions = options);
                services.AddViewModelComposition(options =>
                {
                    options.AddMvcSupport();
                });
            },
                configure: app =>
            {
                app.UseMvc();
            }
                          );

            // Act
            factory.CreateClient();

            // Assert
            var registeredFilter = mvcOptions
                                   .Filters
                                   .SingleOrDefault(f =>
            {
                return(f is TypeFilterAttribute tfa &&
                       tfa.ImplementationType == typeof(CompositionActionFilter));
            });

            Assert.NotNull(registeredFilter);
        }
Exemple #2
0
        public void Should_not_register_duplicated_handlers()
        {
            IServiceProvider container = null;
            // Arrange
            var factory = new SelfContainedWebApplicationFactoryWithWebHost <When_assembly_scanning>
                          (
                configureServices: services =>
            {
                services.AddViewModelComposition();
                services.AddRouting();
            },
                configure: app =>
            {
                container = app.ApplicationServices;
                app.RunCompositionGatewayWithDefaultRoutes();
            }
                          );

            factory.CreateClient();

            var handler = container.GetServices <IInterceptRoutes>()
                          .SingleOrDefault(svc => svc is SampleNeverInvokedHandler);

            Assert.NotNull(handler);
        }
        public void Options_customization_can_access_configuration_if_set()
        {
            // Arrange
            var config  = new FakeConfig();
            var factory = new SelfContainedWebApplicationFactoryWithWebHost <When_using_assembly_scanner>
                          (
                configureServices: services =>
            {
                services.AddViewModelComposition(options =>
                {
                    options.TypesFilter = type =>
                    {
                        if (type.Assembly.FullName.Contains("TestClassLibraryWithHandlers"))
                        {
                            return(true);
                        }

                        if (type == typeof(EmptyCustomizations))
                        {
                            return(false);
                        }

                        if (type.IsNestedTypeOf <When_using_assembly_scanner>())
                        {
                            return(true);
                        }

                        return(false);
                    };
                }, config);
                services.AddRouting();
            },
                configure: app =>
            {
                app.UseRouting();
                app.UseEndpoints(builder => builder.MapCompositionHandlers());
            }
                          );

            // Act
            var client = factory.CreateClient();

            // Assert
            Assert.Same(config, _customizationsThatAccessTheConfigurationConfig);
        }
Exemple #4
0
        public void Should_not_fail_due_to_invalid_assemblies()
        {
            // Arrange
            var factory = new SelfContainedWebApplicationFactoryWithWebHost <When_assembly_scanning>
                          (
                configureServices: services =>
            {
                services.AddViewModelComposition();
                services.AddRouting();
            },
                configure: app =>
            {
                app.RunCompositionGatewayWithDefaultRoutes();
            }
                          );

            factory.CreateClient();
        }
Exemple #5
0
        public void Should_fail_if_no_mvc_is_configured()
        {
            Assert.Throws <InvalidOperationException>(() =>
            {
                // Arrange
                var factory = new SelfContainedWebApplicationFactoryWithWebHost <When_configuring_Mvc_support>
                              (
                    configureServices: services =>
                {
                    services.AddViewModelComposition(options =>
                    {
                        options.AddMvcSupport();
                    });
                },
                    configure: app =>
                {
                    app.UseMvc();
                }
                              );

                // Act
                factory.CreateClient();
            });
        }