public void CanInitConfigModuleEnumerator()
 {
     MockConfigurationStore store = new MockConfigurationStore();
     ConfigurationModuleCatalog catalog = new ConfigurationModuleCatalog();
     catalog.Store = store;
     Assert.IsNotNull(catalog);
 }
        public void GetZeroModules()
        {
            MockConfigurationStore store = new MockConfigurationStore();
            ConfigurationModuleCatalog catalog = new ConfigurationModuleCatalog() { Store = store };
            catalog.Load();

            Assert.AreEqual(0, catalog.Modules.Count());
        }
        public void GetZeroModules()
        {
            MockConfigurationStore store = new MockConfigurationStore();
            IModuleEnumerator enumerator = new ConfigurationModuleEnumerator(store);

            ModuleInfo[] modules = enumerator.GetModules();

            Assert.AreEqual(0, modules.Length);
        }
        public void ShouldReturnAListOfModuleInfo()
        {
            MockConfigurationStore store = new MockConfigurationStore();
            store.Modules = new[] { new ModuleConfigurationElement(@"MocksModules\MockModuleA.dll", "Microsoft.Composite.Tests.Mocks.Modules.MockModuleA", "MockModuleA", false) };

            IModuleEnumerator enumerator = new ConfigurationModuleEnumerator(store);

            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.Composite.Tests.Mocks.Modules.MockModuleA", modules[0].ModuleType);
            Assert.IsFalse(modules[0].StartupLoaded);
        }
        public void ShouldReturnAListOfModuleInfo()
        {
            MockConfigurationStore store = new MockConfigurationStore();
            store.Modules = new[] { new ModuleConfigurationElement(@"MocksModules\MockModuleA.dll", "TestModules.MockModuleAClass", "MockModuleA", false) };

            ConfigurationModuleCatalog catalog = new ConfigurationModuleCatalog(){Store = store};
            catalog.Load();

            IEnumerable<ModuleInfo> modules = catalog.Modules;

            Assert.IsNotNull(modules);
            Assert.AreEqual(1, modules.Count());
            Assert.AreNotEqual(InitializationMode.WhenAvailable, modules.First().InitializationMode);
            Assert.IsNotNull(modules.First().Ref);
            StringAssert.StartsWith(modules.First().Ref, "file://");
            Assert.IsTrue( modules.First().Ref.Contains(@"MocksModules/MockModuleA.dll"));
            Assert.IsNotNull( modules.First().ModuleType);
            Assert.AreEqual("TestModules.MockModuleAClass",  modules.First().ModuleType);

        }
        public void EnumeratesThreeModulesWithDependencies()
        {
            var store = new MockConfigurationStore();
            var module1 = new ModuleConfigurationElement("Module1.dll", "Test.Module1", "Module1", false);
            module1.Dependencies = new ModuleDependencyCollection(
                new[] { new ModuleDependencyConfigurationElement("Module2") });

            var module2 = new ModuleConfigurationElement("Module2.dll", "Test.Module2", "Module2", false);
            module2.Dependencies = new ModuleDependencyCollection(
                new[] { new ModuleDependencyConfigurationElement("Module3") });

            var module3 = new ModuleConfigurationElement("Module3.dll", "Test.Module3", "Module3", false);
            store.Modules = new[] { module3, module2, module1 };

            IModuleEnumerator enumerator = new ConfigurationModuleEnumerator(store);

            var modules = new List<ModuleInfo>(enumerator.GetModules());

            Assert.AreEqual(3, modules.Count);
            Assert.IsTrue(modules.Exists(module => module.ModuleName == "Module1"));
            Assert.IsTrue(modules.Exists(module => module.ModuleName == "Module2"));
            Assert.IsTrue(modules.Exists(module => module.ModuleName == "Module3"));
        }
        public void EnumeratesThreeModulesWithDependencies()
        {
            var store = new MockConfigurationStore();
            var module1 = new ModuleConfigurationElement("Module1.dll", "Test.Module1", "Module1", false);
            module1.Dependencies = new ModuleDependencyCollection(
                new[] { new ModuleDependencyConfigurationElement("Module2") });

            var module2 = new ModuleConfigurationElement("Module2.dll", "Test.Module2", "Module2", false);
            module2.Dependencies = new ModuleDependencyCollection(
                new[] { new ModuleDependencyConfigurationElement("Module3") });

            var module3 = new ModuleConfigurationElement("Module3.dll", "Test.Module3", "Module3", false);
            store.Modules = new[] { module3, module2, module1 };

            ConfigurationModuleCatalog catalog = new ConfigurationModuleCatalog() { Store = store };
            catalog.Load();

            var modules = catalog.Modules;

            Assert.AreEqual(3, modules.Count());
            Assert.IsTrue(modules.Any(module => module.ModuleName == "Module1"));
            Assert.IsTrue(modules.Any(module => module.ModuleName == "Module2"));
            Assert.IsTrue(modules.Any(module => module.ModuleName == "Module3"));
        }
 public void CanInitConfigModuleEnumerator()
 {
     MockConfigurationStore store = new MockConfigurationStore();
     IModuleEnumerator enumerator = new ConfigurationModuleEnumerator(store);
     Assert.IsNotNull(enumerator);
 }
        public void GetModuleReturnsOnlySpecifiedModule()
        {
            MockConfigurationStore store = new MockConfigurationStore();
            var module1 = new ModuleConfigurationElement("Module1.dll", "Test.Module1", "Module1", false);

            IModuleEnumerator enumerator = new ConfigurationModuleEnumerator(store);
            store.Modules = new[] { module1 };

            var module = enumerator.GetModule("Module1");

            Assert.IsNotNull(module);
            Assert.AreEqual("Module1", module.ModuleName);
        }
        public void GetStartupLoadedModulesDoesntRetrieveOnDemandLoaded()
        {
            MockConfigurationStore store = new MockConfigurationStore();
            var module1 = new ModuleConfigurationElement("Module1.dll", "Test.Module1", "Module1", false);

            IModuleEnumerator enumerator = new ConfigurationModuleEnumerator(store);
            store.Modules = new[] { module1 };

            Assert.AreEqual<int>(1, enumerator.GetModules().Length);
            Assert.AreEqual<int>(0, enumerator.GetStartupLoadedModules().Length);
        }
        public void EnumerateNotThrowsIfDuplicateAssemblyFile()
        {
            MockConfigurationStore store = new MockConfigurationStore();
            var module1 = new ModuleConfigurationElement("Module1.dll", "Test.Module1", "Module1", false);
            var module2 = new ModuleConfigurationElement("Module1.dll", "Test.Module2", "Module2", false);
            store.Modules = new[] { module2, module1 };
            IModuleEnumerator enumerator = new ConfigurationModuleEnumerator(store);

            Assert.AreEqual(2, enumerator.GetModules().Length);
        }
        public void EnumerateThrowsIfDuplicateNames()
        {
            MockConfigurationStore store = new MockConfigurationStore();
            var module1 = new ModuleConfigurationElement("Module1.dll", "Test.Module1", "Module1", false);
            var module2 = new ModuleConfigurationElement("Module2.dll", "Test.Module2", "Module1", false);
            store.Modules = new[] { module2, module1 };
            IModuleEnumerator enumerator = new ConfigurationModuleEnumerator(store);

            ModuleInfo[] modules = enumerator.GetModules();
        }
        public void GetStartupLoadedModulesDoesntRetrieveOnDemandLoaded()
        {
            MockConfigurationStore store = new MockConfigurationStore();
            var module1 = new ModuleConfigurationElement("Module1.dll", "Test.Module1", "Module1", false);
            store.Modules = new[] { module1 };

            ConfigurationModuleCatalog catalog = new ConfigurationModuleCatalog() { Store = store };
            catalog.Load();

            Assert.AreEqual<int>(1, catalog.Modules.Count());
            Assert.AreEqual<int>(0, catalog.Modules.Count(m => m.InitializationMode != InitializationMode.OnDemand));
        }
        public void EnumerateNotThrowsIfDuplicateAssemblyFile()
        {
            MockConfigurationStore store = new MockConfigurationStore();
            var module1 = new ModuleConfigurationElement("Module1.dll", "Test.Module1", "Module1", false);
            var module2 = new ModuleConfigurationElement("Module1.dll", "Test.Module2", "Module2", false);
            store.Modules = new[] { module2, module1 };
            ConfigurationModuleCatalog catalog = new ConfigurationModuleCatalog() { Store = store };
            catalog.Load();

            Assert.AreEqual(2, catalog.Modules.Count());
        }
 public void EnumerateThrowsIfDuplicateNames()
 {
     MockConfigurationStore store = new MockConfigurationStore();
     var module1 = new ModuleConfigurationElement("Module1.dll", "Test.Module1", "Module1", false);
     var module2 = new ModuleConfigurationElement("Module2.dll", "Test.Module2", "Module1", false);
     store.Modules = new[] { module2, module1 };
     ConfigurationModuleCatalog catalog = new ConfigurationModuleCatalog() { Store = store };
     catalog.Load();
 }