public void TestExtractPatch__NeedsUnsatisfied()
        {
            UrlDir.UrlConfig urlConfig = CreateConfig("@NODE_TYPE");

            ITagList tagList = Substitute.For <ITagList>();

            tagListParser.Parse("NODE_TYPE", urlConfig).Returns(tagList);

            IPassSpecifier passSpecifier = Substitute.For <IPassSpecifier>();
            ProtoPatch     protoPatch    = new ProtoPatch(
                urlConfig,
                Command.Edit,
                "NODE_TYPE",
                "nodeName",
                "needs",
                "has",
                passSpecifier
                );

            protoPatchBuilder.Build(urlConfig, Command.Edit, tagList).Returns(protoPatch);
            needsChecker.CheckNeedsExpression("needs").Returns(false);

            Assert.Null(patchExtractor.ExtractPatch(urlConfig));

            AssertNoErrors();

            Assert.Empty(root.AllConfigs);

            passSpecifier.DidNotReceiveWithAnyArgs().CheckNeeds(null, null);
            needsChecker.DidNotReceiveWithAnyArgs().CheckNeedsRecursive(null, null);
            patchCompiler.DidNotReceiveWithAnyArgs().CompilePatch(null);

            progress.Received().NeedsUnsatisfiedRoot(urlConfig);
        }
Esempio n. 2
0
        public void TestParse__EndsWithColon()
        {
            ITagList tagList = tagListParser.Parse("stuff:blah::", urlConfig);

            progress.Received().Warning(urlConfig, "trailing : detected");

            Assert.Equal(new Tag("stuff", null, null), tagList.PrimaryTag);
            Assert.Equal(new[] {
                new Tag("blah", null, null),
            }, tagList);
        }
Esempio n. 3
0
        public void TestCompilePatch__Edit()
        {
            ProtoPatch protoPatch = new ProtoPatch(
                UrlBuilder.CreateConfig("ghi/jkl", new TestConfigNode("@NODE")
            {
                { "@bar", "bleh" },
            }),
                Command.Edit,
                "NODE",
                "foo",
                null,
                "#bar",
                Substitute.For <IPassSpecifier>()
                );

            EditPatch patch = Assert.IsType <EditPatch>(patchCompiler.CompilePatch(protoPatch));

            Assert.Same(protoPatch.urlConfig, patch.UrlConfig);
            AssertNodeMatcher(patch.NodeMatcher);

            ConfigNode config = new TestConfigNode("NODE")
            {
                { "name", "foo" },
                { "bar", "baz" },
            };

            IProtoUrlConfig urlConfig = Substitute.For <IProtoUrlConfig>();

            urlConfig.Node.Returns(config);
            urlConfig.UrlFile.Returns(file);

            LinkedList <IProtoUrlConfig> configs = new LinkedList <IProtoUrlConfig>();

            configs.AddLast(urlConfig);

            patch.Apply(configs, progress, logger);

            AssertNoErrors();

            progress.Received().ApplyingUpdate(urlConfig, protoPatch.urlConfig);

            Assert.Single(configs);
            Assert.NotSame(config, configs.First.Value.Node);
            AssertNodesEqual(new TestConfigNode("NODE")
            {
                { "name", "foo" },
                { "bar", "bleh" },
            }, configs.First.Value.Node);
            Assert.Same(file, configs.First.Value.UrlFile);
        }
Esempio n. 4
0
        public void TestCheckNeeds__False()
        {
            needsChecker.CheckNeeds("mod1").Returns(false);
            Assert.False(passSpecifier.CheckNeeds(needsChecker, progress));

            progress.Received().NeedsUnsatisfiedFor(urlConfig);
        }
Esempio n. 5
0
        public void TestCompilePatch__Edit()
        {
            ProtoPatch protoPatch = new ProtoPatch(
                UrlBuilder.CreateConfig("ghi/jkl", new TestConfigNode("@NODE")
            {
                { "@bar", "bleh" },
            }),
                Command.Edit,
                "NODE",
                "foo",
                null,
                "#bar",
                Substitute.For <IPassSpecifier>()
                );

            EditPatch patch = Assert.IsType <EditPatch>(patchCompiler.CompilePatch(protoPatch));

            Assert.Same(protoPatch.urlConfig, patch.UrlConfig);
            AssertNodeMatcher(patch.NodeMatcher);

            UrlDir.UrlConfig urlConfig = UrlBuilder.CreateConfig(new TestConfigNode("NODE")
            {
                { "name", "foo" },
                { "bar", "baz" },
            }, file);

            patch.Apply(file, progress, logger);

            AssertNoErrors();

            progress.Received().ApplyingUpdate(urlConfig, protoPatch.urlConfig);

            Assert.Equal(1, file.configs.Count);
            Assert.NotSame(urlConfig, file.configs[0]);
            AssertNodesEqual(new TestConfigNode("NODE")
            {
                { "name", "foo" },
                { "bar", "bleh" },
            }, file.configs[0].config);
        }
Esempio n. 6
0
        public void TestApply__NameChanged()
        {
            UrlDir.UrlFile file = UrlBuilder.CreateFile("abc/def.cfg");

            UrlDir.UrlConfig urlConfig = UrlBuilder.CreateConfig(new TestConfigNode("NODE")
            {
                { "name", "000" },
                { "foo", "bar" },
            }, file);

            INodeMatcher nodeMatcher = Substitute.For <INodeMatcher>();

            nodeMatcher.IsMatch(urlConfig.config).Returns(true);

            CopyPatch patch = new CopyPatch(UrlBuilder.CreateConfig("ghi/jkl", new TestConfigNode("@NODE")
            {
                { "@name", "001" },
                { "@foo", "baz" },
                { "pqr", "stw" },
            }), nodeMatcher, Substitute.For <IPassSpecifier>());

            IPatchProgress progress = Substitute.For <IPatchProgress>();
            IBasicLogger   logger   = Substitute.For <IBasicLogger>();

            patch.Apply(file, progress, logger);

            Assert.Equal(2, file.configs.Count);

            Assert.Same(urlConfig, file.configs[0]);
            AssertNodesEqual(new TestConfigNode("NODE")
            {
                { "name", "000" },
                { "foo", "bar" },
            }, file.configs[0].config);

            AssertNodesEqual(new TestConfigNode("NODE")
            {
                { "name", "001" },
                { "foo", "baz" },
                { "pqr", "stw" },
            }, file.configs[1].config);

            progress.Received().ApplyingCopy(urlConfig, patch.UrlConfig);

            progress.DidNotReceiveWithAnyArgs().ApplyingUpdate(null, null);
            progress.DidNotReceiveWithAnyArgs().ApplyingDelete(null, null);

            progress.DidNotReceiveWithAnyArgs().Error(null, null);
            progress.DidNotReceiveWithAnyArgs().Exception(null, null);
            progress.DidNotReceiveWithAnyArgs().Exception(null, null, null);
        }
        public void TestApply__NameNotChanged()
        {
            ConfigNode config = new TestConfigNode("NODE")
            {
                { "name", "000" },
                { "foo", "bar" },
            };

            INodeMatcher nodeMatcher = Substitute.For <INodeMatcher>();

            nodeMatcher.IsMatch(config).Returns(true);

            CopyPatch patch = new CopyPatch(UrlBuilder.CreateConfig("ghi/jkl", new TestConfigNode("+NODE")
            {
                { "@foo", "baz" },
                { "pqr", "stw" },
            }), nodeMatcher, Substitute.For <IPassSpecifier>());

            IProtoUrlConfig protoConfig = Substitute.For <IProtoUrlConfig>();

            protoConfig.Node.Returns(config);
            protoConfig.FullUrl.Returns("abc/def.cfg/NODE");

            LinkedList <IProtoUrlConfig> configs = new LinkedList <IProtoUrlConfig>();

            configs.AddLast(protoConfig);

            IPatchProgress progress = Substitute.For <IPatchProgress>();
            IBasicLogger   logger   = Substitute.For <IBasicLogger>();

            patch.Apply(configs, progress, logger);

            Assert.Single(configs);

            Assert.Same(protoConfig, configs.First.Value);
            AssertNodesEqual(new TestConfigNode("NODE")
            {
                { "name", "000" },
                { "foo", "bar" },
            }, configs.First.Value.Node);

            progress.Received().Error(patch.UrlConfig, "Error - when applying copy ghi/jkl/+NODE to abc/def.cfg/NODE - the copy needs to have a different name than the parent (use @name = xxx)");

            progress.DidNotReceiveWithAnyArgs().ApplyingUpdate(null, null);
            progress.DidNotReceiveWithAnyArgs().ApplyingCopy(null, null);
            progress.DidNotReceiveWithAnyArgs().ApplyingDelete(null, null);

            progress.DidNotReceiveWithAnyArgs().Exception(null, null);
            progress.DidNotReceiveWithAnyArgs().Exception(null, null, null);
        }
Esempio n. 8
0
        public void Test__Lifecycle()
        {
            IPatch[] patches = new IPatch[]
            {
                Substitute.For <IPatch>(),
                Substitute.For <IPatch>(),
                Substitute.For <IPatch>(),
                Substitute.For <IPatch>(),
                Substitute.For <IPatch>(),
                Substitute.For <IPatch>(),
                Substitute.For <IPatch>(),
                Substitute.For <IPatch>(),
                Substitute.For <IPatch>(),
                Substitute.For <IPatch>(),
                Substitute.For <IPatch>(),
                Substitute.For <IPatch>(),
                Substitute.For <IPatch>(),
                Substitute.For <IPatch>(),
                Substitute.For <IPatch>(),
                Substitute.For <IPatch>(),
                Substitute.For <IPatch>(),
                Substitute.For <IPatch>(),
                Substitute.For <IPatch>(),
                Substitute.For <IPatch>(),
                Substitute.For <IPatch>(),
                Substitute.For <IPatch>(),
                Substitute.For <IPatch>(),
                Substitute.For <IPatch>(),
                Substitute.For <IPatch>(),
            };

            UrlDir.UrlConfig urlConfig = UrlBuilder.CreateConfig("abc/def", new ConfigNode("NODE"));

            patches[00].PassSpecifier.Returns(new InsertPassSpecifier());
            patches[01].PassSpecifier.Returns(new InsertPassSpecifier());
            patches[02].PassSpecifier.Returns(new FirstPassSpecifier());
            patches[03].PassSpecifier.Returns(new FirstPassSpecifier());
            patches[04].PassSpecifier.Returns(new LegacyPassSpecifier());
            patches[05].PassSpecifier.Returns(new LegacyPassSpecifier());
            patches[06].PassSpecifier.Returns(new BeforePassSpecifier("mod1", urlConfig));
            patches[07].PassSpecifier.Returns(new BeforePassSpecifier("MOD1", urlConfig));
            patches[08].PassSpecifier.Returns(new ForPassSpecifier("mod1", urlConfig));
            patches[09].PassSpecifier.Returns(new ForPassSpecifier("MOD1", urlConfig));
            patches[10].PassSpecifier.Returns(new AfterPassSpecifier("mod1", urlConfig));
            patches[11].PassSpecifier.Returns(new AfterPassSpecifier("MOD1", urlConfig));
            patches[12].PassSpecifier.Returns(new LastPassSpecifier("mod1"));
            patches[13].PassSpecifier.Returns(new LastPassSpecifier("MOD1"));
            patches[14].PassSpecifier.Returns(new BeforePassSpecifier("mod2", urlConfig));
            patches[15].PassSpecifier.Returns(new BeforePassSpecifier("MOD2", urlConfig));
            patches[16].PassSpecifier.Returns(new ForPassSpecifier("mod2", urlConfig));
            patches[17].PassSpecifier.Returns(new ForPassSpecifier("MOD2", urlConfig));
            patches[18].PassSpecifier.Returns(new AfterPassSpecifier("mod2", urlConfig));
            patches[19].PassSpecifier.Returns(new AfterPassSpecifier("MOD2", urlConfig));
            patches[20].PassSpecifier.Returns(new LastPassSpecifier("mod2"));
            patches[21].PassSpecifier.Returns(new LastPassSpecifier("MOD2"));
            patches[22].PassSpecifier.Returns(new LastPassSpecifier("mod3"));
            patches[23].PassSpecifier.Returns(new FinalPassSpecifier());
            patches[24].PassSpecifier.Returns(new FinalPassSpecifier());

            patches[00].CountsAsPatch.Returns(false);
            patches[01].CountsAsPatch.Returns(false);
            patches[02].CountsAsPatch.Returns(true);
            patches[03].CountsAsPatch.Returns(true);
            patches[04].CountsAsPatch.Returns(true);
            patches[05].CountsAsPatch.Returns(true);
            patches[06].CountsAsPatch.Returns(true);
            patches[07].CountsAsPatch.Returns(true);
            patches[08].CountsAsPatch.Returns(true);
            patches[09].CountsAsPatch.Returns(true);
            patches[10].CountsAsPatch.Returns(true);
            patches[11].CountsAsPatch.Returns(true);
            patches[12].CountsAsPatch.Returns(true);
            patches[13].CountsAsPatch.Returns(true);
            patches[14].CountsAsPatch.Returns(true);
            patches[15].CountsAsPatch.Returns(true);
            patches[16].CountsAsPatch.Returns(true);
            patches[17].CountsAsPatch.Returns(true);
            patches[18].CountsAsPatch.Returns(true);
            patches[19].CountsAsPatch.Returns(true);
            patches[20].CountsAsPatch.Returns(true);
            patches[21].CountsAsPatch.Returns(true);
            patches[22].CountsAsPatch.Returns(true);
            patches[23].CountsAsPatch.Returns(true);
            patches[24].CountsAsPatch.Returns(true);

            IPatchProgress progress = Substitute.For <IPatchProgress>();

            PatchList patchList = new PatchList(new[] { "mod1", "mod2" }, patches, progress);

            IPass[] passes = patchList.ToArray();

            Assert.Equal(13, passes.Length);

            Assert.Equal(":INSERT (initial)", passes[0].Name);
            Assert.Equal(new[] { patches[0], patches[1] }, passes[0]);

            Assert.Equal(":FIRST", passes[1].Name);
            Assert.Equal(new[] { patches[2], patches[3] }, passes[1]);

            Assert.Equal(":LEGACY (default)", passes[2].Name);
            Assert.Equal(new[] { patches[4], patches[5] }, passes[2]);

            Assert.Equal(":BEFORE[MOD1]", passes[3].Name);
            Assert.Equal(new[] { patches[6], patches[7] }, passes[3]);

            Assert.Equal(":FOR[MOD1]", passes[4].Name);
            Assert.Equal(new[] { patches[8], patches[9] }, passes[4]);

            Assert.Equal(":AFTER[MOD1]", passes[5].Name);
            Assert.Equal(new[] { patches[10], patches[11] }, passes[5]);

            Assert.Equal(":BEFORE[MOD2]", passes[6].Name);
            Assert.Equal(new[] { patches[14], patches[15] }, passes[6]);

            Assert.Equal(":FOR[MOD2]", passes[7].Name);
            Assert.Equal(new[] { patches[16], patches[17] }, passes[7]);

            Assert.Equal(":AFTER[MOD2]", passes[8].Name);
            Assert.Equal(new[] { patches[18], patches[19] }, passes[8]);

            Assert.Equal(":LAST[MOD1]", passes[9].Name);
            Assert.Equal(new[] { patches[12], patches[13] }, passes[9]);

            Assert.Equal(":LAST[MOD2]", passes[10].Name);
            Assert.Equal(new[] { patches[20], patches[21] }, passes[10]);

            Assert.Equal(":LAST[MOD3]", passes[11].Name);
            Assert.Equal(new[] { patches[22] }, passes[11]);

            Assert.Equal(":FINAL", passes[12].Name);
            Assert.Equal(new[] { patches[23], patches[24] }, passes[12]);

            progress.Received(23).PatchAdded();
        }
Esempio n. 9
0
        public void TestApplyPatches__Edit()
        {
            UrlDir.UrlConfig config1 = UrlBuilder.CreateConfig(new TestConfigNode("PART")
            {
                { "name", "abc" },
                { "foo", "bar" },
            }, file);

            UrlDir.UrlConfig config2 = UrlBuilder.CreateConfig(new TestConfigNode("PART")
            {
                { "name", "def" },
            }, file);

            UrlDir.UrlConfig config3 = UrlBuilder.CreateConfig(new TestConfigNode("PORT")
            {
                { "name", "ghi" },
                { "jkl", "mno" },
            }, file);

            UrlDir.UrlConfig patch1 = new UrlDir.UrlConfig(file, new TestConfigNode("@PART")
            {
                { "@foo", "baz" },
                { "pqr", "stw" },
            });

            patchList.firstPatches.Add(patch1);

            patchApplier.ApplyPatches();

            EnsureNoErrors();

            progress.Received(1).PatchApplied();
            progress.Received().ApplyingUpdate(config1, patch1);
            progress.Received().ApplyingUpdate(config2, patch1);

            UrlDir.UrlConfig[] allConfigs = databaseRoot.AllConfigs.ToArray();
            Assert.Equal(3, allConfigs.Length);

            AssertNodesEqual(new TestConfigNode("PART")
            {
                { "name", "abc" },
                { "foo", "baz" },
                { "pqr", "stw" },
            }, allConfigs[0].config);

            AssertNodesEqual(new TestConfigNode("PART")
            {
                { "name", "def" },
                { "pqr", "stw" },
            }, allConfigs[1].config);

            AssertNodesEqual(new TestConfigNode("PORT")
            {
                { "name", "ghi" },
                { "jkl", "mno" },
            }, allConfigs[2].config);
        }
        public void TestSortAndExtractPatches()
        {
            UrlDir.UrlConfig[] insertConfigs =
            {
                CreateConfig("NODE"),
                CreateConfig("NADE"),
            };

            UrlDir.UrlConfig[] legacyConfigs =
            {
                CreateConfig("@NODE"),
                CreateConfig("@NADE[foo]:HAS[#bar]"),
            };

            UrlDir.UrlConfig[] firstConfigs =
            {
                CreateConfig("@NODE:FIRST"),
                CreateConfig("@NODE[foo]:HAS[#bar]:FIRST"),
                CreateConfig("@NADE:First"),
                CreateConfig("@NADE:first"),
            };

            UrlDir.UrlConfig[] finalConfigs =
            {
                CreateConfig("@NODE:FINAL"),
                CreateConfig("@NODE[foo]:HAS[#bar]:FINAL"),
                CreateConfig("@NADE:Final"),
                CreateConfig("@NADE:final"),
            };

            UrlDir.UrlConfig[] beforeMod1Configs =
            {
                CreateConfig("@NODE:BEFORE[mod1]"),
                CreateConfig("@NODE[foo]:HAS[#bar]:BEFORE[mod1]"),
                CreateConfig("@NADE:before[mod1]"),
                CreateConfig("@NADE:BEFORE[MOD1]"),
            };

            UrlDir.UrlConfig[] forMod1Configs =
            {
                CreateConfig("@NODE:FOR[mod1]"),
                CreateConfig("@NODE[foo]:HAS[#bar]:FOR[mod1]"),
                CreateConfig("@NADE:for[mod1]"),
                CreateConfig("@NADE:FOR[MOD1]"),
            };

            UrlDir.UrlConfig[] afterMod1Configs =
            {
                CreateConfig("@NODE:AFTER[mod1]"),
                CreateConfig("@NODE[foo]:HAS[#bar]:AFTER[mod1]"),
                CreateConfig("@NADE:after[mod1]"),
                CreateConfig("@NADE:AFTER[MOD1]"),
            };

            UrlDir.UrlConfig[] beforeMod2Configs =
            {
                CreateConfig("@NODE:BEFORE[mod2]"),
                CreateConfig("@NODE[foo]:HAS[#bar]:BEFORE[mod2]"),
                CreateConfig("@NADE:before[mod2]"),
                CreateConfig("@NADE:BEFORE[MOD2]"),
            };

            UrlDir.UrlConfig[] forMod2Configs =
            {
                CreateConfig("@NODE:FOR[mod2]"),
                CreateConfig("@NODE[foo]:HAS[#bar]:FOR[mod2]"),
                CreateConfig("@NADE:for[mod2]"),
                CreateConfig("@NADE:FOR[MOD2]"),
            };

            UrlDir.UrlConfig[] afterMod2Configs =
            {
                CreateConfig("@NODE:AFTER[mod2]"),
                CreateConfig("@NODE[foo]:HAS[#bar]:AFTER[mod2]"),
                CreateConfig("@NADE:after[mod2]"),
                CreateConfig("@NADE:AFTER[MOD2]"),
            };

            UrlDir.UrlConfig[] beforeMod3Configs =
            {
                CreateConfig("@NODE:BEFORE[mod3]"),
                CreateConfig("@NODE[foo]:HAS[#bar]:BEFORE[mod3]"),
                CreateConfig("@NADE:before[mod3]"),
                CreateConfig("@NADE:BEFORE[MOD3]"),
            };

            UrlDir.UrlConfig[] forMod3Configs =
            {
                CreateConfig("@NODE:FOR[mod3]"),
                CreateConfig("@NODE[foo]:HAS[#bar]:FOR[mod3]"),
                CreateConfig("@NADE:for[mod3]"),
                CreateConfig("@NADE:FOR[MOD3]"),
            };

            UrlDir.UrlConfig[] afterMod3Configs =
            {
                CreateConfig("@NODE:AFTER[mod3]"),
                CreateConfig("@NODE[foo]:HAS[#bar]:AFTER[mod3]"),
                CreateConfig("@NADE:after[mod3]"),
                CreateConfig("@NADE:AFTER[MOD3]"),
            };

            string[]  modList = { "mod1", "mod2" };
            PatchList list    = PatchExtractor.SortAndExtractPatches(root, modList, progress);

            progress.DidNotReceiveWithAnyArgs().Error(null, null);
            progress.DidNotReceiveWithAnyArgs().Exception(null, null);
            progress.DidNotReceiveWithAnyArgs().Exception(null, null, null);

            Assert.True(list.modPasses.HasMod("mod1"));
            Assert.True(list.modPasses.HasMod("mod2"));
            Assert.False(list.modPasses.HasMod("mod3"));

            Assert.Equal(insertConfigs, root.AllConfigs);

            Assert.Equal(legacyConfigs, list.legacyPatches);

            List <UrlDir.UrlConfig> currentPatches;

            currentPatches = list.firstPatches;
            Assert.Equal(firstConfigs.Length, currentPatches.Count);
            AssertUrlCorrect("@NODE", firstConfigs[0], currentPatches[0]);
            AssertUrlCorrect("@NODE[foo]:HAS[#bar]", firstConfigs[1], currentPatches[1]);
            AssertUrlCorrect("@NADE", firstConfigs[2], currentPatches[2]);
            AssertUrlCorrect("@NADE", firstConfigs[3], currentPatches[3]);

            currentPatches = list.finalPatches;
            Assert.Equal(finalConfigs.Length, currentPatches.Count);
            AssertUrlCorrect("@NODE", finalConfigs[0], currentPatches[0]);
            AssertUrlCorrect("@NODE[foo]:HAS[#bar]", finalConfigs[1], currentPatches[1]);
            AssertUrlCorrect("@NADE", finalConfigs[2], currentPatches[2]);
            AssertUrlCorrect("@NADE", finalConfigs[3], currentPatches[3]);

            currentPatches = list.modPasses["mod1"].beforePatches;
            Assert.Equal(beforeMod1Configs.Length, currentPatches.Count);
            AssertUrlCorrect("@NODE", beforeMod1Configs[0], currentPatches[0]);
            AssertUrlCorrect("@NODE[foo]:HAS[#bar]", beforeMod1Configs[1], currentPatches[1]);
            AssertUrlCorrect("@NADE", beforeMod1Configs[2], currentPatches[2]);
            AssertUrlCorrect("@NADE", beforeMod1Configs[3], currentPatches[3]);

            currentPatches = list.modPasses["mod1"].forPatches;
            Assert.Equal(forMod1Configs.Length, currentPatches.Count);
            AssertUrlCorrect("@NODE", forMod1Configs[0], currentPatches[0]);
            AssertUrlCorrect("@NODE[foo]:HAS[#bar]", forMod1Configs[1], currentPatches[1]);
            AssertUrlCorrect("@NADE", forMod1Configs[2], currentPatches[2]);
            AssertUrlCorrect("@NADE", forMod1Configs[3], currentPatches[3]);

            currentPatches = list.modPasses["mod1"].afterPatches;
            Assert.Equal(afterMod1Configs.Length, currentPatches.Count);
            AssertUrlCorrect("@NODE", afterMod1Configs[0], currentPatches[0]);
            AssertUrlCorrect("@NODE[foo]:HAS[#bar]", afterMod1Configs[1], currentPatches[1]);
            AssertUrlCorrect("@NADE", afterMod1Configs[2], currentPatches[2]);
            AssertUrlCorrect("@NADE", afterMod1Configs[3], currentPatches[3]);

            currentPatches = list.modPasses["mod2"].beforePatches;
            Assert.Equal(beforeMod2Configs.Length, currentPatches.Count);
            AssertUrlCorrect("@NODE", beforeMod2Configs[0], currentPatches[0]);
            AssertUrlCorrect("@NODE[foo]:HAS[#bar]", beforeMod2Configs[1], currentPatches[1]);
            AssertUrlCorrect("@NADE", beforeMod2Configs[2], currentPatches[2]);
            AssertUrlCorrect("@NADE", beforeMod2Configs[3], currentPatches[3]);

            currentPatches = list.modPasses["mod2"].forPatches;
            Assert.Equal(forMod2Configs.Length, currentPatches.Count);
            AssertUrlCorrect("@NODE", forMod2Configs[0], currentPatches[0]);
            AssertUrlCorrect("@NODE[foo]:HAS[#bar]", forMod2Configs[1], currentPatches[1]);
            AssertUrlCorrect("@NADE", forMod2Configs[2], currentPatches[2]);
            AssertUrlCorrect("@NADE", forMod2Configs[3], currentPatches[3]);

            currentPatches = list.modPasses["mod2"].afterPatches;
            Assert.Equal(afterMod2Configs.Length, currentPatches.Count);
            AssertUrlCorrect("@NODE", afterMod2Configs[0], currentPatches[0]);
            AssertUrlCorrect("@NODE[foo]:HAS[#bar]", afterMod2Configs[1], currentPatches[1]);
            AssertUrlCorrect("@NADE", afterMod2Configs[2], currentPatches[2]);
            AssertUrlCorrect("@NADE", afterMod2Configs[3], currentPatches[3]);

            progress.Received(34).PatchAdded();

            progress.Received().NeedsUnsatisfiedBefore(beforeMod3Configs[0]);
            progress.Received().NeedsUnsatisfiedBefore(beforeMod3Configs[1]);
            progress.Received().NeedsUnsatisfiedBefore(beforeMod3Configs[2]);
            progress.Received().NeedsUnsatisfiedBefore(beforeMod3Configs[3]);

            progress.Received().NeedsUnsatisfiedFor(forMod3Configs[0]);
            progress.Received().NeedsUnsatisfiedFor(forMod3Configs[1]);
            progress.Received().NeedsUnsatisfiedFor(forMod3Configs[2]);
            progress.Received().NeedsUnsatisfiedFor(forMod3Configs[3]);

            progress.Received().NeedsUnsatisfiedAfter(afterMod3Configs[0]);
            progress.Received().NeedsUnsatisfiedAfter(afterMod3Configs[1]);
            progress.Received().NeedsUnsatisfiedAfter(afterMod3Configs[2]);
            progress.Received().NeedsUnsatisfiedAfter(afterMod3Configs[3]);
        }
Esempio n. 11
0
        public void TestApply__NameChanged()
        {
            UrlDir.UrlFile file = UrlBuilder.CreateFile("abc/def.cfg");

            ConfigNode config = new TestConfigNode("NODE")
            {
                { "name", "000" },
                { "foo", "bar" },
            };

            INodeMatcher nodeMatcher = Substitute.For <INodeMatcher>();

            nodeMatcher.IsMatch(config).Returns(true);

            CopyPatch patch = new CopyPatch(UrlBuilder.CreateConfig("ghi/jkl", new TestConfigNode("@NODE")
            {
                { "@name", "001" },
                { "@foo", "baz" },
                { "pqr", "stw" },
            }), nodeMatcher, Substitute.For <IPassSpecifier>());

            IProtoUrlConfig protoConfig = Substitute.For <IProtoUrlConfig>();

            protoConfig.Node.Returns(config);
            protoConfig.UrlFile.Returns(file);

            LinkedList <IProtoUrlConfig> configs = new LinkedList <IProtoUrlConfig>();

            configs.AddLast(protoConfig);

            IPatchProgress progress = Substitute.For <IPatchProgress>();
            IBasicLogger   logger   = Substitute.For <IBasicLogger>();

            patch.Apply(configs, progress, logger);

            IProtoUrlConfig[] newConfigs = configs.ToArray();

            Assert.Equal(2, newConfigs.Length);

            Assert.Same(protoConfig, newConfigs[0]);
            AssertNodesEqual(new TestConfigNode("NODE")
            {
                { "name", "000" },
                { "foo", "bar" },
            }, newConfigs[0].Node);

            AssertNodesEqual(new TestConfigNode("NODE")
            {
                { "name", "001" },
                { "foo", "baz" },
                { "pqr", "stw" },
            }, newConfigs[1].Node);
            Assert.Same(file, newConfigs[1].UrlFile);

            progress.Received().ApplyingCopy(protoConfig, patch.UrlConfig);

            progress.DidNotReceiveWithAnyArgs().ApplyingUpdate(null, null);
            progress.DidNotReceiveWithAnyArgs().ApplyingDelete(null, null);

            progress.DidNotReceiveWithAnyArgs().Error(null, null);
            progress.DidNotReceiveWithAnyArgs().Exception(null, null);
            progress.DidNotReceiveWithAnyArgs().Exception(null, null, null);
        }
        public void TestCheckNeeds__Root()
        {
            string[] modList = { "mod1", "mod2" };

            UrlDir.UrlConfig config1 = UrlBuilder.CreateConfig(new ConfigNode("SOME_NODE"), file);
            UrlDir.UrlConfig config2 = UrlBuilder.CreateConfig(new ConfigNode("SOME_NODE:NEEDS[mod1]"), file);
            UrlDir.UrlConfig config3 = UrlBuilder.CreateConfig(new ConfigNode("SOME_NODE:needs[mod1]"), file);
            UrlDir.UrlConfig config4 = UrlBuilder.CreateConfig(new ConfigNode("SOME_NODE:NEEDS[mod2]:AFTER[mod3]"), file);

            UrlDir.UrlConfig config5 = UrlBuilder.CreateConfig(new ConfigNode("SOME_NODE:NEEDS[mod3]"), file);
            UrlDir.UrlConfig config6 = UrlBuilder.CreateConfig(new ConfigNode("SOME_NODE:needs[mod3]"), file);
            UrlDir.UrlConfig config7 = UrlBuilder.CreateConfig(new ConfigNode("SOME_NODE:NEEDS[mod3]:FOR[mod2]"), file);

            NeedsChecker.CheckNeeds(root, modList, progress, logger);

            progress.DidNotReceiveWithAnyArgs().Exception(null, null);
            progress.DidNotReceiveWithAnyArgs().Exception(null, null, null);
            progress.DidNotReceiveWithAnyArgs().Error(null, null);

            UrlDir.UrlConfig[] configs = root.AllConfigs.ToArray();
            Assert.Equal(4, configs.Length);

            Assert.Same(config1, configs[0]);
            AssertUrlCorrect("SOME_NODE", config2, configs[1]);
            AssertUrlCorrect("SOME_NODE", config3, configs[2]);
            AssertUrlCorrect("SOME_NODE:AFTER[mod3]", config4, configs[3]);

            progress.Received().NeedsUnsatisfiedRoot(config5);
            progress.Received().NeedsUnsatisfiedRoot(config6);
            progress.Received().NeedsUnsatisfiedRoot(config7);
        }