Пример #1
0
        public void sorting_hard_linked_non_dag_list_results_in_exception()
        {
            /*
             * The non-dag graph:
             * A -> B -> C -> A
             * |
             * > X -> Y
             */
            var a = SetUpModuleInfo("A", "B", "X");
            var b = SetUpModuleInfo("B", "C");
            var c = SetUpModuleInfo("C", "A");
            var e = SetUpModuleInfo("X", "Y");
            var x = SetUpModuleInfo("Y");

            Modules = new List <ModuleInfo>()
            {
                a,
                b,
                c,
                e,
                x
            };
            ExpectedModules = null;

            // perform test
            Assert.Throws <ArgumentException>(() => DependencyChecker.SortModules(Modules));
        }
Пример #2
0
        public void sorting_properly_modules_with_equal_high_versions()
        {
            /*  More complex graph:
             *     P
             *   /   \
             *  A     Z
             *   \   /
             *     Q
             */

            var version = new Version("2.2.1.4");

            var z = SetUpModuleInfoWithVersion("Z", version);
            var p = SetUpModuleInfoWithVersion("P", version,
                                               new KeyValuePair <string, Version>("Z", version));
            var q = SetUpModuleInfoWithVersion("Q", version,
                                               new KeyValuePair <string, Version>("Z", version));

            ModuleInfo a = SetUpModuleInfoWithVersion("A", version,
                                                      new KeyValuePair <string, Version>("P", version),
                                                      new KeyValuePair <string, Version>("Q", version));

            Modules = new[]
            {
                a, q, p, z
            };
            ExpectedModules = new[]
            {
                z, p, q, a
            };

            Assert.AreEqual(ExpectedModules, DependencyChecker.SortModules(Modules),
                            "The list was sorted wrongly.");
        }
Пример #3
0
        public void one_module_has_lower_version_than_required_results_in_exception()
        {
            /* Graph:
             * A  -> B (wrong version) -> C
             */
            var upper = new Version("1.2.0.0");
            var lower = new Version("1.0.0.0");

            var c = SetUpModuleInfoWithVersion("C", upper);
            var b = SetUpModuleInfoWithVersion("B", lower,
                                               new KeyValuePair <string, Version>("C", lower));
            var a = SetUpModuleInfoWithVersion("A", upper,
                                               new KeyValuePair <string, Version>("B", upper));

            Modules = new[]
            {
                a,
                b,
                c
            };

            // no expected modules but exception
            Assert.Throws <ArgumentException>(() => DependencyChecker.SortModules(Modules),
                                              "The modules should not be possible to sort. Missing version.");
        }
Пример #4
0
        public void sorting_empty_list()
        {
            Modules         = new List <ModuleInfo>();
            ExpectedModules = new List <ModuleInfo>();

            IEnumerable <ModuleInfo> result = DependencyChecker.SortModules(Modules);

            Assert.AreEqual(ExpectedModules, result);
        }
Пример #5
0
        public void sorting_one_elment_list()
        {
            var a = SetUpModuleInfo("A");

            Modules = new List <ModuleInfo>()
            {
                a
            };
            ExpectedModules = new List <ModuleInfo>()
            {
                a
            };

            Assert.AreEqual(ExpectedModules, DependencyChecker.SortModules(Modules), "One element list should be sorted right away");
        }
Пример #6
0
        public void sorting_two_independnt_element_list()
        {
            var a = SetUpModuleInfo("A");
            var b = SetUpModuleInfo("B");

            Modules = new List <ModuleInfo>()
            {
                a, b
            };
            ExpectedModules = new List <ModuleInfo>()
            {
                a, b
            };

            Assert.AreEqual(ExpectedModules, DependencyChecker.SortModules(Modules), "Two element list with no dependencies should be sorted right away");
        }
Пример #7
0
        public void sorting_contains_cycle_exception()
        {
            /*
             * A -> B -> C -> B
             */
            var a = SetUpModuleInfo("A", "B");
            var b = SetUpModuleInfo("B", "C");
            var c = SetUpModuleInfo("C", "B");

            Modules = new List <ModuleInfo> {
                a, b, c
            };

            ExpectedModules = null;

            // perform test
            Assert.Throws <ArgumentException>(() => DependencyChecker.SortModules(Modules));
        }
Пример #8
0
        public void sorting_proper_with_various_versions()
        {
            /*
             * Quite the DAG graph
             *       Q
             *     /
             *    P -- R
             *   /      \
             *  A        Z
             *   \     /
             *      B
             *
             */
            var high    = new Version("2.2.37.2");
            var neutral = new Version("1.5.0.0");
            var low     = new Version("1.0.0.50");

            var z = SetUpModuleInfoWithVersion("Z", neutral);
            var b = SetUpModuleInfoWithVersion("B", neutral,
                                               new KeyValuePair <string, Version>("Z", neutral));
            var r = SetUpModuleInfoWithVersion("R", neutral,
                                               new KeyValuePair <string, Version>("Z", low));
            var q = SetUpModuleInfoWithVersion("Q", high);
            var p = SetUpModuleInfoWithVersion("P", neutral,
                                               new KeyValuePair <string, Version>("Q", high),
                                               new KeyValuePair <string, Version>("R", low));

            var a = SetUpModuleInfoWithVersion("A", high,
                                               new KeyValuePair <string, Version>("P", neutral),
                                               new KeyValuePair <string, Version>("B", low));

            Modules = new[]
            {
                a, p, q, z, b, r,
            };
            ExpectedModules = new[]
            {
                q, z, r, p, b, a
            };

            Assert.AreEqual(ExpectedModules, DependencyChecker.SortModules(Modules), "This complex case should be possible to sort");
        }
Пример #9
0
        public void sorting_hard_linked_dag_list()
        {
            /* The graph:
             * A -> B -> C - > X
             *   \            /
             *    > D -> E  /
             */

            var a = SetUpModuleInfo("A", "B", "D");
            var b = SetUpModuleInfo("B", "C");
            var d = SetUpModuleInfo("D", "E");
            var c = SetUpModuleInfo("C", "X");
            var e = SetUpModuleInfo("E", "X");
            var x = SetUpModuleInfo("X");

            Modules = new List <ModuleInfo>
            {
                b,
                a,
                d,
                c,
                x,
                e,
            };

            ExpectedModules = new List <ModuleInfo>
            {
                x,
                c,
                b,
                e,
                d,
                a
            };

            // perform test
            Assert.AreEqual(ExpectedModules, DependencyChecker.SortModules(Modules));
        }