public void CheckDefaultFeatureLoadersDiscoveredOnConfiguring() { //-- arrange var logger = new MicroserviceHostLoggerMock(); var host = new MicroserviceHost(CreateBootConfiguration(), logger); var handler = new AssemblyLoadEventHandler(); host.AssemblyLoad += handler.Handle; //-- act host.Configure(); //-- assert var logs = logger.TakeLog(); logs.Should().Contain(new string[] { "FoundFeatureLoaderComponent(component=FirstFeatureLoader)", "FoundFeatureLoaderComponent(component=SecondFeatureLoader)", "FoundFeatureLoaderComponent(component=SeventhFeatureLoader)", }); }
public void TryDiscoverDuplicatedFeatureLoaderOnConfiguring() { //-- arrange var logger = new MicroserviceHostLoggerMock(); var config = CreateBootConfiguration(); var host = new MicroserviceHost(config, logger); var handler = new AssemblyLoadEventHandler(); host.AssemblyLoad += handler.Handle; host.AssemblyLoad += (object sender, AssemblyLoadEventArgs e) => { if (e.ImplementedInterface == typeof(IFeatureLoader)) { if (e.AssemblyName == "FirstModuleAssembly") { e.Destination.Add(typeof(DuplicatedFeatureLoader)); } } }; //-- act Action configuring = () => host.Configure(); //-- assert configuring.ShouldThrow <Exception>(); }
public void EmptyBootConfig_DefaultKernelFeaturesLoaded() { //-- arrange var bootConfig = CreateBootConfiguration( frameworkModules: new MicroserviceConfig.ModuleConfig[0], applicationModules: new MicroserviceConfig.ModuleConfig[0]); var assemlyLoadHandler = new AssemblyLoadEventHandler(); var logger = new MicroserviceHostLoggerMock(); var microserviceUnderTest = new MicroserviceHost(bootConfig, logger); microserviceUnderTest.AssemblyLoad += assemlyLoadHandler.Handle; var featureLog = new List <string>(); InterceptAllFeatureLoadersLogs(featureLog); //-- act microserviceUnderTest.Configure(); //-- assert featureLog.Should().Contain($"{typeof(Kernel_FeatureOne).Name}.{nameof(IFeatureLoader.ContributeComponents)}"); featureLog.Should().Contain($"{typeof(Kernel_FeatureTwo).Name}.{nameof(IFeatureLoader.ContributeComponents)}"); featureLog.Should().NotContain($"{typeof(Kernel_FeatureThree).Name}.{nameof(IFeatureLoader.ContributeComponents)}"); }
public void ModulesLoadedInOrder() { //-- arrange var logger = new MicroserviceHostLoggerMock(); var host = new MicroserviceHost(CreateBootConfiguration(), logger); var handler = new AssemblyLoadEventHandler(); var assemblies = new List <string>(); host.AssemblyLoad += handler.Handle; host.AssemblyLoad += (object sender, AssemblyLoadEventArgs e) => { assemblies.Add(e.AssemblyName); }; //-- act host.Configure(); //-- assert assemblies.ToArray().Should().Equal(new string[] { "InjectionAdapter", "NWheels.Implementation", "FrameworkModule", "FirstModuleAssembly", "SecondModuleAssembly", }); }
public void CanLoadInjectionAdapter() { //-- arrange var bootConfig = CreateBootConfiguration( frameworkModules: new MicroserviceConfig.ModuleConfig[0], applicationModules: new MicroserviceConfig.ModuleConfig[0]); var assemlyLoadHandler = new AssemblyLoadEventHandler(); var logger = new MicroserviceHostLoggerMock(); var microserviceUnderTest = new MicroserviceHost(bootConfig, logger); microserviceUnderTest.AssemblyLoad += assemlyLoadHandler.Handle; //-- act microserviceUnderTest.Configure(); //-- assert assemlyLoadHandler.EventList.Count.Should().Be(2); assemlyLoadHandler.EventList[0].ImplementedInterface.Should().Be(typeof(IComponentContainerBuilder)); assemlyLoadHandler.EventList[0].AssemblyName.Should().Be("InjectionAdapter"); assemlyLoadHandler.EventList[1].ImplementedInterface.Should().Be(typeof(IFeatureLoader)); assemlyLoadHandler.EventList[1].AssemblyName.Should().Be("NWheels.Implementation"); }
public void InjectionAdapterCtorWithoutArgumentExceptionThrown() { //-- arrange var logger = new MicroserviceHostLoggerMock(); var config = CreateBootConfiguration(); config.MicroserviceConfig.InjectionAdapter.Assembly = "AdapterInjectionCtorWithoutArgument"; var host = new MicroserviceHost(config, logger); var handler = new AssemblyLoadEventHandler(); host.AssemblyLoad += handler.Handle; host.AssemblyLoad += (object sender, AssemblyLoadEventArgs e) => { if (e.ImplementedInterface == typeof(IComponentContainerBuilder)) { if (e.AssemblyName == "AdapterInjectionCtorWithoutArgument") { e.Destination.Add(typeof(ComponentContainerBuilderCtorWithoutArgument)); } } }; //-- act Action act = () => host.Configure(); //-- assert act.ShouldThrow <Exception>(); }
public void InjectionAdapterModuleFeatureLoadersWereNotLoaded() { //-- arrange var logger = new MicroserviceHostLoggerMock(); var config = CreateBootConfiguration(); var host = new MicroserviceHost(config, logger); var handler = new AssemblyLoadEventHandler(); host.AssemblyLoad += handler.Handle; host.AssemblyLoad += (object sender, AssemblyLoadEventArgs e) => { if ((e.AssemblyName == config.MicroserviceConfig.InjectionAdapter.Assembly && e.ImplementedInterface != typeof(IComponentContainerBuilder)) || (e.AssemblyName != config.MicroserviceConfig.InjectionAdapter.Assembly && e.ImplementedInterface == typeof(IComponentContainerBuilder))) { throw new Exception("AssemblyLoadEventHandler.Handle check haven't passed."); } }; //-- act Action act = () => host.Configure(); //-- assert act.ShouldNotThrow <Exception>(); }
public void NamedKernelModuleLoadedFirstInFrameworkModules() { //-- arrange var logger = new MicroserviceHostLoggerMock(); var config = CreateBootConfiguration(); config.MicroserviceConfig.FrameworkModules = new MicroserviceConfig.ModuleConfig[] { new MicroserviceConfig.ModuleConfig() { Assembly = "NWheels.Implementation", Features = new MicroserviceConfig.ModuleConfig.FeatureConfig[] { new MicroserviceConfig.ModuleConfig.FeatureConfig() { Name = "NamedKernelFeatureLoader" } } } }; var host = new MicroserviceHost(config, logger); var handler = new AssemblyLoadEventHandler(); host.AssemblyLoad += (object sender, AssemblyLoadEventArgs e) => { if (e.ImplementedInterface == typeof(IFeatureLoader)) { if (e.AssemblyName == "NWheels.Implementation") { e.Destination.Add(typeof(NamedKernelFeatureLoader)); } } }; host.AssemblyLoad += handler.Handle; //-- act host.Configure(); //-- assert var logs = logger.TakeLog(); logs.Skip(1 + 2).First().Should().Be( "FoundFeatureLoaderComponent(component=NamedKernelFeatureLoader)"); }
public void GetCompileRegistredComponentAfterConfiguring() { //-- arrange var logger = new MicroserviceHostLoggerMock(); var host = new MicroserviceHost(CreateBootConfiguration(), logger); var handler = new AssemblyLoadEventHandler(); host.AssemblyLoad += handler.Handle; //-- act host.Configure(); var container = host.GetContainer(); var component = container.Resolve <ICompileRegistered>(); //-- assert component.Should().NotBeNull(); }
public void TryDiscoverUnexistedFeatureLoaderOnConfiguring() { //-- arrange var logger = new MicroserviceHostLoggerMock(); var config = CreateBootConfiguration(); config.MicroserviceConfig.ApplicationModules[0].Features[0].Name = "Abracadabra"; var host = new MicroserviceHost(config, logger); var handler = new AssemblyLoadEventHandler(); host.AssemblyLoad += handler.Handle; //-- act Action configuring = () => host.Configure(); //-- assert configuring.ShouldThrow <Exception>(); }
public void InjectionAdapterLoadedFirst() { //-- arrange var logger = new MicroserviceHostLoggerMock(); var host = new MicroserviceHost(CreateBootConfiguration(), logger); var handler = new AssemblyLoadEventHandler(); host.AssemblyLoad += handler.Handle; //-- act host.Configure(); //-- assert var logs = logger.TakeLog(); var firstLoadedComponent = logs.FirstOrDefault(x => x.StartsWith("FoundFeatureLoaderComponent")); firstLoadedComponent.Should().Be("FoundFeatureLoaderComponent(component=ComponentContainerBuilder)"); }
public void KernelModulesDefaultFeatureLoadersLoadedFirstAfterInjectionAdapter() { //-- arrange var logger = new MicroserviceHostLoggerMock(); var host = new MicroserviceHost(CreateBootConfiguration(), logger); var handler = new AssemblyLoadEventHandler(); host.AssemblyLoad += handler.Handle; //-- act host.Configure(); //-- assert var logs = logger.TakeLog(); logs.Skip(1).Take(2).OrderBy(x => x).Should().Equal(new string[] { "FoundFeatureLoaderComponent(component=CompilationFeatureLoader)", "FoundFeatureLoaderComponent(component=InvocationSchedulerFeatureLoader)", }); }