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 ModuleInfo[] DoEnumeration(string path)
 {
     IModuleEnumerator enumerator = new DirectoryLookupModuleEnumerator(path);
     ModuleInfo[] modules = enumerator.GetModules();
     return modules;
 }
        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 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 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 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 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 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 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 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 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]);
        }