public void ShouldIgnoreAbstractClassesThatImplementIModule() { CompilerHelper.CleanUpDirectory(ModulesDirectory1); CompilerHelper.CompileFile(@"Prism.Avalonia.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 { ModulePath = ModulesDirectory1 }; catalog.Load(); var modules = catalog.Modules.ToArray(); Assert.AreEqual(1, modules.Length); Assert.AreEqual("MockInheritingModule", modules[0].ModuleName); CompilerHelper.CleanUpDirectory(ModulesDirectory1); }
public void ShouldGetDependantModulesFromAttribute() { string path = @".\DependantModules"; CompilerHelper.CleanUpDirectory(path); CompilerHelper.CompileFile(@"Microsoft.Practices.Composite.Tests.Mocks.Modules.MockDependencyModule.cs", @".\DependantModules\DependencyModule.dll"); CompilerHelper.CompileFile(@"Microsoft.Practices.Composite.Tests.Mocks.Modules.MockDependantModule.cs", @".\DependantModules\DependantModule.dll"); IModuleEnumerator enumerator = new DirectoryLookupModuleEnumerator(path); ModuleInfo[] modules = enumerator.GetModules(); 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 ShouldLoadFilesEvenIfDynamicAssemblyExists() { CompilerHelper.CleanUpDirectory(@".\CompileOutput\"); CompilerHelper.CleanUpDirectory(@".\IgnoreDynamicGeneratedFilesTestDir\"); CompilerHelper.CompileFile(@"Microsoft.Practices.Prism.Tests.Mocks.Modules.MockAttributedModule.cs", @".\IgnoreDynamicGeneratedFilesTestDir\MockAttributedModule.dll"); string path = @".\IgnoreDynamicGeneratedFilesTestDir"; AppDomain testDomain = null; try { testDomain = CreateAppDomain(); RemoteDirectoryLookupCatalog remoteEnum = CreateRemoteDirectoryModuleCatalogInAppDomain(testDomain); remoteEnum.LoadDynamicEmittedModule(); ModuleInfo[] infos = remoteEnum.DoEnumeration(path); Assert.IsNotNull( infos.FirstOrDefault(x => x.ModuleType.IndexOf("Microsoft.Practices.Prism.Tests.Mocks.Modules.MockAttributedModule") >= 0) ); } finally { if (testDomain != null) { AppDomain.Unload(testDomain); } } }
public void CleanUpDirectories() { CompilerHelper.CleanUpDirectory(ModulesDirectory1); CompilerHelper.CleanUpDirectory(ModulesDirectory2); CompilerHelper.CleanUpDirectory(ModulesDirectory3); CompilerHelper.CleanUpDirectory(ModulesDirectory4); CompilerHelper.CleanUpDirectory(ModulesDirectory5); }
public void CanInitDirectoryLookupModuleEnumerator() { string path = @".\MocksModules"; CompilerHelper.CleanUpDirectory(path); IModuleEnumerator enumerator = new DirectoryLookupModuleEnumerator(path); Assert.IsNotNull(enumerator); }
private void CleanUpDirectories() { CompilerHelper.CleanUpDirectory(ModulesDirectory1); CompilerHelper.CleanUpDirectory(ModulesDirectory2); CompilerHelper.CleanUpDirectory(ModulesDirectory3); CompilerHelper.CleanUpDirectory(ModulesDirectory4); CompilerHelper.CleanUpDirectory(ModulesDirectory5); CompilerHelper.CleanUpDirectory(InvalidModulesDirectory); }
public void GetStartupLoadedModulesDoesntRetrieveOnDemandLoaded() { string path = @".\AttributedModules"; CompilerHelper.CleanUpDirectory(path); CompilerHelper.CompileFile(@"Microsoft.Practices.Composite.Tests.Mocks.Modules.MockAttributedModule.cs", @".\AttributedModules\MockAttributedModule.dll"); IModuleEnumerator enumerator = new DirectoryLookupModuleEnumerator(path); Assert.AreEqual <int>(1, enumerator.GetModules().Length); Assert.AreEqual <int>(0, enumerator.GetStartupLoadedModules().Length); }
public void ShouldNotGetModuleInfoForAnAssemblyAlreadyLoadedInTheMainDomain() { string path = @".\Mocks\ModulesMainDomain\"; CompilerHelper.CleanUpDirectory(path); var assemblyPath = Assembly.GetCallingAssembly().Location; File.Copy(assemblyPath, path + Path.GetFileName(assemblyPath)); var enumerator = new DirectoryLookupModuleEnumerator(path); Assert.AreEqual(0, enumerator.GetModules().Count()); }
public void UseClassNameAsModuleNameWhenNotSpecifiedInAttribute() { string path = @".\MocksModules"; CompilerHelper.CleanUpDirectory(path); CompilerHelper.CompileFile(@"Microsoft.Practices.Composite.Tests.Mocks.Modules.MockModuleA.cs", @".\MocksModules\MockModuleA.dll"); IModuleEnumerator enumerator = new DirectoryLookupModuleEnumerator(path); ModuleInfo[] modules = enumerator.GetModules(); Assert.IsNotNull(modules); Assert.AreEqual("MockModuleA", modules[0].ModuleName); }
public void ShouldLoadAssemblyEvenIfIsExposingTypesFromAnAssemblyInTheGac() { string path = @".\Mocks\Modules"; CompilerHelper.CleanUpDirectory(path); CompilerHelper.CompileFile(@"Microsoft.Practices.Composite.Tests.Mocks.Modules.MockExposingTypeFromGacAssemblyModule.cs", @".\Mocks\Modules\MockExposingTypeFromGacAssemblyModule.dll", @"System.Transactions.dll"); IModuleEnumerator enumerator = new DirectoryLookupModuleEnumerator(path); ModuleInfo[] modules = enumerator.GetModules(); Assert.AreEqual(1, modules.Count()); }
public void GetModuleReturnsOnlySpecifiedModule() { string path = @".\AttributedModules"; CompilerHelper.CleanUpDirectory(path); CompilerHelper.CompileFile(@"Microsoft.Practices.Composite.Tests.Mocks.Modules.MockAttributedModule.cs", @".\AttributedModules\MockAttributedModule.dll"); IModuleEnumerator enumerator = new DirectoryLookupModuleEnumerator(path); var module = enumerator.GetModule("TestModule"); Assert.IsNotNull(module); Assert.AreEqual("TestModule", module.ModuleName); }
public void ShouldNotLoadAssembliesInCurrentAppDomain() { string path = @".\Mocks\Modules"; CompilerHelper.CleanUpDirectory(path); CompilerHelper.CompileFile(@"Microsoft.Practices.Composite.Tests.Mocks.Modules.MockModuleA.cs", @".\Mocks\Modules\MockModuleA.dll"); IModuleEnumerator enumerator = new DirectoryLookupModuleEnumerator(path); ModuleInfo[] modules = enumerator.GetModules(); Assembly loadedAssembly = Array.Find <Assembly>(AppDomain.CurrentDomain.GetAssemblies(), assembly => assembly.Location.Equals(modules[0].AssemblyFile, StringComparison.InvariantCultureIgnoreCase)); Assert.IsNull(loadedAssembly); }
public void ShouldGetStartupLoadedFromAttribute() { string path = @".\AttributedModules"; CompilerHelper.CleanUpDirectory(path); CompilerHelper.CompileFile(@"Microsoft.Practices.Composite.Tests.Mocks.Modules.MockAttributedModule.cs", @".\AttributedModules\MockAttributedModule.dll"); IModuleEnumerator enumerator = new DirectoryLookupModuleEnumerator(path); ModuleInfo[] modules = enumerator.GetModules(); Assert.AreEqual(1, modules.Length); Assert.AreEqual <bool>(false, modules[0].StartupLoaded); }
public void ShouldLoadAssemblyEvenIfTheyAreReferencingEachOther() { string path = @".\Mocks\Modules"; CompilerHelper.CleanUpDirectory(path); CompilerHelper.CompileFile(@"Microsoft.Practices.Composite.Tests.Mocks.Modules.MockModuleA.cs", @".\Mocks\Modules\MockModuleZZZ.dll"); CompilerHelper.CompileFile(@"Microsoft.Practices.Composite.Tests.Mocks.Modules.MockModuleReferencingOtherModule.cs", @".\Mocks\Modules\MockModuleReferencingOtherModule.dll", @".\Mocks\Modules\MockModuleZZZ.dll"); IModuleEnumerator enumerator = new DirectoryLookupModuleEnumerator(path); ModuleInfo[] modules = enumerator.GetModules(); Assert.AreEqual(2, modules.Count()); }
public void ShouldNotFailWhenAlreadyLoadedAssembliesAreAlsoFoundOnTargetDirectory() { string path = @".\MocksModules"; CompilerHelper.CleanUpDirectory(path); CompilerHelper.CompileFile(@"Microsoft.Practices.Composite.Tests.Mocks.Modules.MockModuleA.cs", @".\MocksModules\MockModuleA.dll"); string filename = typeof(DirectoryLookupModuleEnumerator).Assembly.Location; string destinationFileName = Path.Combine(path, Path.GetFileName(filename)); File.Copy(filename, destinationFileName); IModuleEnumerator enumerator = new DirectoryLookupModuleEnumerator(path); ModuleInfo[] modules = enumerator.GetModules(); Assert.AreEqual(1, modules.Length); }
public void CreateChildAppDomainHasParentEvidenceAndSetup() { string path = @".\MocksModules"; CompilerHelper.CleanUpDirectory(path); TestableDirectoryLookupModuleEnumerator enumerator = new TestableDirectoryLookupModuleEnumerator(path); Evidence parentEvidence = new Evidence(); AppDomainSetup parentSetup = new AppDomainSetup(); parentSetup.ApplicationName = "Test Parent"; AppDomain parentAppDomain = AppDomain.CreateDomain("Parent", parentEvidence, parentSetup); AppDomain childDomain = enumerator.BuildChildDomain(parentAppDomain); Assert.AreEqual(parentEvidence.Count, childDomain.Evidence.Count); Assert.AreEqual("Test Parent", childDomain.SetupInformation.ApplicationName); Assert.AreNotEqual(AppDomain.CurrentDomain.Evidence.Count, childDomain.Evidence.Count); Assert.AreNotEqual(AppDomain.CurrentDomain.SetupInformation.ApplicationName, childDomain.SetupInformation.ApplicationName); }
public void ShouldReturnAListOfModuleInfo() { string path = @".\MocksModules"; CompilerHelper.CleanUpDirectory(path); CompilerHelper.CompileFile(@"Microsoft.Practices.Composite.Tests.Mocks.Modules.MockModuleA.cs", @".\MocksModules\MockModuleA.dll"); IModuleEnumerator enumerator = new DirectoryLookupModuleEnumerator(path); ModuleInfo[] modules = enumerator.GetModules(); Assert.IsNotNull(modules); Assert.AreEqual(1, modules.Length); Assert.IsNotNull(modules[0].AssemblyFile); Assert.IsTrue(modules[0].AssemblyFile.Contains(@"MocksModules\MockModuleA.dll")); Assert.IsNotNull(modules[0].ModuleType); Assert.AreEqual("Microsoft.Practices.Composite.Tests.Mocks.Modules.MockModuleA", modules[0].ModuleType); Assert.IsTrue(modules[0].StartupLoaded); }
public void ShouldNotThrowWithLoadFromByteAssemblies() { CompilerHelper.CleanUpDirectory(@".\CompileOutput\"); CompilerHelper.CleanUpDirectory(@".\IgnoreLoadFromByteAssembliesTestDir\"); var results = CompilerHelper.CompileFile(@"Prism.WinForms.Tests.Mocks.Modules.MockModuleA.cs", @".\CompileOutput\MockModuleA.dll"); CompilerHelper.CompileFile(@"Prism.WinForms.Tests.Mocks.Modules.MockAttributedModule.cs", @".\IgnoreLoadFromByteAssembliesTestDir\MockAttributedModule.dll"); string path = @".\IgnoreLoadFromByteAssembliesTestDir"; AppDomain testDomain = null; try { testDomain = CreateAppDomain(); RemoteDirectoryLookupCatalog remoteEnum = CreateRemoteDirectoryModuleCatalogInAppDomain(testDomain); remoteEnum.LoadDynamicEmittedModule(); remoteEnum.LoadAssembliesByByte(@".\CompileOutput\MockModuleA.dll"); ModuleInfo[] infos = remoteEnum.DoEnumeration(path); Assert.IsNotNull( infos.FirstOrDefault(x => x.ModuleType.IndexOf("Prism.WinForms.Tests.Mocks.Modules.MockAttributedModule") >= 0) ); } finally { if (testDomain != null) { AppDomain.Unload(testDomain); } } }
private void CleanUpDirectories() { CompilerHelper.CleanUpDirectory(ModulesDirectory1); }