示例#1
0
        public void ShouldReturnInCorrectRetrieveOrderWhenCompletingListWithDependencies()
        {
            // A <- B <- C <- D,    C <- X
            var moduleA = CreateModuleInfo("A");
            var moduleB = CreateModuleInfo("B", "A");
            var moduleC = CreateModuleInfo("C", "B");
            var moduleD = CreateModuleInfo("D", "C");
            var moduleX = CreateModuleInfo("X", "C");

            var moduleCatalog = new ModuleCatalog();

            // Add the modules in random order
            moduleCatalog.AddModule(moduleB);
            moduleCatalog.AddModule(moduleA);
            moduleCatalog.AddModule(moduleD);
            moduleCatalog.AddModule(moduleX);
            moduleCatalog.AddModule(moduleC);

            var dependantModules = moduleCatalog.CompleteListWithDependencies(new[] { moduleD, moduleX }).ToList();

            Assert.AreEqual(5, dependantModules.Count);
            Assert.IsTrue(dependantModules.IndexOf(moduleA) < dependantModules.IndexOf(moduleB));
            Assert.IsTrue(dependantModules.IndexOf(moduleB) < dependantModules.IndexOf(moduleC));
            Assert.IsTrue(dependantModules.IndexOf(moduleC) < dependantModules.IndexOf(moduleD));
            Assert.IsTrue(dependantModules.IndexOf(moduleC) < dependantModules.IndexOf(moduleX));
        }
示例#2
0
 public void CompleteListWithDependenciesThrowsWithNull()
 {
     var ex = Assert.Throws <ArgumentNullException>(() =>
     {
         var catalog = new ModuleCatalog();
         catalog.CompleteListWithDependencies(null);
     });
 }
示例#3
0
        public void LoadModule(string moduleName)
        {
            var modules = ModuleCatalog.Modules.Where(m => m.ModuleName == moduleName);

            if (modules == null || modules.Count() == 0)
            {
                throw new ModuleNotFoundException(moduleName, string.Format(CultureInfo.CurrentCulture, "Module not found", moduleName));
            }
            else if (modules.Count() > 1)
            {
                throw new DuplicateModuleException(moduleName, string.Format(CultureInfo.CurrentCulture, "Duplicate module", moduleName));
            }

            LoadModules(ModuleCatalog.CompleteListWithDependencies(modules));
        }
        public void LoadModule(string moduleName)
        {
            var modules = ModuleCatalog.Modules.Where(m => m.ModuleName == moduleName);

            if (modules == null || modules.Count() == 0)
            {
                throw new ModuleNotFoundException(moduleName, string.Format(CultureInfo.CurrentCulture, Resources.ModuleNotFound, moduleName));
            }
            else if (modules.Count() > 1)
            {
                throw new DuplicateModuleException(moduleName, string.Format(CultureInfo.CurrentCulture, Resources.DuplicatedModuleInCatalog, moduleName));
            }

            var modulesToLoad = ModuleCatalog.CompleteListWithDependencies(modules);

            LoadModules(modulesToLoad);
        }
示例#5
0
        public void CanCompleteListWithTheirDependencies()
        {
            // A <- B <- C
            var moduleInfoA      = CreateModuleInfo("A");
            var moduleInfoB      = CreateModuleInfo("B", "A");
            var moduleInfoC      = CreateModuleInfo("C", "B");
            var moduleInfoOrphan = CreateModuleInfo("X", "B");

            List <ModuleInfo> moduleInfos = new List <ModuleInfo>
            {
                moduleInfoA
                , moduleInfoB
                , moduleInfoC
                , moduleInfoOrphan
            };
            var moduleCatalog = new ModuleCatalog(moduleInfos);

            IEnumerable <ModuleInfo> dependantModules = moduleCatalog.CompleteListWithDependencies(new[] { moduleInfoC });

            Assert.AreEqual(3, dependantModules.Count());
            Assert.IsTrue(dependantModules.Contains(moduleInfoA));
            Assert.IsTrue(dependantModules.Contains(moduleInfoB));
            Assert.IsTrue(dependantModules.Contains(moduleInfoC));
        }
示例#6
0
        public void CanCompleteListWithTheirDependencies()
        {
            // A <- B <- C
            var moduleInfoA = CreateModuleInfo("A");
            var moduleInfoB = CreateModuleInfo("B", "A");
            var moduleInfoC = CreateModuleInfo("C", "B");
            var moduleInfoOrphan = CreateModuleInfo("X", "B");

            List<ModuleInfo> moduleInfos = new List<ModuleInfo>
                                               {
                                                   moduleInfoA
                                                   , moduleInfoB
                                                   , moduleInfoC
                                                   , moduleInfoOrphan
                                               };
            var moduleCatalog = new ModuleCatalog(moduleInfos);

            IEnumerable<ModuleInfo> dependantModules = moduleCatalog.CompleteListWithDependencies(new[] { moduleInfoC });

            Assert.AreEqual(3, dependantModules.Count());
            Assert.IsTrue(dependantModules.Contains(moduleInfoA));
            Assert.IsTrue(dependantModules.Contains(moduleInfoB));
            Assert.IsTrue(dependantModules.Contains(moduleInfoC));
        }
示例#7
0
        public void CompleteListWithDependenciesThrowsWithNull()
        {
            var catalog = new ModuleCatalog();

            catalog.CompleteListWithDependencies(null);
        }
示例#8
0
        public void ShouldReturnInCorrectRetrieveOrderWhenCompletingListWithDependencies()
        {
            // A <- B <- C <- D,    C <- X
            var moduleA = CreateModuleInfo("A");
            var moduleB = CreateModuleInfo("B", "A");
            var moduleC = CreateModuleInfo("C", "B");
            var moduleD = CreateModuleInfo("D", "C");
            var moduleX = CreateModuleInfo("X", "C");

            var moduleCatalog = new ModuleCatalog();
            // Add the modules in random order
            moduleCatalog.AddModule(moduleB);
            moduleCatalog.AddModule(moduleA);
            moduleCatalog.AddModule(moduleD);
            moduleCatalog.AddModule(moduleX);
            moduleCatalog.AddModule(moduleC);

            var dependantModules = moduleCatalog.CompleteListWithDependencies(new[] { moduleD, moduleX }).ToList();

            Assert.AreEqual(5, dependantModules.Count);
            Assert.IsTrue(dependantModules.IndexOf(moduleA) < dependantModules.IndexOf(moduleB));
            Assert.IsTrue(dependantModules.IndexOf(moduleB) < dependantModules.IndexOf(moduleC));
            Assert.IsTrue(dependantModules.IndexOf(moduleC) < dependantModules.IndexOf(moduleD));
            Assert.IsTrue(dependantModules.IndexOf(moduleC) < dependantModules.IndexOf(moduleX));
        }
示例#9
0
 public void CompleteListWithDependenciesThrowsWithNull()
 {
     var catalog = new ModuleCatalog();
     catalog.CompleteListWithDependencies(null);
 }
 public void CompleteListWithDependenciesThrowsWithNull()
 {
     var catalog = new ModuleCatalog();
     Assert.ThrowsException<ArgumentNullException>(() => catalog.CompleteListWithDependencies(null));
 }