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

            Exception retrieverException = new Exception();

            moduleTypeLoader.LoadCompletedError = retrieverException;

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

            try
            {
                manager.Run();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ModuleTypeLoadingException));
                Assert.AreEqual(moduleInfo.ModuleName, ((ModularityException)ex).ModuleName);
                StringAssert.Contains(ex.Message, moduleInfo.ModuleName);
                Assert.AreSame(retrieverException, ex.InnerException);
                return;
            }

            Assert.Fail("Exception not thrown.");
        }
Exemple #2
0
        public void ShouldNotInitializeIfDependenciesAreNotMet()
        {
            var loader         = 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 = m => new[] { requiredModule };

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

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

            manager.Run();

            moduleTypeLoader.RaiseLoadModuleCompleted(new LoadModuleCompletedEventArgs(dependantModuleInfo, null));

            Assert.IsFalse(loader.InitializeCalled);
            Assert.AreEqual(0, loader.InitializedModules.Count);
        }
Exemple #3
0
        public void ShouldLogMessageOnModuleRetrievalError()
        {
            var loader     = new MockModuleInitializer();
            var moduleInfo = CreateModuleInfo("ModuleThatNeedsRetrieval", InitializationMode.WhenAvailable);
            var catalog    = new MockModuleCatalog {
                Modules = { moduleInfo }
            };
            var           logger           = new MockLogger();
            ModuleManager manager          = new ModuleManager(loader, catalog, logger);
            var           moduleTypeLoader = new MockModuleTypeLoader();

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

            try
            {
                manager.Run();
            }
            catch
            {
                // Ignore all errors to make sure logger is called even if errors thrown.
            }

            Assert.IsNotNull(logger.LastMessage);
            StringAssert.Contains(logger.LastMessage, "ModuleThatNeedsRetrieval");
            Assert.AreEqual <Category>(Category.Exception, logger.LastMessageCategory);
        }
Exemple #4
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]);
        }
        public void ShouldInvokeRetrieverForModules()
        {
            var loader = new MockModuleInitializer();
            var moduleInfo = CreateModuleInfo("needsRetrieval", InitializationMode.WhenAvailable);
            var catalog = new MockModuleCatalog { Modules = { moduleInfo } };
            ModuleManager manager = new ModuleManager(loader, catalog, new MockLogger());
            var moduleTypeLoader = new MockModuleTypeLoader();
            manager.ModuleTypeLoaders = new List<IModuleTypeLoader> { moduleTypeLoader };

            manager.Run();

            Assert.IsTrue(moduleTypeLoader.LoadedModules.Contains(moduleInfo));
        }
        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]);
        }
Exemple #7
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);
        }
Exemple #8
0
        public void ShouldThrowIfNoRetrieverCanRetrieveModule()
        {
            var loader  = new MockModuleInitializer();
            var catalog = new MockModuleCatalog {
                Modules = { CreateModuleInfo("ModuleThatNeedsRetrieval", InitializationMode.WhenAvailable) }
            };
            ModuleManager manager = new ModuleManager(loader, catalog, new MockLogger());

            manager.ModuleTypeLoaders = new List <IModuleTypeLoader> {
                new MockModuleTypeLoader()
                {
                    canLoadModuleTypeReturnValue = false
                }
            };
            manager.Run();
        }
Exemple #9
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");
        }
Exemple #10
0
        public void ShouldInvokeRetrieverForModules()
        {
            var loader     = new MockModuleInitializer();
            var moduleInfo = CreateModuleInfo("needsRetrieval", InitializationMode.WhenAvailable);
            var catalog    = new MockModuleCatalog {
                Modules = { moduleInfo }
            };
            ModuleManager manager          = new ModuleManager(loader, catalog, new MockLogger());
            var           moduleTypeLoader = new MockModuleTypeLoader();

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

            manager.Run();

            Assert.IsTrue(moduleTypeLoader.LoadedModules.Contains(moduleInfo));
        }
        public void EmptyOnDemandModuleReturnedThrows()
        {
            var ex = Assert.Throws <ModuleNotFoundException>(() =>
            {
                var loader = new MockModuleInitializer();

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

                manager.LoadModule("NullModule");
            });
        }
 public void ShouldThrowIfNoRetrieverCanRetrieveModule()
 {
     var ex = Assert.Throws <ModuleTypeLoaderNotFoundException>(() =>
     {
         var loader  = new MockModuleInitializer();
         var catalog = new MockModuleCatalog {
             Modules = { CreateModuleInfo("ModuleThatNeedsRetrieval", InitializationMode.WhenAvailable) }
         };
         ModuleManager manager = new ModuleManager(loader, catalog)
         {
             ModuleTypeLoaders = new List <IModuleTypeLoader> {
                 new MockModuleTypeLoader()
                 {
                     canLoadModuleTypeReturnValue = false
                 }
             }
         };
         manager.Run();
     });
 }
Exemple #13
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");
        }
        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]);
        }
Exemple #15
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]);
        }
Exemple #16
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);
        }
Exemple #17
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]);
        }
Exemple #18
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);
        }
        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);
            var moduleTypeLoader = new MockModuleTypeLoader();

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

            manager.Run();

            Assert.DoesNotContain(alreadyPresentModule, moduleTypeLoader.LoadedModules);
            Assert.True(loader.InitializeCalled);
            Assert.Single(loader.InitializedModules);
            Assert.Equal(alreadyPresentModule, loader.InitializedModules[0]);
        }
Exemple #20
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(ModuleInfo 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);
        }
 public void ShouldThrowIfNoRetrieverCanRetrieveModule()
 {
     var loader = new MockModuleInitializer();
     var catalog = new MockModuleCatalog { Modules = { CreateModuleInfo("ModuleThatNeedsRetrieval", InitializationMode.WhenAvailable) } };
     ModuleManager manager = new ModuleManager(loader, catalog, new MockLogger());
     manager.ModuleTypeLoaders = new List<IModuleTypeLoader> { new MockModuleTypeLoader() { canLoadModuleTypeReturnValue = false } };
     manager.Run();
 }
        public void ShouldThrowOnRetrieverErrorAndWrapException()
        {
            var loader = new MockModuleInitializer();
            var moduleInfo = CreateModuleInfo("NeedsRetrieval", InitializationMode.WhenAvailable);
            var catalog = new MockModuleCatalog { Modules = { moduleInfo } };
            ModuleManager manager = new ModuleManager(loader, catalog, new MockLogger());
            var moduleTypeLoader = new MockModuleTypeLoader();

            Exception retrieverException = new Exception();
            moduleTypeLoader.LoadCompletedError = retrieverException;

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

            try
            {
                manager.Run();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ModuleTypeLoadingException));
                Assert.AreEqual(moduleInfo.ModuleName, ((ModularityException)ex).ModuleName);
                StringAssert.Contains(ex.Message, moduleInfo.ModuleName);
                Assert.AreSame(retrieverException, ex.InnerException);
                return;
            }

            Assert.Fail("Exception not thrown.");
        }
        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(ModuleInfo 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);
        }
        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");
        }
        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]);
        }
        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);
        }
        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);
        }
        public void ShouldLogMessageOnModuleRetrievalError()
        {
            var loader = new MockModuleInitializer();
            var moduleInfo = CreateModuleInfo("ModuleThatNeedsRetrieval", InitializationMode.WhenAvailable);
            var catalog = new MockModuleCatalog { Modules = { moduleInfo } };
            var logger = new MockLogger();
            ModuleManager manager = new ModuleManager(loader, catalog, logger);
            var moduleTypeLoader = new MockModuleTypeLoader();
            moduleTypeLoader.LoadCompletedError = new Exception();
            manager.ModuleTypeLoaders = new List<IModuleTypeLoader> { moduleTypeLoader };

            try
            {
                manager.Run();
            }
            catch
            {
                // Ignore all errors to make sure logger is called even if errors thrown.
            }

            Assert.IsNotNull(logger.LastMessage);
            StringAssert.Contains(logger.LastMessage, "ModuleThatNeedsRetrieval");
            Assert.AreEqual<Category>(Category.Exception, logger.LastMessageCategory);
        }
        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);
        }
        public void ShouldNotInitializeIfDependenciesAreNotMet()
        {
            var loader = 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 = m => new[] { requiredModule };

            ModuleManager manager = new ModuleManager(loader, catalog, new MockLogger());
            var moduleTypeLoader = new MockModuleTypeLoader();
            manager.ModuleTypeLoaders = new List<IModuleTypeLoader> { moduleTypeLoader };

            manager.Run();

            moduleTypeLoader.RaiseLoadModuleCompleted(new LoadModuleCompletedEventArgs(dependantModuleInfo, null));            

            Assert.IsFalse(loader.InitializeCalled);
            Assert.AreEqual(0, loader.InitializedModules.Count);
        }
        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");
        }