Beispiel #1
0
        public void WhenSettingsDerived_LoadsBaseAndDerivedProperties()
        {
            ContainerSetup
            .Arrange((TestTypeResolver resolver) =>
            {
                resolver.DefaultSettingsConfig();
                resolver.AddPlugin <MockCorePlugin>().AddPluginType <MockDerivedSettings>();
            })

            .Test(c =>
            {
                c.WithConfig <EnvironmentConfig>(settings => {
                    AddInMemorySettings(settings);
                });

                c.Build();
            },
                  (IAppContainer c) =>
            {
                var settings = c.Services.Resolve <MockDerivedSettings>();
                settings.Should().NotBeNull();

                settings.Height.Should().Be(20);
                settings.Width.Should().Be(50);
                settings.Dialog.Colors.Frame.Should().Be("RED");
                settings.Dialog.Colors.Title.Should().Be("DARK_RED");
            });
        }
Beispiel #2
0
 public void HostSpecifiedServices_Registered()
 {
     ContainerSetup
     .Arrange((TestTypeResolver config) =>
     {
         config.AddPlugin <MockAppHostPlugin>();
     })
     .Test(c =>
     {
         c.WithConfig <AutofacRegistrationConfig>(rc =>
         {
             rc.Build = builder =>
             {
                 builder.RegisterType <MockHostServiceType>()
                 .As <IMockHostServiceType>();
             };
         });
         c.Build();
     },
           (IAppContainer c) =>
     {
         var hostRegistration = c.Services.Resolve <IMockHostServiceType>();
         hostRegistration.Should().NotBeNull();
         hostRegistration.Should().BeOfType <MockHostServiceType>();
     });
 }
Beispiel #3
0
        public void CorePluginsComposed_FromAllOtherPluginTypes()
        {
            ContainerSetup
            .Arrange((TestTypeResolver config) =>
            {
                config.AddPlugin <MockAppHostPlugin>()
                .AddPluginType <MockTypeOneBasedOnKnownType>();

                config.AddPlugin <MockAppComponentPlugin>()
                .AddPluginType <MockTypeTwoBasedOnKnownType>();

                config.AddPlugin <MockCorePlugin>()
                .AddPluginType <MockTypeThreeBasedOnKnownType>();

                // This core plug-in contains a module that is composed
                // from types contained within the above plug-ins.
                config.AddPlugin <MockCorePlugin>()
                .AddPluginType <MockComposedModule>();
            })
            .Test(
                c => c.Build(),
                (MockComposedModule m) =>
            {
                m.ImportedTypes.Should().NotBeNull();
                m.ImportedTypes.Should().HaveCount(3);
                m.ImportedTypes.OfType <MockTypeOneBasedOnKnownType>().Should().HaveCount(1);
                m.ImportedTypes.OfType <MockTypeTwoBasedOnKnownType>().Should().HaveCount(1);
                m.ImportedTypes.OfType <MockTypeThreeBasedOnKnownType>().Should().HaveCount(1);
            });
        }
Beispiel #4
0
        public void ModulesUsedTo_BootstrapPlugin()
        {
            Action <Plugin, Type> assertOneModule = (p, type) => p.PluginModules.Should()
                                                    .HaveCount(1)
                                                    .And.Subject.First().Should().BeOfType(type);

            ContainerSetup
            .Arrange((TestTypeResolver config) =>
            {
                config.AddPlugin <MockAppHostPlugin>()
                .AddPluginType <MockPluginOneModule>();

                config.AddPlugin <MockAppComponentPlugin>()
                .AddPluginType <MockPluginTwoModule>();

                config.AddPlugin <MockCorePlugin>()
                .AddPluginType <MockPluginThreeModule>();
            })
            .Test(
                c => c.Build(),
                (CompositeApplication ca) =>
            {
                assertOneModule(ca.AppHostPlugin, typeof(MockPluginOneModule));
                assertOneModule(ca.AppComponentPlugins.First(), typeof(MockPluginTwoModule));
                assertOneModule(ca.CorePlugins.First(), typeof(MockPluginThreeModule));
            });
        }
Beispiel #5
0
        public void ComponentCanBeNotified_OnCreation()
        {
            ContainerSetup
            .Arrange((TestTypeResolver config) =>
            {
                config.AddPlugin <MockAppHostPlugin>()
                .AddPluginType <MockActivatedType>();
            })
            .Test(c =>
            {
                c.WithConfig <AutofacRegistrationConfig>(rc =>
                {
                    rc.Build = (bdr) => bdr.RegisterType <MockActivatedType>()
                               .NotifyOnActivating()
                               .AsSelf()
                               .SingleInstance();
                });

                c.Build();
            },
                  (IAppContainer c) =>
            {
                var comp = c.Services.Resolve <MockActivatedType>();
                comp.Should().NotBeNull();
                comp.IsActivated.Should().BeTrue();
            });
        }
Beispiel #6
0
        public void TypesLoaded_ForAppComponentPlugin()
        {
            ContainerSetup
            .Arrange((TestTypeResolver config) =>
            {
                config.AddPlugin <MockAppHostPlugin>();

                config.AddPlugin <MockAppComponentPlugin>()
                .AddPluginType <MockOneType>();
            })
            .Test(
                c => c.Build(),
                (CompositeApplication ca) =>
            {
                var appComponentPlugin = ca.AppComponentPlugins.First();

                // Type assignment:
                appComponentPlugin.PluginTypes.Should().HaveCount(1);
                appComponentPlugin.PluginTypes.Select(pt => pt.Type).Contains(typeof(MockOneType));

                // Categorized Types:
                ca.GetPluginTypes().Should().HaveCount(1);
                ca.GetPluginTypes(PluginTypes.AppComponentPlugin).Should().HaveCount(1);
                ca.GetPluginTypes(PluginTypes.CorePlugin, PluginTypes.AppHostPlugin).Should().HaveCount(0);
            });
        }
Beispiel #7
0
        public void CanReadSpecificSettingValue_FromConfiguration()
        {
            ContainerSetup
            .Arrange((TestTypeResolver config) =>
            {
                config.DefaultSettingsConfig();
                config.AddPlugin <MockCorePlugin>().AddPluginType <MockSetttings>();
            })

            .Test(c =>
            {
                c.WithConfig <EnvironmentConfig>(settings => {
                    AddInMemorySettings(settings);
                });

                c.Build();
            },
                  (IAppContainer c) =>
            {
                var configuration = c.Services.Resolve <IConfiguration>();

                int width = configuration.GetValue <int>("App:MainWindow:Width");
                width.Should().Be(50);
            });
        }
Beispiel #8
0
        public void CanInjectSettings_DirectlyIntoConsumer()
        {
            ContainerSetup
            .Arrange((TestTypeResolver resolver) =>
            {
                resolver.DefaultSettingsConfig();
                resolver.AddPlugin <MockCorePlugin>().AddPluginType <MockSetttings>();
            })

            .Test(c =>
            {
                c.WithConfig <EnvironmentConfig>(settings => {
                    AddInMemorySettings(settings);
                });

                c.Build();
            },
                  (IAppContainer c) =>
            {
                var settings = c.Services.Resolve <MockSetttings>();
                settings.Should().NotBeNull();

                settings.Height.Should().Be(20);
                settings.Width.Should().Be(50);
            });
        }
        public Task ExceptionsRecorded_ForEachEventHandler()
        {
            return(ContainerSetup.Arrange((TestTypeResolver config) => {
                config.AddPlugin <MockAppHostPlugin>()
                .AddPluginType <MockDomainEvent>()
                .AddPluginType <MockErrorMessageConsumer>();

                config.AddPlugin <MockCorePlugin>()
                .UseMessagingPlugin();
            })
                   .Test(async c =>
            {
                c.WithConfig <AutofacRegistrationConfig>(regConfig =>
                {
                    regConfig.Build = builder =>
                    {
                        builder.RegisterType <NullEntityScriptingService>()
                        .As <IEntityScriptingService>()
                        .SingleInstance();
                    };
                });

                c.Build();

                var srv = c.Services.Resolve <IMessagingService>();
                var evt = new MockDomainEvent();
                await srv.PublishAsync(evt);
            },
                         (c, e) =>
            {
                e.Should().NotBeNull();
                e.Should().BeOfType <PublisherException>();
            }));
        }
Beispiel #10
0
        public void AppPluginsComposed_FromOnlyOtherAppPluginTypes()
        {
            ContainerSetup
            .Arrange((TestTypeResolver config) =>
            {
                config.AddPlugin <MockAppHostPlugin>()
                .AddPluginType <MockTypeOneBasedOnKnownType>();

                config.AddPlugin <MockCorePlugin>()
                .AddPluginType <MockTypeThreeBasedOnKnownType>();

                config.AddPlugin <MockCorePlugin>()
                .AddPluginType <MockTypeTwoBasedOnKnownType>();

                config.AddPlugin <MockAppComponentPlugin>()
                .AddPluginType <MockComposedModule>();
            })
            .Test(
                c => c.Build(),
                (MockComposedModule m) =>
            {
                m.ImportedTypes.Should().NotBeNull();
                m.ImportedTypes.Should().HaveCount(1);
                m.ImportedTypes.OfType <MockTypeOneBasedOnKnownType>().Should().HaveCount(1);
            });
        }
Beispiel #11
0
 public void Must_Have_One_AppHostPlugin()
 {
     ContainerSetup
     .Arrange((TestTypeResolver config) => { })
     .Test(
         c => c.Build(),
         (c, e) =>
     {
         e.Should().BeOfType <ContainerException>();
     });
 }
Beispiel #12
0
 public void Composite_Application_Has_AppHost_Plugin()
 {
     ContainerSetup
     .Arrange((TestTypeResolver config) =>
     {
         config.AddPlugin <MockAppHostPlugin>();
     })
     .Test(
         c => c.Build(),
         (CompositeApplication ca) => ca.AppHostPlugin.Should().NotBeNull());
 }
Beispiel #13
0
 public void Composite_Application_Can_Have_Several_App_Component_Plugins()
 {
     ContainerSetup
     .Arrange((TestTypeResolver config) =>
     {
         config.AddPlugin <MockAppHostPlugin>();
         config.AddPlugin <MockAppComponentPlugin>();
         config.AddPlugin <MockAppComponentPlugin>();
     })
     .Test(
         c => c.Build(),
         (CompositeApplication ca) => ca.AppComponentPlugins.Should().HaveCount(2));
 }
Beispiel #14
0
 public void Can_Not_Have_Multiple_AppHostPlugins()
 {
     ContainerSetup
     .Arrange((TestTypeResolver config) =>
     {
         config.AddPlugin <MockAppHostPlugin>();
         config.AddPlugin <MockAppHostPlugin>();
     })
     .Test(
         c => c.Build(),
         (c, e) =>
     {
         e.Should().BeOfType <ContainerException>();
     });
 }
Beispiel #15
0
 public void AppContainerRegistered_AsSingletonService()
 {
     ContainerSetup
     .Arrange((TestTypeResolver config) =>
     {
         config.AddPlugin <MockAppHostPlugin>();
     })
     .Test(
         c => c.Build(),
         (IAppContainer ac) =>
     {
         var appContainer = ac.Services.Resolve <IAppContainer>();
         appContainer.Should().BeSameAs(ac);
     });
 }
 public void DatabaseClientActivated_WhenResolved()
 {
     ContainerSetup
     .Arrange((TestTypeResolver config) =>
     {
         config.UseDefaultSettingsConfig();
         config.SetupValidMongoConsumingPlugin();
     })
     .Test(
         c => c.Build(),
         (IAppContainer c) =>
     {
         var client = (MockMongoDbClient <MockMongoDb>)c.Services.ResolveOptional <IMongoDbClient <MockMongoDb> >();
         client.IsActivated.Should().BeTrue();
     });
 }
Beispiel #17
0
 public void PluginTypes_AssociatedWithPlugin()
 {
     ContainerSetup
     .Arrange((TestTypeResolver config) =>
     {
         config.AddPlugin <MockAppHostPlugin>()
         .AddPluginType <MockOneType>();
     })
     .Test(
         c => c.Build(),
         (CompositeApplication ca) =>
     {
         var appHostPlugin = ca.AppHostPlugin;
         appHostPlugin.PluginTypes.First().Plugin.Should().BeSameAs(appHostPlugin);
     });
 }
 public void AppContainerDisposed_PluginModulesAreDisposed()
 {
     ContainerSetup
     .Arrange((TestTypeResolver config) =>
     {
         config.AddPlugin <MockAppHostPlugin>()
         .AddPluginType <MockPluginOneModule>();
     })
     .Test(
         c => { c.Build(); c.Dispose(); },
         (CompositeApplication ca) =>
     {
         var pluginModule = ca.AppHostPlugin.PluginModules.First();
         (pluginModule as MockPluginModule).IsDisposed.Should().BeTrue();
     });
 }
 public void CanLookup_ClassMapping()
 {
     ContainerSetup
         .Arrange((TestTypeResolver config) =>
         {
             config.UseDefaultSettingsConfig();
             config.SetupValidMongoConsumingPlugin();
         })
         .Test(
             c => c.Build(),
             (MappingModule module) =>
             {
                 var entityMap = module.GetEntityMap(typeof(MockEntity));
                 entityMap.Should().NotBeNull();
             });
 }
 public void CanLookup_KnowTypeClassDescriminator()
 {
     ContainerSetup
         .Arrange((TestTypeResolver config) =>
         {
             config.UseDefaultSettingsConfig();
             config.SetupValidMongoConsumingPlugin();
         })
         .Test(
             c => c.Build(),
             (MappingModule module) =>
             {
                 var descriminator  = module.GetEntityDiscriminator(typeof(MockEntity), typeof(MockDerivedEntity));
                 descriminator.Should().Be("expected_descriminator_name");
             });
 }
 public void AllPluginManifests_MustHaveIdentityValue()
 {
     ContainerSetup
     .Arrange((TestTypeResolver config) =>
     {
         var appHostPlugin = new MockAppHostPlugin {
             PluginId = null
         };
         config.AddPlugin(appHostPlugin);
     })
     .Test(c => c.Build(),
           (c, e) =>
     {
         e.Should().NotBeNull();
         e.Should().BeOfType <ContainerException>();
     });
 }
 public void PluginAssemblyName_MustBeSpecified()
 {
     ContainerSetup
     .Arrange((TestTypeResolver config) =>
     {
         var appHostPlugin = new MockAppHostPlugin {
             AssemblyName = ""
         };
         config.AddPlugin(appHostPlugin);
     })
     .Test(
         c => c.Build(), (c, e) =>
     {
         e.Should().NotBeNull();
         e.Should().BeOfType <ContainerException>();
     });
 }
Beispiel #23
0
 public void ModuleRegisteredAsService_IfImplementsMarkerInterface()
 {
     ContainerSetup
     .Arrange((TestTypeResolver config) =>
     {
         config.AddPlugin <MockAppHostPlugin>()
         .AddPluginType <MockPluginOneModule>();
     })
     .Test(
         c => c.Build(),
         (IAppContainer ac) =>
     {
         var moduleAsService = ac.Services.Resolve <IMockPluginOneModule>();
         moduleAsService.Should().NotBeNull();
         moduleAsService.Should().BeOfType <MockPluginOneModule>();
     });
 }
 public void DiscoveredEntityClassMaps_AddedToMongo()
 {
     ContainerSetup
         .Arrange((TestTypeResolver config) =>
         {
             config.UseDefaultSettingsConfig();
             config.SetupValidMongoConsumingPlugin();
         })
         .Test(
             c => c.Build().Start(),
             (MappingModule module) =>
             {
                 var classMap = BsonClassMap.GetRegisteredClassMaps().FirstOrDefault();
                 classMap.Should().NotBeNull();
                 classMap.Should().BeOfType<MockEntityClassMap>();
             });
 }
 public void EntityClassMaps_DiscoveredByModule()
 {
     ContainerSetup
         .Arrange((TestTypeResolver config) =>
         {
             config.UseDefaultSettingsConfig();
             config.SetupValidMongoConsumingPlugin();
         })
         .Test(
             c => c.Build(),
             (MappingModule module) =>
             {
                 module.Mappings.Should().HaveCount(2);
                 module.Mappings.OfType<MockEntityClassMap>().Should().HaveCount(1);
                 module.Mappings.OfType<MockDerivedEntityClassMap>().Should().HaveCount(1);
             });
 }
Beispiel #26
0
 public void SpecifiedPluginConfiguration_AssociatedWithPlugin()
 {
     ContainerSetup
     .Arrange((TestTypeResolver config) =>
     {
         config.AddPlugin <MockAppHostPlugin>()
         .AddPluginType <MockPluginConfig>();
     })
     .Test(c =>
     {
         c.WithConfig(new MockPluginConfig());
         c.Build();
     },
           (CompositeApplication ca) =>
     {
         ca.AppHostPlugin.PluginConfigs.Should().HaveCount(1);
         ca.AppHostPlugin.PluginConfigs.First().Should().BeOfType <MockPluginConfig>();
     });
 }
Beispiel #27
0
 public void DefaultDispatchers_CanBeCleared()
 {
     ContainerSetup
     .Arrange((TestTypeResolver config) =>
     {
         config.AddPlugin <MockAppHostPlugin>();
         config.AddPlugin <MockCorePlugin>()
         .UseMessagingPlugin();
     })
     .TestConfig(c =>
     {
         c.WithConfig <MessagingConfig>(config => config.ClearMessagePublishers());
         c.Build();
     },
                 (MessagingConfig ca) =>
     {
         ca.PublisherTypes.Should().HaveCount(0);
     });
 }
        public void WhenAppContainerStarted_EachPluginModuleStarted()
        {
            ContainerSetup
            .Arrange((TestTypeResolver config) =>
            {
                config.AddPlugin <MockAppHostPlugin>()
                .AddPluginType <MockPluginOneModule>();

                config.AddPlugin <MockCorePlugin>()
                .AddPluginType <MockPluginTwoModule>();
            })
            .Test(
                c => c.Build().Start(),
                (CompositeApplication ca) =>
            {
                ca.AllPluginModules.OfType <MockPluginModule>()
                .All(m => m.IsStarted).Should().BeTrue();
            });
        }
        public void DisposedAppContainer_CannotHaveServicesAccessed()
        {
            ContainerSetup
            .Arrange((TestTypeResolver config) =>
            {
                config.AddPlugin <MockAppHostPlugin>();
            })
            .Test(c =>
            {
                c.Build();
                c.Dispose();

                var s = c.Services;
            },
                  (c, e) =>
            {
                e.Should().BeOfType <ContainerException>();
            });
        }
 public void PluginContainingType_CanBeQueried()
 {
     ContainerSetup
     .Arrange((TestTypeResolver config) =>
     {
         var appHostPlugin = new MockAppHostPlugin {
             PluginId = "__101"
         };
         appHostPlugin.AddPluginType <MockTypeOneBasedOnKnownType>();
         config.AddPlugin(appHostPlugin);
     })
     .Test(
         c => c.Build(),
         c =>
     {
         var plugIn = c.GetPluginForType(typeof(MockTypeOneBasedOnKnownType));
         plugIn.Manifest.PluginId.Should().Be("__101");
     }
         );
 }