예제 #1
0
        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)",
            });
        }
예제 #2
0
        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>();
        }
예제 #3
0
        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)}");
        }
예제 #4
0
        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",
            });
        }
예제 #5
0
        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");
        }
예제 #6
0
        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>();
        }
예제 #7
0
        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>();
        }
예제 #8
0
        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)");
        }
예제 #9
0
        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();
        }
예제 #10
0
        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>();
        }
예제 #11
0
        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)");
        }
예제 #12
0
        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)",
            });
        }