/// <summary> /// Populates the module catalog. /// </summary> /// <returns>A populated module catalog.</returns> /// <remarks> /// This method populates the module catalog by looking for /// assemblies in the directory assigned to ModulePath. This requires /// a post-build event wherein each module outputs its DLL to the /// afformentioned directory. /// </remarks> protected override IModuleCatalog CreateModuleCatalog() { DirectoryModuleCatalog moduleCatalog = new DirectoryModuleCatalog(); moduleCatalog.ModulePath = @".\Modules"; return moduleCatalog; }
/// <summary> /// Initialization of the Module Catalog from the "Module" directory /// </summary> /// <returns>The Module Catalog.</returns> protected override IModuleCatalog CreateModuleCatalog() { if (!Directory.Exists(@".\Modules")) { Directory.CreateDirectory(@".\Modules"); } var moduleCatalog = new DirectoryModuleCatalog {ModulePath = @".\Modules"}; Logger.Log("${SolutionName} Module Catalog was created", Category.Info, Priority.None); return moduleCatalog; }
public void ShouldReturnAListOfModuleInfo() { CompilerHelper.CompileFile(@"Microsoft.Practices.Prism.Composition.Tests.Mocks.Modules.MockModuleA.cs", ModulesDirectory1 + @"\MockModuleA.dll"); DirectoryModuleCatalog catalog = new DirectoryModuleCatalog(); catalog.ModulePath = ModulesDirectory1; catalog.Load(); ModuleInfo[] modules = catalog.Modules.ToArray(); Assert.IsNotNull(modules); Assert.AreEqual(1, modules.Length); Assert.IsNotNull(modules[0].Ref); StringAssert.StartsWith(modules[0].Ref, "file://"); Assert.IsTrue(modules[0].Ref.Contains(@"MockModuleA.dll")); Assert.IsNotNull(modules[0].ModuleType); StringAssert.Contains(modules[0].ModuleType, "Microsoft.Practices.Prism.Composition.Tests.Mocks.Modules.MockModuleA"); }
protected override void ConfigureModuleCatalog() { var moduleAType = typeof (ModuleA.Wpf.ModuleA); ModuleCatalog.AddModule(new ModuleInfo(moduleAType.Name, moduleAType.AssemblyQualifiedName)); var moduleCType = typeof (ModuleC.Wpf.ModuleC); ModuleCatalog.AddModule(new ModuleInfo { ModuleName = moduleCType.Name, ModuleType = moduleCType.AssemblyQualifiedName, InitializationMode = InitializationMode.OnDemand }); #if (!SILVERLIGHT) var directoryCatalog = new DirectoryModuleCatalog {ModulePath = @".\Modules"}; ((AggregateModuleCatalog) ModuleCatalog).AddCatalog(directoryCatalog); var configurationCatalog = new ConfigurationModuleCatalog(); ((AggregateModuleCatalog) ModuleCatalog).AddCatalog(configurationCatalog); #endif }
public void ShouldNotGetModuleInfoForAnAssemblyAlreadyLoadedInTheMainDomain() { var assemblyPath = Assembly.GetCallingAssembly().Location; DirectoryModuleCatalog catalog = new DirectoryModuleCatalog(); catalog.ModulePath = ModulesDirectory5; catalog.Load(); ModuleInfo[] modules = catalog.Modules.ToArray(); Assert.AreEqual(0, modules.Length); }
public void ShouldNotLoadAssembliesInCurrentAppDomain() { CompilerHelper.CompileFile(@"Microsoft.Practices.Prism.Tests.Mocks.Modules.MockModuleA.cs", ModulesDirectory4 + @"\MockModuleA.dll"); DirectoryModuleCatalog catalog = new DirectoryModuleCatalog(); catalog.ModulePath = ModulesDirectory4; catalog.Load(); ModuleInfo[] modules = catalog.Modules.ToArray(); // filtering out dynamic assemblies due to using a dynamic mocking framework. Assembly loadedAssembly = AppDomain.CurrentDomain.GetAssemblies().Where(assembly => !assembly.IsDynamic) .Where(assembly => assembly.Location.Equals(modules[0].Ref, StringComparison.InvariantCultureIgnoreCase)) .FirstOrDefault(); Assert.IsNull(loadedAssembly); }
protected override IModuleCatalog CreateModuleCatalog() { var moduleCatalog = new DirectoryModuleCatalog { ModulePath = DirectoryModulePath }; return moduleCatalog; }
protected override IModuleCatalog CreateModuleCatalog() { var catalog = new DirectoryModuleCatalog {ModulePath = @".\Internal"}; return catalog; }
public void NonExistentPathThrows() { DirectoryModuleCatalog catalog = new DirectoryModuleCatalog(); catalog.ModulePath = "NonExistentPath"; catalog.Load(); }
public ModuleInfo[] DoEnumeration(string path) { DirectoryModuleCatalog catalog = new DirectoryModuleCatalog(); catalog.ModulePath = path; catalog.Load(); return catalog.Modules.ToArray(); }
public void ShouldNotFailWhenAlreadyLoadedAssembliesAreAlsoFoundOnTargetDirectory() { CompilerHelper.CompileFile(@"Microsoft.Practices.Prism.Tests.Mocks.Modules.MockModuleA.cs", ModulesDirectory1 + @"\MockModuleA.dll"); string filename = typeof(DirectoryModuleCatalog).Assembly.Location; string destinationFileName = Path.Combine(ModulesDirectory1, Path.GetFileName(filename)); File.Copy(filename, destinationFileName); DirectoryModuleCatalog catalog = new DirectoryModuleCatalog(); catalog.ModulePath = ModulesDirectory1; catalog.Load(); ModuleInfo[] modules = catalog.Modules.ToArray(); Assert.AreEqual(1, modules.Length); }
public void LoadsValidAssembliesWhenInvalidDllsArePresent() { CompilerHelper.CompileFile(@"Microsoft.Practices.Prism.Tests.Mocks.Modules.MockModuleA.cs", InvalidModulesDirectory + @"\MockModuleA.dll"); DirectoryModuleCatalog catalog = new DirectoryModuleCatalog(); catalog.ModulePath = InvalidModulesDirectory; try { catalog.Load(); } catch (Exception) { Assert.Fail("Should not have thrown."); } ModuleInfo[] modules = catalog.Modules.ToArray(); Assert.IsNotNull(modules); Assert.AreEqual(1, modules.Length); Assert.IsNotNull(modules[0].Ref); StringAssert.StartsWith(modules[0].Ref, "file://"); Assert.IsTrue(modules[0].Ref.Contains(@"MockModuleA.dll")); Assert.IsNotNull(modules[0].ModuleType); StringAssert.Contains(modules[0].ModuleType, "Microsoft.Practices.Prism.Tests.Mocks.Modules.MockModuleA"); }
public void ShouldNotThrowWithNonValidDotNetAssembly() { DirectoryModuleCatalog catalog = new DirectoryModuleCatalog(); catalog.ModulePath = InvalidModulesDirectory; try { catalog.Load(); } catch (Exception) { Assert.Fail("Should not have thrown."); } ModuleInfo[] modules = catalog.Modules.ToArray(); Assert.IsNotNull(modules); Assert.AreEqual(0, modules.Length); }
protected override Microsoft.Practices.Prism.Modularity.IModuleCatalog CreateModuleCatalog() { var catalog = new DirectoryModuleCatalog { ModulePath = @".\" }; return catalog; }
protected override IModuleCatalog CreateModuleCatalog() { var catalog = new DirectoryModuleCatalog { ModulePath = @"..\..\..\_Modules" }; return catalog; }
public void ShouldLoadAssemblyEvenIfTheyAreReferencingEachOther() { CompilerHelper.CompileFile(@"Microsoft.Practices.Prism.Tests.Mocks.Modules.MockModuleA.cs", ModulesDirectory4 + @"\MockModuleZZZ.dll"); CompilerHelper.CompileFile(@"Microsoft.Practices.Prism.Tests.Mocks.Modules.MockModuleReferencingOtherModule.cs", ModulesDirectory4 + @"\MockModuleReferencingOtherModule.dll", ModulesDirectory4 + @"\MockModuleZZZ.dll"); DirectoryModuleCatalog catalog = new DirectoryModuleCatalog(); catalog.ModulePath = ModulesDirectory4; catalog.Load(); ModuleInfo[] modules = catalog.Modules.ToArray(); Assert.AreEqual(2, modules.Count()); }
public void ShouldLoadAssemblyEvenIfIsExposingTypesFromAnAssemblyInTheGac() { CompilerHelper.CompileFile(@"Microsoft.Practices.Prism.Tests.Mocks.Modules.MockExposingTypeFromGacAssemblyModule.cs", ModulesDirectory4 + @"\MockExposingTypeFromGacAssemblyModule.dll", @"System.Transactions.dll"); DirectoryModuleCatalog catalog = new DirectoryModuleCatalog(); catalog.ModulePath = ModulesDirectory4; catalog.Load(); ModuleInfo[] modules = catalog.Modules.ToArray(); Assert.AreEqual(1, modules.Count()); }
public void ShouldGetModuleNameFromAttribute() { CompilerHelper.CompileFile(@"Microsoft.Practices.Prism.Tests.Mocks.Modules.MockAttributedModule.cs", ModulesDirectory2 + @"\MockAttributedModule.dll"); DirectoryModuleCatalog catalog = new DirectoryModuleCatalog(); catalog.ModulePath = ModulesDirectory2; catalog.Load(); ModuleInfo[] modules = catalog.Modules.ToArray(); Assert.AreEqual(1, modules.Length); Assert.AreEqual("TestModule", modules[0].ModuleName); }
public void ShouldIgnoreAbstractClassesThatImplementIModule() { CompilerHelper.CleanUpDirectory(ModulesDirectory1); CompilerHelper.CompileFile(@"Microsoft.Practices.Prism.Tests.Mocks.Modules.MockAbstractModule.cs", ModulesDirectory1 + @"\MockAbstractModule.dll"); string filename = typeof(DirectoryModuleCatalog).Assembly.Location; string destinationFileName = Path.Combine(ModulesDirectory1, Path.GetFileName(filename)); File.Copy(filename, destinationFileName); DirectoryModuleCatalog catalog = new DirectoryModuleCatalog(); catalog.ModulePath = ModulesDirectory1; catalog.Load(); ModuleInfo[] modules = catalog.Modules.ToArray(); Assert.AreEqual(1, modules.Length); Assert.AreEqual("MockInheritingModule", modules[0].ModuleName); CompilerHelper.CleanUpDirectory(ModulesDirectory1); }
public void ShouldGetDependantModulesFromAttribute() { CompilerHelper.CompileFile(@"Microsoft.Practices.Prism.Tests.Mocks.Modules.MockDependencyModule.cs", ModulesDirectory3 + @"\DependencyModule.dll"); CompilerHelper.CompileFile(@"Microsoft.Practices.Prism.Tests.Mocks.Modules.MockDependantModule.cs", ModulesDirectory3 + @"\DependantModule.dll"); DirectoryModuleCatalog catalog = new DirectoryModuleCatalog(); catalog.ModulePath = ModulesDirectory3; catalog.Load(); ModuleInfo[] modules = catalog.Modules.ToArray(); Assert.AreEqual(2, modules.Length); var dependantModule = modules.First(module => module.ModuleName == "DependantModule"); var dependencyModule = modules.First(module => module.ModuleName == "DependencyModule"); Assert.IsNotNull(dependantModule); Assert.IsNotNull(dependencyModule); Assert.IsNotNull(dependantModule.DependsOn); Assert.AreEqual(1, dependantModule.DependsOn.Count); Assert.AreEqual(dependencyModule.ModuleName, dependantModule.DependsOn[0]); }
public void EmptyPathThrows() { DirectoryModuleCatalog catalog = new DirectoryModuleCatalog(); catalog.Load(); }
public void UseClassNameAsModuleNameWhenNotSpecifiedInAttribute() { CompilerHelper.CompileFile(@"Microsoft.Practices.Prism.Tests.Mocks.Modules.MockModuleA.cs", ModulesDirectory1 + @"\MockModuleA.dll"); DirectoryModuleCatalog catalog = new DirectoryModuleCatalog(); catalog.ModulePath = ModulesDirectory1; catalog.Load(); ModuleInfo[] modules = catalog.Modules.ToArray(); Assert.IsNotNull(modules); Assert.AreEqual("MockModuleA", modules[0].ModuleName); }
protected override IModuleCatalog CreateModuleCatalog() { var modulePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Modules"); var catalog = new DirectoryModuleCatalog {ModulePath = modulePath}; return catalog; }
public void ShouldDefaultInitializationModeToWhenAvailable() { CompilerHelper.CompileFile(@"Microsoft.Practices.Prism.Tests.Mocks.Modules.MockModuleA.cs", ModulesDirectory1 + @"\MockModuleA.dll"); DirectoryModuleCatalog catalog = new DirectoryModuleCatalog(); catalog.ModulePath = ModulesDirectory1; catalog.Load(); ModuleInfo[] modules = catalog.Modules.ToArray(); Assert.IsNotNull(modules); Assert.AreEqual(InitializationMode.WhenAvailable, modules[0].InitializationMode); }
protected override void ConfigureModuleCatalog() { // Module A is defined in the code. Type moduleAType = typeof(ModuleA); ModuleCatalog.AddModule(new ModuleInfo(moduleAType.Name, moduleAType.AssemblyQualifiedName)); // Module C is defined in the code. Type moduleCType = typeof(ModuleC); ModuleCatalog.AddModule(new ModuleInfo() { ModuleName = moduleCType.Name, ModuleType = moduleCType.AssemblyQualifiedName, InitializationMode = InitializationMode.OnDemand }); // Module B and Module D are copied to a directory as part of a post-build step. // These modules are not referenced in the project and are discovered by inspecting a directory. // Both projects have a post-build step to copy themselves into that directory. DirectoryModuleCatalog directoryCatalog = new DirectoryModuleCatalog() { ModulePath = @".\DirectoryModules" }; ((AggregateModuleCatalog)ModuleCatalog).AddCatalog(directoryCatalog); // Module E and Module F are defined in configuration. ConfigurationModuleCatalog configurationCatalog = new ConfigurationModuleCatalog(); ((AggregateModuleCatalog)ModuleCatalog).AddCatalog(configurationCatalog); }
public void ShouldHonorStartupLoadedAttribute() { CompilerHelper.CompileFile(@"Microsoft.Practices.Prism.Tests.Mocks.Modules.MockStartupLoadedAttributedModule.cs", ModulesDirectory3 + @"\MockStartupLoadedAttributedModule.dll"); DirectoryModuleCatalog catalog = new DirectoryModuleCatalog(); catalog.ModulePath = ModulesDirectory3; catalog.Load(); ModuleInfo[] modules = catalog.Modules.ToArray(); Assert.AreEqual(1, modules.Length); Assert.AreEqual(InitializationMode.OnDemand, modules[0].InitializationMode); }