public void ShouldReturnAListOfModuleInfo()
        {
            CompilerHelper.CompileFile(@"Prism.Wpf.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, "Prism.Wpf.Tests.Mocks.Modules.MockModuleA");
        }
 public void NonExistentPathThrows()
 {
     DirectoryModuleCatalog catalog = new DirectoryModuleCatalog();
     catalog.ModulePath = "NonExistentPath";
     catalog.Load();
 }
 public void EmptyPathThrows()
 {
     DirectoryModuleCatalog catalog = new DirectoryModuleCatalog();
     catalog.Load();
 }
 public ModuleInfo[] DoEnumeration(string path)
 {
     DirectoryModuleCatalog catalog = new DirectoryModuleCatalog();
     catalog.ModulePath = path;
     catalog.Load();
     return catalog.Modules.ToArray();
 }
        public void ShouldIgnoreAbstractClassesThatImplementIModule()
        {
            CompilerHelper.CleanUpDirectory(ModulesDirectory1);
            CompilerHelper.CompileFile(@"Prism.Wpf.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 ShouldNotFailWhenAlreadyLoadedAssembliesAreAlsoFoundOnTargetDirectory()
        {
            CompilerHelper.CompileFile(@"Prism.Wpf.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 ShouldLoadAssemblyEvenIfIsExposingTypesFromAnAssemblyInTheGac()
        {
            CompilerHelper.CompileFile(@"Prism.Wpf.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(@"Prism.Wpf.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 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(@"Prism.Wpf.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);
        }
        public void ShouldGetOnDemandFromAttribute()
        {
            CompilerHelper.CompileFile(@"Prism.Wpf.Tests.Mocks.Modules.MockAttributedModule.cs",
                                       ModulesDirectory3 + @"\MockAttributedModule.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);

        }
        public void ShouldDefaultInitializationModeToWhenAvailable()
        {
            CompilerHelper.CompileFile(@"Prism.Wpf.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);
        }
        public void UseClassNameAsModuleNameWhenNotSpecifiedInAttribute()
        {
            CompilerHelper.CompileFile(@"Prism.Wpf.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);
        }
        public void ShouldGetDependantModulesFromAttribute()
        {
            CompilerHelper.CompileFile(@"Prism.Wpf.Tests.Mocks.Modules.MockDependencyModule.cs",
                                       ModulesDirectory3 + @"\DependencyModule.dll");

            CompilerHelper.CompileFile(@"Prism.Wpf.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 ShouldLoadAssemblyEvenIfTheyAreReferencingEachOther()
        {
            CompilerHelper.CompileFile(@"Prism.Wpf.Tests.Mocks.Modules.MockModuleA.cs",
                                       ModulesDirectory4 + @"\MockModuleZZZ.dll");

            CompilerHelper.CompileFile(@"Prism.Wpf.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 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);
 }
        public void LoadsValidAssembliesWhenInvalidDllsArePresent()
        {
            CompilerHelper.CompileFile(@"Prism.Wpf.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, "Prism.Wpf.Tests.Mocks.Modules.MockModuleA");
        }