Ejemplo n.º 1
0
        public void ShouldInitializeModuleOnDemand()
        {
            var loader = new MockModuleInitializer();
            var onDemandModule = CreateModuleInfo("NeedsRetrieval", InitializationMode.OnDemand);
            var catalog = new MockModuleCatalog { Modules = { onDemandModule } };
            ModuleManager manager = new ModuleManager(loader, catalog, new MockLogger());
            var moduleRetriever = new MockModuleTypeLoader();
            manager.ModuleTypeLoaders = new List<IModuleTypeLoader> { moduleRetriever };
            manager.Run();

            Assert.IsFalse(loader.InitializeCalled);
            Assert.AreEqual(0, moduleRetriever.LoadedModules.Count);

            manager.LoadModule("NeedsRetrieval");

            Assert.AreEqual(1, moduleRetriever.LoadedModules.Count);
            Assert.IsTrue(loader.InitializeCalled);
            Assert.AreEqual(1, loader.InitializedModules.Count);
            Assert.AreEqual(onDemandModule, loader.InitializedModules[0]);
        }
Ejemplo n.º 2
0
        public void InvalidOnDemandModuleNameThrows()
        {
            var loader = new MockModuleInitializer();

            var catalog = new MockModuleCatalog { Modules = new List<ModuleInfo> { CreateModuleInfo("Missing", InitializationMode.OnDemand) } };

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

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

            manager.LoadModule("NonExistent");
        }
Ejemplo n.º 3
0
        public void ShouldWorkIfModuleLoadsAnotherOnDemandModuleWhenInitializing()
        {
            var initializer = new StubModuleInitializer();
            var onDemandModule = CreateModuleInfo(typeof(MockModule), InitializationMode.OnDemand);
            onDemandModule.ModuleName = "OnDemandModule";
            var moduleThatLoadsOtherModule = CreateModuleInfo(typeof(MockModule), InitializationMode.WhenAvailable);
            var catalog = new MockModuleCatalog { Modules = { moduleThatLoadsOtherModule, onDemandModule } };
            ModuleManager manager = new ModuleManager(initializer, catalog, new MockLogger());
            
            bool onDemandModuleWasInitialized = false;
            initializer.Initialize = m =>
                                     {
                                         if (m == moduleThatLoadsOtherModule)
                                         {
                                             manager.LoadModule("OnDemandModule");
                                         }
                                         else if (m == onDemandModule)
                                         {
                                             onDemandModuleWasInitialized = true;
                                         }
                                     };

            manager.Run();

            Assert.IsTrue(onDemandModuleWasInitialized);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        public void ShouldNotLoadSameModuleTwice()
        {
            var loader = new MockModuleInitializer();
            var onDemandModule = CreateModuleInfo(typeof(MockModule), InitializationMode.OnDemand);
            var catalog = new MockModuleCatalog { Modules = { onDemandModule } };
            var manager = new ModuleManager(loader, catalog, new MockLogger());
            manager.Run();
            manager.LoadModule("MockModule");
            loader.InitializeCalled = false;
            manager.LoadModule("MockModule");

            Assert.IsFalse(loader.InitializeCalled);
        }
Ejemplo n.º 6
0
        public void EmptyOnDemandModuleReturnedThrows()
        {
            var loader = new MockModuleInitializer();

            var catalog = new MockModuleCatalog { CompleteListWithDependencies = modules => new List<ModuleInfo>() };
            ModuleManager manager = new ModuleManager(loader, catalog, new MockLogger());
            var moduleRetriever = new MockModuleTypeLoader();
            manager.ModuleTypeLoaders = new List<IModuleTypeLoader> { moduleRetriever };
            manager.Run();

            manager.LoadModule("NullModule");
        }