public void MustThrowDuplicateModuleExceptionIfTheModuleIsRegisteredInMoreThanOnceCatalog() { var catalog = new CompositeModuleCatalog(); var firstCatalog = new ModuleCatalog(); firstCatalog.AddModule(new ModuleInfo("ModuleA", typeof(ModuleA).FullName)); catalog.Add(firstCatalog); var secondCatalog = new ModuleCatalog(); secondCatalog.AddModule(new ModuleInfo("ModuleA", typeof(ModuleA).FullName)); catalog.Add(secondCatalog); ExceptionTester.CallMethodAndExpectException <DuplicateModuleException>(() => catalog.Initialize()); }
/// <summary> /// Creates the <see cref="T:Microsoft.Practices.Prism.Modularity.IModuleCatalog"/> used by Prism. /// </summary> protected override IModuleCatalog CreateModuleCatalog() { var modulesDefFile = Path.Combine(Metaseed.AppEnvironment.AppPath, @"Modules\ModulesDef.xml"); var compositeModuleCatalog = new CompositeModuleCatalog(); // compositeModuleCatalog.Add(new NuGetBasedModuleCatalog()); var serializer = new XmlSerializer(typeof(ModuleInfo[])); var forceScanModules_DebugHelper = true;//debug only var exception = false; var modulesDefFileExist = File.Exists(modulesDefFile); if (!forceScanModules_DebugHelper && modulesDefFileExist) { try { using (FileStream s = new FileStream(modulesDefFile, FileMode.Open)) { var m = serializer.Deserialize(s); var modules = m as ModuleInfo[]; foreach (ModuleInfo module in modules) { compositeModuleCatalog.AddModule(module); } } } catch (Exception) { exception = true; } } if (forceScanModules_DebugHelper || (!modulesDefFileExist) || exception) { var allSubDirectoriesModuleCatalog = new MetaStudioModuleCatalog { ModulePath = ModulesDirectory }; //AllSubDirectoriesModuleCatalog MetaStudioModuleCatalog compositeModuleCatalog.Add(allSubDirectoriesModuleCatalog); allSubDirectoriesModuleCatalog.Initialize(); if (!forceScanModules_DebugHelper) { using (FileStream s = new FileStream(modulesDefFile, FileMode.Create)) { var modules = allSubDirectoriesModuleCatalog.Modules.ToArray(); serializer.Serialize(s, modules);//System.Windows.Markup.XamlWriter } Log.Info("Rebuild modules def file"); } } Type shellModuleType = typeof(ShellModule); compositeModuleCatalog.AddModule( new ModuleInfo() { ModuleName = shellModuleType.Name, ModuleType = shellModuleType.AssemblyQualifiedName, }); return(CompositeModuleCatalog = compositeModuleCatalog); }
public void CallsTheInitializedMethodOfAllRegisteredCatalogs() { var catalog = new CompositeModuleCatalog(); var firstCatalog = new FooModuleCatalog(); firstCatalog.AddModule(new ModuleInfo("ModuleA", typeof(ModuleA).FullName)); catalog.Add(firstCatalog); var secondCatalog = new FooModuleCatalog(); secondCatalog.AddModule(new ModuleInfo("ModuleB", typeof(ModuleB).FullName)); catalog.Add(secondCatalog); catalog.Initialize(); Assert.IsTrue(firstCatalog.Initialized); Assert.IsTrue(secondCatalog.Initialized); }
public void MustThrowArgumentNullExceptionIfIsCalledWithNullArgument() { var catalog = new CompositeModuleCatalog(); ExceptionTester.CallMethodAndExpectException <ArgumentNullException>(() => catalog.Add(null)); }