Esempio n. 1
0
        public void load_modules_loads_all_modules_provided_by_module_discovery()
        {
            var expectedModuleInfos = new[]
                                          {
                                              new ModuleInfo("a", _moduleManifestMock.Object),
                                              new ModuleInfo("b", _moduleManifestMock.Object)
                                          };

            var discoveryMock = new Mock<IModuleDiscovery>(MockBehavior.Loose);
            discoveryMock.Setup(discovery => discovery.GetModules())
                .Returns(expectedModuleInfos);

            var loaderMock = new Mock<IModuleLoader>(MockBehavior.Strict);
            loaderMock.Setup(x => x.GetLoadedModules()).Returns(new List<ModuleInfo>());

            loaderMock.Setup(loader => loader.LoadModule(expectedModuleInfos[0]))
                .Verifiable("First module was never loaded");

            loaderMock.Setup(loader => loader.LoadModule(expectedModuleInfos[1]))
                .Verifiable("Second module was never loaded");

            var moduleManager = new ModuleManager(loaderMock.Object, _moduleFilterMock.Object,
                                                  _dependencyMock.Object);

            moduleManager.LoadModules(discoveryMock.Object);

            loaderMock.Verify();
        }
Esempio n. 2
0
        public void clear_registries_and_create_module_manager()
        {
            _registry = new InjectableModulesRegistry();
            LoadedModulesRegistry.Clear();

            Container = new WindsorContainer();
            Container.Register(
                Component.For<IInjectableModulesRegistry>().Instance(_registry)
                );

            var dependencyCheckerMock = new Mock<IDependencyChecker>(MockBehavior.Loose);
            dependencyCheckerMock.Setup(x => x.SortModules(It.IsAny<IEnumerable<ModuleInfo>>()))
                .Returns<IEnumerable<ModuleInfo>>(e => e);

            Manager = new ModuleManager(new ModuleLoader(Container, new NullGuiThreadProvider()),
                                        new CompositeModuleFilter(),
                                        dependencyCheckerMock.Object);
        }
Esempio n. 3
0
        private void RegisterCoreServices(NomadConfiguration nomadConfiguration)
        {
            ModuleAppDomain = AppDomain.CreateDomain("Modules AppDomain",
                                                     new Evidence(AppDomain.CurrentDomain.Evidence),
                                                     AppDomain.CurrentDomain.BaseDirectory,
                                                     AppDomain.CurrentDomain.BaseDirectory,
                                                     true);

            // create kernel version of the event aggregator4
            var siteEventAggregator = new EventAggregator(new NullGuiThreadProvider());

            // use container creator to create communication services on modules app domain
            string asmName = typeof (ContainerCreator).Assembly.FullName;
            string typeName = typeof (ContainerCreator).FullName;

            if (typeName != null)
            {
                _moduleLoaderCreator = (ContainerCreator)
                                       ModuleAppDomain.CreateInstanceAndUnwrap(asmName, typeName);

                DistributedConfiguration distributedConfiguration = nomadConfiguration.DistributedConfiguration;
                String loggerConfiguration = KernelConfiguration.ModulesLoggerConfigurationFilePath;
                _moduleLoaderCreator.Install(distributedConfiguration, loggerConfiguration);

                // create facade for event aggregator combining proxy and on site object
                EventAggregator = new ForwardingEventAggregator(_moduleLoaderCreator.EventAggregatorOnModulesDomain,
                                                                siteEventAggregator);

                // used proxied service locator
                ServiceLocator = _moduleLoaderCreator.ServiceLocator;

                ModuleLoader = _moduleLoaderCreator.CreateModuleLoaderInstance();
            }

            _moduleManager = new ModuleManager(ModuleLoader,
                                               KernelConfiguration.ModuleFilter,
                                               KernelConfiguration.DependencyChecker);
        }
Esempio n. 4
0
        private void RegisterCoreServices()
        {
            switch (KernelConfiguration.DefaultSecurityChanged)
            {
                case false:
                    {
                        ModuleAppDomain = AppDomain.CreateDomain("Modules AppDomain",
                                                                 new Evidence(
                                                                     AppDomain.CurrentDomain.
                                                                         Evidence),
                                                                 AppDomain.CurrentDomain.
                                                                     BaseDirectory,
                                                                 AppDomain.CurrentDomain.
                                                                     BaseDirectory,
                                                                 true);
                        break;
                    }
                case true:
                    {
                        AppDomainSetup appDomainSetup = new AppDomainSetup
                                                            {
                                                                ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
                                                            };
                        ModuleAppDomain = AppDomain.CreateDomain(
                            "Sandboxed Modules AppDomain",
                            new Evidence(AppDomain.CurrentDomain.Evidence),
                            appDomainSetup,
                            KernelConfiguration.ModulesDomainPermissions,
                            KernelConfiguration.FullTrustAssembliesSet.ToArray()
                            );
                        break;
                    }
            }

            // create kernel version of the event aggregator4
            var siteEventAggregator = new EventAggregator(new NullGuiThreadProvider());

            // use container creator to create communication services on modules app domain
            string asmName = typeof (ContainerCreator).Assembly.FullName;
            string typeName = typeof (ContainerCreator).FullName;

            var moduleLoaderCreator = (ContainerCreator)
                                      ModuleAppDomain.CreateInstanceAndUnwrap(asmName, typeName);

            // create facade for event aggregator combining proxy and on site object
            EventAggregator = new ForwardingEventAggregator(moduleLoaderCreator.EventAggregatorOnModulesDomain,
                                          siteEventAggregator);

            // used proxied service locator
            ServiceLocator = moduleLoaderCreator.ServiceLocator;

            ModuleLoader = moduleLoaderCreator.CreateModuleLoaderInstance();

            _moduleManager = new ModuleManager(ModuleLoader,
                                               KernelConfiguration.ModuleFilter,
                                               KernelConfiguration.DependencyChecker);
        }
Esempio n. 5
0
        public void manager_delegates_module_dependency_resolving_to_dependency_checker()
        {
            const string moduleAssemblyName = "module assembly name";
            var expectedModuleInfo = new ModuleInfo(moduleAssemblyName, _moduleManifestMock.Object);
            var loaderMock = new Mock<IModuleLoader>(MockBehavior.Loose);
            loaderMock.Setup(x => x.GetLoadedModules()).Returns(new List<ModuleInfo>());
            loaderMock.Setup(loader => loader.LoadModule(expectedModuleInfo));

            var dependencyCheckerMock = new Mock<IDependencyChecker>(MockBehavior.Strict);
            dependencyCheckerMock.Setup(x => x.SortModules(It.IsAny<IEnumerable<ModuleInfo>>()))
                .Returns<IEnumerable<ModuleInfo>>(e => e)
                .Verifiable("No sorting has been called upon loading");

            var manager = new ModuleManager(loaderMock.Object, _moduleFilterMock.Object,
                                            dependencyCheckerMock.Object);

            var discoveryMock = new Mock<IModuleDiscovery>(MockBehavior.Loose);
            discoveryMock.Setup(x => x.GetModules()).Returns(new List<ModuleInfo>
                                                                 {
                                                                     new ModuleInfo(
                                                                         moduleAssemblyName,
                                                                         _moduleManifestMock.Object)
                                                                 });
            manager.LoadModules(discoveryMock.Object);

            dependencyCheckerMock.Verify();
        }
Esempio n. 6
0
        public void load_modules_only_loads_modules_that_pass_filter()
        {
            var a = new ModuleInfo("a", _moduleManifestMock.Object);
            var b = new ModuleInfo("b", _moduleManifestMock.Object);

            var expectedModuleInfos = new[]
                                          {
                                              a, b
                                          };

            var discoveryMock = new Mock<IModuleDiscovery>(MockBehavior.Loose);
            discoveryMock.Setup(discovery => discovery.GetModules())
                .Returns(expectedModuleInfos);

            var filterMock = new Mock<IModuleFilter>(MockBehavior.Loose);
            filterMock.Setup(filter => filter.Matches(a))
                .Returns(true);
            filterMock.Setup(filter => filter.Matches(b))
                .Returns(false);

            var loaderMock = new Mock<IModuleLoader>(MockBehavior.Strict);
            loaderMock.Setup(x => x.GetLoadedModules()).Returns(new List<ModuleInfo>());
            loaderMock.Setup(loader => loader.LoadModule(a));

            var moduleManager = new ModuleManager(loaderMock.Object, filterMock.Object,
                                                  _dependencyMock.Object);

            moduleManager.LoadModules(discoveryMock.Object);

            loaderMock.Verify(x => x.LoadModule(a));
            loaderMock.Verify(x => x.LoadModule(It.IsAny<ModuleInfo>()), Times.Exactly(1));
        }
Esempio n. 7
0
        public void manager_delegates_module_loading_to_module_loader()
        {
            const string moduleAssemblyName = "module assembly name";
            var expectedModuleInfo = new ModuleInfo(moduleAssemblyName, _moduleManifestMock.Object);
            var loaderMock = new Mock<IModuleLoader>(MockBehavior.Strict);
            loaderMock.Setup(x => x.GetLoadedModules()).Returns(new List<ModuleInfo>());
            loaderMock.Setup(loader => loader.LoadModule(expectedModuleInfo))
                .Verifiable("Loader was not told to load requested module");

            var manager = new ModuleManager(loaderMock.Object, _moduleFilterMock.Object,
                                            _dependencyMock.Object);
            manager.LoadSingleModule(new ModuleInfo(moduleAssemblyName, _moduleManifestMock.Object));

            loaderMock.Verify();
        }
Esempio n. 8
0
        public void manager_delegates_module_dependency_resolving_with_currently_loaded_modules()
        {
            const string moduleAssemblyName = "module assembly name";
            var expectedModuleInfo = new ModuleInfo(moduleAssemblyName, _moduleManifestMock.Object);
            var loaderMock = new Mock<IModuleLoader>(MockBehavior.Strict);
            loaderMock.Setup(x => x.GetLoadedModules()).Returns(new List<ModuleInfo>
                                                                    {
                                                                        new ModuleInfo("bzdura",
                                                                                       new ModuleManifest
                                                                                           {
                                                                                               ModuleName
                                                                                                   =
                                                                                                   "bzdura"
                                                                                           },
                                                                                       new ModuleManifestFactory
                                                                                           ())
                                                                    });
            loaderMock.Setup(
                x => x.LoadModule(It.Is<ModuleInfo>(y => y.AssemblyPath == moduleAssemblyName)));

            var dependencyCheckerMock = new Mock<IDependencyChecker>(MockBehavior.Loose);

            dependencyCheckerMock.Setup(x => x.SortModules(
                It.Is<IEnumerable<ModuleInfo>>((y) => y.Count(z => z.AssemblyPath == "bzdura") == 1)))
                .Returns<IEnumerable<ModuleInfo>>(y => y);

            var manager = new ModuleManager(loaderMock.Object, _moduleFilterMock.Object,
                                            dependencyCheckerMock.Object);

            var discoveryMock = new Mock<IModuleDiscovery>(MockBehavior.Loose);
            discoveryMock.Setup(x => x.GetModules()).Returns(new List<ModuleInfo>
                                                                 {
                                                                     new ModuleInfo(
                                                                         moduleAssemblyName,
                                                                         _moduleManifestMock.Object)
                                                                 });
            manager.LoadModules(discoveryMock.Object);

            dependencyCheckerMock.Verify(x => x.SortModules(
                It.Is<IEnumerable<ModuleInfo>>((y) => y.Count(z => z.AssemblyPath == "bzdura") == 1)),
                                         Times.Exactly(1));
        }