Beispiel #1
0
        public void ShouldInitializeModulesOnRetrievalCompleted()
        {
            var loader = new MockModuleInitializer();
            var backgroungModuleInfo = CreateModuleInfo("NeedsRetrieval", InitializationMode.WhenAvailable);
            var catalog = new MockModuleCatalog {
                Modules = { backgroungModuleInfo }
            };
            ModuleManager manager          = new ModuleManager(loader, catalog, new MockLogger());
            var           moduleTypeLoader = new MockModuleTypeLoader();

            manager.ModuleTypeLoaders = new List <IModuleTypeLoader> {
                moduleTypeLoader
            };
            Assert.IsFalse(loader.InitializeCalled);

            manager.Run();

            Assert.IsTrue(loader.InitializeCalled);
            Assert.AreEqual(1, loader.InitializedModules.Count);
            Assert.AreEqual(backgroungModuleInfo, loader.InitializedModules[0]);
        }
Beispiel #2
0
        public void ShouldNotLoadModuleThatNeedsRetrievalTwice()
        {
            var loader         = new MockModuleInitializer();
            var onDemandModule = CreateModuleInfo("ModuleThatNeedsRetrieval", InitializationMode.OnDemand);
            var catalog        = new MockModuleCatalog {
                Modules = { onDemandModule }
            };
            var manager          = new ModuleManager(loader, catalog, new MockLogger());
            var moduleTypeLoader = new MockModuleTypeLoader();

            manager.ModuleTypeLoaders = new List <IModuleTypeLoader> {
                moduleTypeLoader
            };
            manager.Run();
            manager.LoadModule("ModuleThatNeedsRetrieval");
            moduleTypeLoader.RaiseLoadModuleCompleted(new LoadModuleCompletedEventArgs(onDemandModule, null));
            loader.InitializeCalled = false;

            manager.LoadModule("ModuleThatNeedsRetrieval");

            Assert.IsFalse(loader.InitializeCalled);
        }
Beispiel #3
0
        public void ShouldCallValidateCatalogBeforeGettingGroupsFromCatalog()
        {
            var  loader  = new MockModuleInitializer();
            var  catalog = new MockModuleCatalog();
            var  manager = new ModuleManager(loader, catalog, new MockLogger());
            bool validateCatalogCalled          = false;
            bool getModulesCalledBeforeValidate = false;

            catalog.ValidateCatalog = () => validateCatalogCalled = true;
            catalog.CompleteListWithDependencies = f =>
            {
                if (!validateCatalogCalled)
                {
                    getModulesCalledBeforeValidate = true;
                }

                return(null);
            };
            manager.Run();

            Assert.IsTrue(validateCatalogCalled);
            Assert.IsFalse(getModulesCalledBeforeValidate);
        }
Beispiel #4
0
        public void ShouldNotLoadTypeIfModuleInitialized()
        {
            var loader = new MockModuleInitializer();
            var alreadyPresentModule = CreateModuleInfo(typeof(MockModule), InitializationMode.WhenAvailable);

            alreadyPresentModule.State = ModuleState.ReadyForInitialization;
            var catalog = new MockModuleCatalog {
                Modules = { alreadyPresentModule }
            };
            var manager          = new ModuleManager(loader, catalog, new MockLogger());
            var moduleTypeLoader = new MockModuleTypeLoader();

            manager.ModuleTypeLoaders = new List <IModuleTypeLoader> {
                moduleTypeLoader
            };

            manager.Run();

            Assert.IsFalse(moduleTypeLoader.LoadedModules.Contains(alreadyPresentModule));
            Assert.IsTrue(loader.InitializeCalled);
            Assert.AreEqual(1, loader.InitializedModules.Count);
            Assert.AreEqual(alreadyPresentModule, loader.InitializedModules[0]);
        }
Beispiel #5
0
        public void ShouldInitializeIfDependenciesAreMet()
        {
            var initializer    = new MockModuleInitializer();
            var requiredModule = CreateModuleInfo("ModuleThatNeedsRetrieval1", InitializationMode.WhenAvailable);

            requiredModule.ModuleName = "RequiredModule";
            var dependantModuleInfo = CreateModuleInfo("ModuleThatNeedsRetrieval2", InitializationMode.WhenAvailable, "RequiredModule");

            var catalog = new MockModuleCatalog {
                Modules = { requiredModule, dependantModuleInfo }
            };

            catalog.GetDependentModules = delegate(IModuleInfo module)
            {
                if (module == dependantModuleInfo)
                {
                    return new[] { requiredModule }
                }
                ;
                else
                {
                    return(null);
                }
            };

            ModuleManager manager          = new ModuleManager(initializer, catalog, new MockLogger());
            var           moduleTypeLoader = new MockModuleTypeLoader();

            manager.ModuleTypeLoaders = new List <IModuleTypeLoader> {
                moduleTypeLoader
            };

            manager.Run();

            Assert.IsTrue(initializer.InitializeCalled);
            Assert.AreEqual(2, initializer.InitializedModules.Count);
        }