コード例 #1
0
        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);
        }
コード例 #2
0
        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);
                }
            }
        }
コード例 #4
0
 public void CleanUpDirectories()
 {
     CompilerHelper.CleanUpDirectory(ModulesDirectory1);
     CompilerHelper.CleanUpDirectory(ModulesDirectory2);
     CompilerHelper.CleanUpDirectory(ModulesDirectory3);
     CompilerHelper.CleanUpDirectory(ModulesDirectory4);
     CompilerHelper.CleanUpDirectory(ModulesDirectory5);
 }
コード例 #5
0
        public void CanInitDirectoryLookupModuleEnumerator()
        {
            string path = @".\MocksModules";

            CompilerHelper.CleanUpDirectory(path);
            IModuleEnumerator enumerator = new DirectoryLookupModuleEnumerator(path);

            Assert.IsNotNull(enumerator);
        }
コード例 #6
0
 private void CleanUpDirectories()
 {
     CompilerHelper.CleanUpDirectory(ModulesDirectory1);
     CompilerHelper.CleanUpDirectory(ModulesDirectory2);
     CompilerHelper.CleanUpDirectory(ModulesDirectory3);
     CompilerHelper.CleanUpDirectory(ModulesDirectory4);
     CompilerHelper.CleanUpDirectory(ModulesDirectory5);
     CompilerHelper.CleanUpDirectory(InvalidModulesDirectory);
 }
コード例 #7
0
        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);
        }
コード例 #8
0
        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());
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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());
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        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());
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        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);
        }
コード例 #17
0
        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);
        }
コード例 #18
0
        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);
                }
            }
        }
コード例 #19
0
 private void CleanUpDirectories()
 {
     CompilerHelper.CleanUpDirectory(ModulesDirectory1);
 }