public void EnumeratesOneModuleWithoutVirtualPath()
        {
            MockModuleInfoStore store = new MockModuleInfoStore();
            store.Modules =
                new ModuleConfigurationElement[] {new ModuleConfigurationElement("Module1.Name", "Module1.Assembly", null)};
            WebModuleEnumerator enumerator = new WebModuleEnumerator(store);

            IModuleInfo[] modules = enumerator.EnumerateModules();

            Assert.AreEqual(1, modules.Length);
            Assert.AreEqual("Module1.Name", modules[0].Name);
            Assert.AreEqual("Module1.Assembly", modules[0].AssemblyName);
            Assert.AreEqual(null, modules[0].VirtualPath);
        }
        public void EnumeratesOneModuleWithServicesForRegistration()
        {
            Type registerAs = typeof (string);
            Type concreteType = typeof (Int32);
            string scope = "Global";
            MockModuleInfoStore store = new MockModuleInfoStore();
            ModuleConfigurationElement module1 =
                new ModuleConfigurationElement("Module1.Name", "Module1.Assembly", "Module1.VirtualPath");
            module1.Services =
                new ServiceConfigurationElementCollection(
                    new ServiceConfigurationElement[] {new ServiceConfigurationElement(registerAs, concreteType, scope)});
            store.Modules = new ModuleConfigurationElement[] {module1};
            WebModuleEnumerator enumerator = new WebModuleEnumerator(store);

            IModuleInfo[] modules = enumerator.EnumerateModules();

            Assert.AreEqual(1, modules.Length);
            Assert.IsNotNull(modules[0] as DependantModuleInfo);
            DependantModuleInfo moduleInfo = (DependantModuleInfo) modules[0];
            Assert.IsNotNull(moduleInfo.Services);
            Assert.AreEqual(1, moduleInfo.Services.Length);
            Assert.AreEqual(registerAs, moduleInfo.Services[0].RegisterAs);
            Assert.AreEqual(concreteType, moduleInfo.Services[0].Type);
            Assert.AreEqual(ServiceScope.Global, moduleInfo.Services[0].Scope);
        }
        public void EnumerateThrowsIfDuplicateNames()
        {
            MockModuleInfoStore store = new MockModuleInfoStore();
            ModuleConfigurationElement module1 =
                new ModuleConfigurationElement("Module1.Name", "Module1.Assembly", "Module1.VirtualPath");
            ModuleConfigurationElement module2 =
                new ModuleConfigurationElement("Module1.Name", "Module2.Assembly", "Module2.VirtualPath");
            store.Modules = new ModuleConfigurationElement[] {module2, module1};
            WebModuleEnumerator enumerator = new WebModuleEnumerator(store);

            IModuleInfo[] modules = enumerator.EnumerateModules();
        }
        public void EnumeratesTwoModulesWithoutVirtualPath()
        {
            MockModuleInfoStore store = new MockModuleInfoStore();
            ModuleConfigurationElement module1 = new ModuleConfigurationElement("Module1.Name", "Module1.Assembly", null);
            ModuleConfigurationElement module2 = new ModuleConfigurationElement("Module2.Name", "Module2.Assembly", string.Empty);
            store.Modules = new ModuleConfigurationElement[] {module2, module1};
            WebModuleEnumerator enumerator = new WebModuleEnumerator(store);

            IModuleInfo[] modules = enumerator.EnumerateModules();

            Assert.AreEqual(2, modules.Length);
            Assert.AreEqual("Module1.Name", modules[0].Name);
            Assert.AreEqual("Module2.Name", modules[1].Name);
        }
        public void EnumeratesThreeModulesWithoutDependenciesInCorrectOrder()
        {
            MockModuleInfoStore store = new MockModuleInfoStore();
            ModuleConfigurationElement module1 =
                new ModuleConfigurationElement("Module1.Name", "Module1.Assembly", "Module1.VirtualPath");
            ModuleConfigurationElement module2 =
                new ModuleConfigurationElement("Module2.Name", "Module2.Assembly", "Module2.VirtualPath");
            ModuleConfigurationElement module3 =
                new ModuleConfigurationElement("Module3.Name", "Module3.Assembly", "Module3.VirtualPath");
            store.Modules = new ModuleConfigurationElement[] {module3, module2, module1};
            WebModuleEnumerator enumerator = new WebModuleEnumerator(store);

            IModuleInfo[] modules = enumerator.EnumerateModules();

            Assert.AreEqual(3, modules.Length);
            Assert.AreEqual("Module1.Name", modules[0].Name);
            Assert.AreEqual("Module2.Name", modules[1].Name);
            Assert.AreEqual("Module3.Name", modules[2].Name);
        }
        public void EnumeratesThreeModulesWithDependencies()
        {
            MockModuleInfoStore store = new MockModuleInfoStore();
            ModuleConfigurationElement module1 =
                new ModuleConfigurationElement("Module1.Name", "Module1.Assembly", "Module1.VirtualPath");
            module1.Dependencies =
                new ModuleDependencyCollection(
                    new ModuleDependencyConfigurationElement[] {new ModuleDependencyConfigurationElement("Module2.Name")});
            ModuleConfigurationElement module2 =
                new ModuleConfigurationElement("Module2.Name", "Module2.Assembly", "Module2.VirtualPath");
            module2.Dependencies =
                new ModuleDependencyCollection(
                    new ModuleDependencyConfigurationElement[] {new ModuleDependencyConfigurationElement("Module3.Name")});
            ModuleConfigurationElement module3 =
                new ModuleConfigurationElement("Module3.Name", "Module3.Assembly", "Module3.VirtualPath");
            store.Modules = new ModuleConfigurationElement[] {module3, module2, module1};
            WebModuleEnumerator enumerator = new WebModuleEnumerator(store);

            List<IModuleInfo> modules = new List<IModuleInfo>(enumerator.EnumerateModules());

            Assert.AreEqual(3, modules.Count);
            Assert.IsTrue(modules.Exists(delegate(IModuleInfo module) { return module.Name == "Module1.Name"; }));
            Assert.IsTrue(modules.Exists(delegate(IModuleInfo module) { return module.Name == "Module2.Name"; }));
            Assert.IsTrue(modules.Exists(delegate(IModuleInfo module) { return module.Name == "Module3.Name"; }));
        }