示例#1
0
        public void TestVersionRequirements()
        {
            //test version on missing mod
            var list1 = new List <LocalMod> {
                Make("A", refs: new[] { "[email protected]" })
            };

            ModLoader.EnsureTargetVersionsMet(list1);

            //test passed version check
            var list2 = new List <LocalMod> {
                Make("A", refs: new[] { "[email protected]" }),
                Make("B", version: "1.2")
            };

            ModLoader.EnsureTargetVersionsMet(list2);

            //test failed version check
            var list3 = new List <LocalMod> {
                Make("A", refs: new[] { "[email protected]" }),
                Make("B")
            };

            AssertModException(
                () => ModLoader.EnsureTargetVersionsMet(list3),
                new[] { "A" },
                "A requires version 1.2+ of B but version 1.0.0.0 is installed");

            //test one pass, two fail version check
            var list4 = new List <LocalMod> {
                Make("A"),
                Make("B", refs: new[] { "[email protected]" }),
                Make("C", refs: new[] { "[email protected]" }),
                Make("D", refs: new[] { "[email protected]" })
            };

            AssertModException(
                () => ModLoader.EnsureTargetVersionsMet(list4),
                new[] { "C", "D" },
                "C requires version 1.1+ of A but version 1.0.0.0 is installed\r\n" +
                "D requires version 1.0.0.1+ of A but version 1.0.0.0 is installed");

            //test weak version check (missing)
            var list5 = new List <LocalMod> {
                Make("A", weakRefs: new[] { "[email protected]" })
            };

            ModLoader.EnsureDependenciesExist(list5, false);
            ModLoader.EnsureTargetVersionsMet(list5);

            //test weak version check (too low)
            var list6 = new List <LocalMod> {
                Make("A", weakRefs: new[] { "[email protected]" }),
                Make("B")
            };

            AssertModException(
                () => ModLoader.EnsureTargetVersionsMet(list6),
                new[] { "A" },
                "A requires version 1.1+ of B but version 1.0.0.0 is installed");
        }
示例#2
0
        public void TestDependenciesExist()
        {
            //test A -> B
            var list1 = new List <LocalMod> {
                Make("A", refs: new[] { "B" }),
                Make("B"),
            };

            ModLoader.EnsureDependenciesExist(list1, false);

            //test A -> B (missing)
            var list2 = new List <LocalMod> {
                Make("A", refs: new[] { "B" })
            };

            AssertModException(
                () => ModLoader.EnsureDependenciesExist(list2, false),
                new[] { "A" },
                "Missing mod: B required by A");

            //test multi reference
            var list3 = new List <LocalMod> {
                Make("A", refs: new[] { "B" }),
                Make("B"),
                Make("C", refs: new[] { "A" })
            };

            ModLoader.EnsureDependenciesExist(list3, false);

            //test one missing reference
            var list4 = new List <LocalMod> {
                Make("A", refs: new[] { "B" }),
                Make("B", refs: new[] { "C" })
            };

            AssertModException(
                () => ModLoader.EnsureDependenciesExist(list4, false),
                new[] { "B" },
                "Missing mod: C required by B");

            //test weak reference (missing)
            var list5 = new List <LocalMod> {
                Make("A", weakRefs: new[] { "B" })
            };

            ModLoader.EnsureDependenciesExist(list5, false);
            AssertModException(
                () => ModLoader.EnsureDependenciesExist(list5, true),
                new[] { "A" },
                "Missing mod: B required by A");

            //test weak reference (found)
            var list6 = new List <LocalMod> {
                Make("A", weakRefs: new[] { "B" }),
                Make("B")
            };

            ModLoader.EnsureDependenciesExist(list6, true);

            //test strong (found) and weak (missing)
            var list7 = new List <LocalMod> {
                Make("A", refs: new[] { "B" }),
                Make("B", weakRefs: new[] { "C" })
            };

            ModLoader.EnsureDependenciesExist(list7, false);
            AssertModException(
                () => ModLoader.EnsureDependenciesExist(list7, true),
                new[] { "B" },
                "Missing mod: C required by B");

            //multi test case (missing)
            var list8 = new List <LocalMod> {
                Make("A", refs: new[] { "X" }),
                Make("B", refs: new[] { "Y" }),
                Make("C", refs: new[] { "D" }),
                Make("D", weakRefs: new[] { "E" }),
                Make("E", weakRefs: new[] { "Z" }),
                Make("F", weakRefs: new[] { "Z" })
            };

            AssertModException(
                () => ModLoader.EnsureDependenciesExist(list8, false),
                new[] { "A", "B" },
                "Missing mod: X required by A\r\n" +
                "Missing mod: Y required by B");
            AssertModException(
                () => ModLoader.EnsureDependenciesExist(list8, true),
                new[] { "A", "B", "E", "F" },
                "Missing mod: X required by A\r\n" +
                "Missing mod: Y required by B\r\n" +
                "Missing mod: Z required by E\r\n" +
                "Missing mod: Z required by F");

            //multi test case (found)
            var list9 = new List <LocalMod> {
                Make("A", refs: new[] { "C" }),
                Make("B", refs: new[] { "C" }),
                Make("C", refs: new[] { "D" }),
                Make("D", weakRefs: new[] { "E" }),
                Make("E", weakRefs: new[] { "F" }),
                Make("F")
            };

            ModLoader.EnsureDependenciesExist(list9, false);
            ModLoader.EnsureDependenciesExist(list9, true);
        }