public void TestCheckNeeds__True() { needsChecker.CheckNeeds("mod1").Returns(true); Assert.True(passSpecifier.CheckNeeds(needsChecker, progress)); progress.DidNotReceiveWithAnyArgs().NeedsUnsatisfiedFor(null); }
private void EnsureNoErrors() { progress.DidNotReceiveWithAnyArgs().Error(null, null); progress.DidNotReceiveWithAnyArgs().Exception(null, null); progress.DidNotReceiveWithAnyArgs().Exception(null, null, null); logger.DidNotReceive().Log(LogType.Warning, Arg.Any <string>()); logger.DidNotReceive().Log(LogType.Error, Arg.Any <string>()); logger.DidNotReceive().Log(LogType.Exception, Arg.Any <string>()); }
private void EnsureNoErrors() { progress.DidNotReceiveWithAnyArgs().Error(null, null); progress.DidNotReceiveWithAnyArgs().Exception(null, null); progress.DidNotReceiveWithAnyArgs().Exception(null, null, null); logger.AssertNoWarning(); logger.AssertNoError(); logger.AssertNoException(); }
public void TestApply() { ConfigNode config1 = new ConfigNode("NODE"); ConfigNode config2 = new ConfigNode("NODE"); ConfigNode config3 = new ConfigNode("NODE"); ConfigNode config4 = new ConfigNode("NODE"); INodeMatcher nodeMatcher = Substitute.For <INodeMatcher>(); nodeMatcher.IsMatch(config1).Returns(false); nodeMatcher.IsMatch(config2).Returns(true); nodeMatcher.IsMatch(config3).Returns(false); nodeMatcher.IsMatch(config4).Returns(true); DeletePatch patch = new DeletePatch(UrlBuilder.CreateConfig("ghi/jkl", new ConfigNode("!NODE")), nodeMatcher, Substitute.For <IPassSpecifier>()); IProtoUrlConfig urlConfig1 = Substitute.For <IProtoUrlConfig>(); IProtoUrlConfig urlConfig2 = Substitute.For <IProtoUrlConfig>(); IProtoUrlConfig urlConfig3 = Substitute.For <IProtoUrlConfig>(); IProtoUrlConfig urlConfig4 = Substitute.For <IProtoUrlConfig>(); urlConfig1.Node.Returns(config1); urlConfig2.Node.Returns(config2); urlConfig3.Node.Returns(config3); urlConfig4.Node.Returns(config4); LinkedList <IProtoUrlConfig> configs = new LinkedList <IProtoUrlConfig>(); configs.AddLast(urlConfig1); configs.AddLast(urlConfig2); configs.AddLast(urlConfig3); configs.AddLast(urlConfig4); IPatchProgress progress = Substitute.For <IPatchProgress>(); IBasicLogger logger = Substitute.For <IBasicLogger>(); patch.Apply(configs, progress, logger); Assert.Equal(new[] { urlConfig1, urlConfig3 }, configs); Received.InOrder(delegate { progress.ApplyingDelete(urlConfig2, patch.UrlConfig); progress.ApplyingDelete(urlConfig4, patch.UrlConfig); }); progress.DidNotReceiveWithAnyArgs().ApplyingUpdate(null, null); progress.DidNotReceiveWithAnyArgs().ApplyingCopy(null, null); progress.DidNotReceiveWithAnyArgs().Error(null, null); progress.DidNotReceiveWithAnyArgs().Exception(null, null); progress.DidNotReceiveWithAnyArgs().Exception(null, null, null); }
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); }
public void TestExtractPatch__ProtoPatchNull() { UrlDir.UrlConfig patchConfig = UrlBuilder.CreateConfig("abc/def", new ConfigNode("NODE"), root); protoPatchBuilder.Build(patchConfig, Command.Insert, Arg.Any <ITagList>()).Returns(null, new ProtoPatch[0]); Assert.Null(patchExtractor.ExtractPatch(patchConfig)); needsChecker.DidNotReceiveWithAnyArgs().CheckNeedsExpression(null); AssertNoErrors(); progress.DidNotReceive().PatchAdded(); progress.DidNotReceiveWithAnyArgs().NeedsUnsatisfiedRoot(null); }
public void TestCheckNeeds__NeedsCheckerNull() { ArgumentNullException ex = Assert.Throws <ArgumentNullException>(delegate { passSpecifier.CheckNeeds(null, progress); }); Assert.Equal("needsChecker", ex.ParamName); progress.DidNotReceiveWithAnyArgs().NeedsUnsatisfiedAfter(null); }
public void TestApplyPatches__InvalidOperator() { UrlDir.UrlConfig config1 = UrlBuilder.CreateConfig(new TestConfigNode("PART") { { "name", "000" }, { "aaa", "1" }, }, file); UrlDir.UrlConfig patch1 = new UrlDir.UrlConfig(file, new ConfigNode("%PART")); UrlDir.UrlConfig patch2 = new UrlDir.UrlConfig(file, new ConfigNode("|PART")); UrlDir.UrlConfig patch3 = new UrlDir.UrlConfig(file, new ConfigNode("#PART")); UrlDir.UrlConfig patch4 = new UrlDir.UrlConfig(file, new ConfigNode("*PART")); UrlDir.UrlConfig patch5 = new UrlDir.UrlConfig(file, new ConfigNode("&PART")); patchList.firstPatches.Add(patch1); patchList.firstPatches.Add(patch2); patchList.firstPatches.Add(patch3); patchList.firstPatches.Add(patch4); patchList.firstPatches.Add(patch5); patchApplier.ApplyPatches(); progress.DidNotReceiveWithAnyArgs().Error(null, null); progress.DidNotReceiveWithAnyArgs().Exception(null, null); progress.DidNotReceiveWithAnyArgs().Exception(null, null, null); logger.DidNotReceive().Log(LogType.Error, Arg.Any <string>()); logger.DidNotReceiveWithAnyArgs().Exception(null, null); logger.Received().Log(LogType.Warning, "Invalid command encountered on a patch: abc/def/%PART"); logger.Received().Log(LogType.Warning, "Invalid command encountered on a patch: abc/def/|PART"); logger.Received().Log(LogType.Warning, "Invalid command encountered on a patch: abc/def/#PART"); logger.Received().Log(LogType.Warning, "Invalid command encountered on a patch: abc/def/*PART"); logger.Received().Log(LogType.Warning, "Invalid command encountered on a patch: abc/def/&PART"); UrlDir.UrlConfig[] allConfigs = databaseRoot.AllConfigs.ToArray(); Assert.Equal(1, allConfigs.Length); AssertNodesEqual(new TestConfigNode("PART") { { "name", "000" }, { "aaa", "1" }, }, allConfigs[0].config); }
public void TestApply() { UrlDir.UrlFile file = UrlBuilder.CreateFile("abc/def.cfg"); UrlDir.UrlConfig urlConfig1 = UrlBuilder.CreateConfig(new ConfigNode("NODE"), file); UrlDir.UrlConfig urlConfig2 = UrlBuilder.CreateConfig(new ConfigNode("NODE"), file); UrlDir.UrlConfig urlConfig3 = UrlBuilder.CreateConfig(new ConfigNode("NODE"), file); UrlDir.UrlConfig urlConfig4 = UrlBuilder.CreateConfig(new ConfigNode("NODE"), file); INodeMatcher nodeMatcher = Substitute.For <INodeMatcher>(); nodeMatcher.IsMatch(urlConfig1.config).Returns(false); nodeMatcher.IsMatch(urlConfig2.config).Returns(true); nodeMatcher.IsMatch(urlConfig3.config).Returns(false); nodeMatcher.IsMatch(urlConfig4.config).Returns(true); DeletePatch patch = new DeletePatch(UrlBuilder.CreateConfig("ghi/jkl", new ConfigNode("!NODE")), nodeMatcher, Substitute.For <IPassSpecifier>()); IPatchProgress progress = Substitute.For <IPatchProgress>(); IBasicLogger logger = Substitute.For <IBasicLogger>(); patch.Apply(file, progress, logger); Assert.Equal(new[] { urlConfig1, urlConfig3 }, file.configs); Received.InOrder(delegate { progress.ApplyingDelete(urlConfig2, patch.UrlConfig); progress.ApplyingDelete(urlConfig4, patch.UrlConfig); }); progress.DidNotReceiveWithAnyArgs().ApplyingUpdate(null, null); progress.DidNotReceiveWithAnyArgs().ApplyingCopy(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); }
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]); }
private void AssertNoErrors() { progress.DidNotReceiveWithAnyArgs().Error(null, null); progress.DidNotReceiveWithAnyArgs().Exception(null, null); progress.DidNotReceiveWithAnyArgs().Exception(null, null, null); }
public void TestCheckNeedsRecursive() { ConfigNode node = new TestConfigNode("SOME_NODE") { { "aa", "00" }, { "bb:NEEDS[mod1]", "01" }, { "cc:NEEDS[mod3]", "02" }, new TestConfigNode("INNER_NODE_1") { { "dd", "03" }, { "ee", "04" }, new TestConfigNode("INNER_INNER_NODE_1") { { "ff", "05" }, }, }, new TestConfigNode("INNER_NODE_2") { { "gg:NEEDS[mod1]", "06" }, { "hh:NEEDS[mod3]", "07" }, { "ii", "08" }, new TestConfigNode("INNER_INNER_NODE_11") { { "jj", "09" }, }, new TestConfigNode("INNER_INNER_NODE_12:NEEDS[mod2]") { { "kk", "10" }, }, new TestConfigNode("INNER_INNER_NODE_12:NEEDS[mod3]") { { "ll", "11" }, }, }, new TestConfigNode("INNER_NODE_3:NEEDS[mod1]") { { "mm:NEEDS[mod1]", "12" }, { "nn:NEEDS[mod3]", "13" }, { "oo", "14" }, new TestConfigNode("INNER_INNER_NODE_21") { { "pp", "15" }, }, new TestConfigNode("INNER_INNER_NODE_22:NEEDS[mod2]") { { "qq", "16" }, }, new TestConfigNode("INNER_INNER_NODE_22:NEEDS[mod3]") { { "rr", "17" }, }, }, new TestConfigNode("INNER_NODE_4:NEEDS[mod3]") { { "ss:NEEDS[mod1]", "18" }, }, }; UrlDir.UrlConfig urlConfig = UrlBuilder.CreateConfig("abc/def", node); needsChecker.CheckNeedsRecursive(node, urlConfig); progress.DidNotReceiveWithAnyArgs().Warning(null, null); progress.DidNotReceiveWithAnyArgs().Error(null, null); progress.DidNotReceiveWithAnyArgs().Exception(null, null); progress.DidNotReceiveWithAnyArgs().Exception(null, null, null); Received.InOrder(delegate { progress.NeedsUnsatisfiedValue(urlConfig, "SOME_NODE/cc:NEEDS[mod3]"); progress.NeedsUnsatisfiedValue(urlConfig, "SOME_NODE/INNER_NODE_2/hh:NEEDS[mod3]"); progress.NeedsUnsatisfiedNode(urlConfig, "SOME_NODE/INNER_NODE_2/INNER_INNER_NODE_12:NEEDS[mod3]"); progress.NeedsUnsatisfiedValue(urlConfig, "SOME_NODE/INNER_NODE_3/nn:NEEDS[mod3]"); progress.NeedsUnsatisfiedNode(urlConfig, "SOME_NODE/INNER_NODE_3/INNER_INNER_NODE_22:NEEDS[mod3]"); progress.NeedsUnsatisfiedNode(urlConfig, "SOME_NODE/INNER_NODE_4:NEEDS[mod3]"); }); Assert.Equal(2, node.values.Count); Assert.Equal(3, node.nodes.Count); Assert.Equal("aa", node.values[0].name); Assert.Equal("00", node.values[0].value); Assert.Equal("bb", node.values[1].name); Assert.Equal("01", node.values[1].value); Assert.Same(node.nodes[0], node.nodes[0]); Assert.Equal("INNER_NODE_1", node.nodes[0].name); Assert.Equal(2, node.nodes[0].values.Count); Assert.Equal(1, node.nodes[0].nodes.Count); Assert.Equal("dd", node.nodes[0].values[0].name); Assert.Equal("03", node.nodes[0].values[0].value); Assert.Equal("ee", node.nodes[0].values[1].name); Assert.Equal("04", node.nodes[0].values[1].value); Assert.Equal("INNER_INNER_NODE_1", node.nodes[0].nodes[0].name); Assert.Equal(1, node.nodes[0].nodes[0].values.Count); Assert.Equal(0, node.nodes[0].nodes[0].nodes.Count); Assert.Equal("ff", node.nodes[0].nodes[0].values[0].name); Assert.Equal("05", node.nodes[0].nodes[0].values[0].value); // Assert.NotSame(node.nodes[1], newNode.nodes[1]); Assert.Equal("INNER_NODE_2", node.nodes[1].name); Assert.Equal(2, node.nodes[1].values.Count); Assert.Equal(2, node.nodes[1].nodes.Count); Assert.Equal("gg", node.nodes[1].values[0].name); Assert.Equal("06", node.nodes[1].values[0].value); Assert.Equal("ii", node.nodes[1].values[1].name); Assert.Equal("08", node.nodes[1].values[1].value); Assert.Equal("INNER_INNER_NODE_11", node.nodes[1].nodes[0].name); Assert.Equal("jj", node.nodes[1].nodes[0].values[0].name); Assert.Equal("09", node.nodes[1].nodes[0].values[0].value); Assert.Equal("INNER_INNER_NODE_12", node.nodes[1].nodes[1].name); Assert.Equal("kk", node.nodes[1].nodes[1].values[0].name); Assert.Equal("10", node.nodes[1].nodes[1].values[0].value); // Assert.NotSame(node.nodes[1], newNode.nodes[1]); Assert.Equal("INNER_NODE_3", node.nodes[2].name); Assert.Equal(2, node.nodes[2].values.Count); Assert.Equal(2, node.nodes[2].nodes.Count); Assert.Equal("mm", node.nodes[2].values[0].name); Assert.Equal("12", node.nodes[2].values[0].value); Assert.Equal("oo", node.nodes[2].values[1].name); Assert.Equal("14", node.nodes[2].values[1].value); Assert.Equal("INNER_INNER_NODE_21", node.nodes[2].nodes[0].name); Assert.Equal("pp", node.nodes[2].nodes[0].values[0].name); Assert.Equal("15", node.nodes[2].nodes[0].values[0].value); Assert.Equal("INNER_INNER_NODE_22", node.nodes[2].nodes[1].name); Assert.Equal("qq", node.nodes[2].nodes[1].values[0].name); Assert.Equal("16", node.nodes[2].nodes[1].values[0].value); }
public void TestApplyPatches() { IBasicLogger logger = Substitute.For <IBasicLogger>(); IPatchProgress progress = Substitute.For <IPatchProgress>(); PatchApplier patchApplier = new PatchApplier(progress, logger); UrlDir.UrlFile file1 = UrlBuilder.CreateFile("abc/def.cfg"); UrlDir.UrlFile file2 = UrlBuilder.CreateFile("ghi/jkl.cfg"); IPass pass1 = Substitute.For <IPass>(); IPass pass2 = Substitute.For <IPass>(); IPass pass3 = Substitute.For <IPass>(); pass1.Name.Returns(":PASS1"); pass2.Name.Returns(":PASS2"); pass3.Name.Returns(":PASS3"); UrlDir.UrlConfig[] patchUrlConfigs = new UrlDir.UrlConfig[9]; IPatch[] patches = new IPatch[9]; for (int i = 0; i < patches.Length; i++) { patches[i] = Substitute.For <IPatch>(); } pass1.GetEnumerator().Returns(new ArrayEnumerator <IPatch>(patches[0], patches[1], patches[2])); pass2.GetEnumerator().Returns(new ArrayEnumerator <IPatch>(patches[3], patches[4], patches[5])); pass3.GetEnumerator().Returns(new ArrayEnumerator <IPatch>(patches[6], patches[7], patches[8])); IPass[] patchList = new IPass[] { pass1, pass2, pass3 }; patchApplier.ApplyPatches(new[] { file1, file2 }, new[] { pass1, pass2, pass3 }); progress.DidNotReceiveWithAnyArgs().Error(null, null); progress.DidNotReceiveWithAnyArgs().Exception(null, null); progress.DidNotReceiveWithAnyArgs().Exception(null, null, null); logger.DidNotReceive().Log(LogType.Warning, Arg.Any <string>()); logger.DidNotReceive().Log(LogType.Error, Arg.Any <string>()); logger.DidNotReceiveWithAnyArgs().Exception(null, null); Received.InOrder(delegate { logger.Log(LogType.Log, ":PASS1 pass"); patches[0].Apply(file1, progress, logger); patches[0].Apply(file2, progress, logger); progress.PatchApplied(); patches[1].Apply(file1, progress, logger); patches[1].Apply(file2, progress, logger); progress.PatchApplied(); patches[2].Apply(file1, progress, logger); patches[2].Apply(file2, progress, logger); progress.PatchApplied(); logger.Log(LogType.Log, ":PASS2 pass"); patches[3].Apply(file1, progress, logger); patches[3].Apply(file2, progress, logger); progress.PatchApplied(); patches[4].Apply(file1, progress, logger); patches[4].Apply(file2, progress, logger); progress.PatchApplied(); patches[5].Apply(file1, progress, logger); patches[5].Apply(file2, progress, logger); progress.PatchApplied(); logger.Log(LogType.Log, ":PASS3 pass"); patches[6].Apply(file1, progress, logger); patches[6].Apply(file2, progress, logger); progress.PatchApplied(); patches[7].Apply(file1, progress, logger); patches[7].Apply(file2, progress, logger); progress.PatchApplied(); patches[8].Apply(file1, progress, logger); patches[8].Apply(file2, progress, logger); progress.PatchApplied(); }); }
public void TestApply() { UrlDir.UrlFile file = UrlBuilder.CreateFile("abc/def.cfg"); UrlDir.UrlConfig urlConfig1 = UrlBuilder.CreateConfig(new TestConfigNode("NODE") { { "foo", "bar" }, }, file); UrlDir.UrlConfig urlConfig2 = UrlBuilder.CreateConfig(new TestConfigNode("NODE") { { "foo", "bar" }, }, file); UrlDir.UrlConfig urlConfig3 = UrlBuilder.CreateConfig(new ConfigNode("NODE"), file); UrlDir.UrlConfig urlConfig4 = UrlBuilder.CreateConfig(new ConfigNode("NODE"), file); INodeMatcher nodeMatcher = Substitute.For <INodeMatcher>(); nodeMatcher.IsMatch(urlConfig1.config).Returns(false); nodeMatcher.IsMatch(urlConfig2.config).Returns(true); nodeMatcher.IsMatch(urlConfig3.config).Returns(false); nodeMatcher.IsMatch(urlConfig4.config).Returns(true); EditPatch patch = new EditPatch(UrlBuilder.CreateConfig("ghi/jkl", new TestConfigNode("@NODE") { { "@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(4, file.configs.Count); Assert.Same(urlConfig1, file.configs[0]); AssertNodesEqual(new TestConfigNode("NODE") { { "foo", "bar" }, }, file.configs[0].config); Assert.NotSame(urlConfig2, file.configs[1]); AssertNodesEqual(new TestConfigNode("NODE") { { "foo", "baz" }, { "pqr", "stw" }, }, file.configs[1].config); Assert.Same(urlConfig3, file.configs[2]); AssertNodesEqual(new ConfigNode("NODE"), file.configs[2].config); Assert.NotSame(urlConfig4, file.configs[3]); AssertNodesEqual(new TestConfigNode("NODE") { { "pqr", "stw" }, }, file.configs[3].config); Received.InOrder(delegate { progress.ApplyingUpdate(urlConfig2, patch.UrlConfig); progress.ApplyingUpdate(urlConfig4, patch.UrlConfig); }); progress.DidNotReceiveWithAnyArgs().ApplyingCopy(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__Loop() { UrlDir.UrlFile file = UrlBuilder.CreateFile("abc/def.cfg"); UrlDir.UrlConfig urlConfig = UrlBuilder.CreateConfig(new TestConfigNode("NODE") { { "name", "000" }, { "aaa", "1" }, }, file); INodeMatcher nodeMatcher = Substitute.For <INodeMatcher>(); nodeMatcher.IsMatch(Arg.Is <ConfigNode>(node => int.Parse(node.GetValue("aaa")) < 10)).Returns(true); EditPatch patch = new EditPatch(UrlBuilder.CreateConfig("ghi/jkl", new TestConfigNode("@NODE") { { "@aaa *", "2" }, { "bbb", "002" }, new ConfigNode("MM_PATCH_LOOP"), }), nodeMatcher, Substitute.For <IPassSpecifier>()); IPatchProgress progress = Substitute.For <IPatchProgress>(); IBasicLogger logger = Substitute.For <IBasicLogger>(); List <UrlDir.UrlConfig> modifiedUrlConfigs = new List <UrlDir.UrlConfig>(); progress.ApplyingUpdate(Arg.Do <UrlDir.UrlConfig>(url => modifiedUrlConfigs.Add(url)), patch.UrlConfig); patch.Apply(file, progress, logger); Assert.Equal(1, file.configs.Count); Assert.NotSame(urlConfig, file.configs[0]); AssertNodesEqual(new TestConfigNode("NODE") { { "name", "000" }, { "aaa", "16" }, { "bbb", "002" }, { "bbb", "002" }, { "bbb", "002" }, { "bbb", "002" }, }, file.configs[0].config); Assert.Same(urlConfig, modifiedUrlConfigs[0]); Assert.NotSame(urlConfig, modifiedUrlConfigs[1]); Assert.NotSame(urlConfig, modifiedUrlConfigs[2]); Assert.NotSame(urlConfig, modifiedUrlConfigs[3]); Received.InOrder(delegate { logger.Log(LogType.Log, "Looping on ghi/jkl/@NODE to abc/def/NODE"); progress.ApplyingUpdate(urlConfig, patch.UrlConfig); progress.ApplyingUpdate(modifiedUrlConfigs[1], patch.UrlConfig); progress.ApplyingUpdate(modifiedUrlConfigs[2], patch.UrlConfig); progress.ApplyingUpdate(modifiedUrlConfigs[3], patch.UrlConfig); }); progress.DidNotReceiveWithAnyArgs().ApplyingCopy(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 TestApplyPatches() { IBasicLogger logger = Substitute.For <IBasicLogger>(); IPatchProgress progress = Substitute.For <IPatchProgress>(); PatchApplier patchApplier = new PatchApplier(progress, logger); IPass pass1 = Substitute.For <IPass>(); IPass pass2 = Substitute.For <IPass>(); IPass pass3 = Substitute.For <IPass>(); pass1.Name.Returns(":PASS1"); pass2.Name.Returns(":PASS2"); pass3.Name.Returns(":PASS3"); UrlDir.UrlConfig[] patchUrlConfigs = new UrlDir.UrlConfig[9]; IPatch[] patches = new IPatch[9]; for (int i = 0; i < patches.Length; i++) { patches[i] = Substitute.For <IPatch>(); } patches[0].CountsAsPatch.Returns(false); patches[1].CountsAsPatch.Returns(false); patches[2].CountsAsPatch.Returns(false); patches[3].CountsAsPatch.Returns(true); patches[4].CountsAsPatch.Returns(true); patches[5].CountsAsPatch.Returns(true); patches[6].CountsAsPatch.Returns(true); patches[7].CountsAsPatch.Returns(true); patches[8].CountsAsPatch.Returns(true); pass1.GetEnumerator().Returns(new ArrayEnumerator <IPatch>(patches[0], patches[1], patches[2])); pass2.GetEnumerator().Returns(new ArrayEnumerator <IPatch>(patches[3], patches[4], patches[5])); pass3.GetEnumerator().Returns(new ArrayEnumerator <IPatch>(patches[6], patches[7], patches[8])); IPass[] patchList = new IPass[] { pass1, pass2, pass3 }; LinkedList <IProtoUrlConfig> databaseConfigs = Assert.IsType <LinkedList <IProtoUrlConfig> >(patchApplier.ApplyPatches(new[] { pass1, pass2, pass3 })); progress.DidNotReceiveWithAnyArgs().Error(null, null); progress.DidNotReceiveWithAnyArgs().Exception(null, null); progress.DidNotReceiveWithAnyArgs().Exception(null, null, null); logger.AssertNoWarning(); logger.AssertNoError(); logger.AssertNoException(); Received.InOrder(delegate { progress.PassStarted(pass1); patches[0].Apply(databaseConfigs, progress, logger); patches[1].Apply(databaseConfigs, progress, logger); patches[2].Apply(databaseConfigs, progress, logger); progress.PassStarted(pass2); patches[3].Apply(databaseConfigs, progress, logger); progress.PatchApplied(); patches[4].Apply(databaseConfigs, progress, logger); progress.PatchApplied(); patches[5].Apply(databaseConfigs, progress, logger); progress.PatchApplied(); progress.PassStarted(pass3); patches[6].Apply(databaseConfigs, progress, logger); progress.PatchApplied(); patches[7].Apply(databaseConfigs, progress, logger); progress.PatchApplied(); patches[8].Apply(databaseConfigs, progress, logger); progress.PatchApplied(); }); }
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 TestApply() { UrlDir.UrlFile file = UrlBuilder.CreateFile("abc/def.cfg"); ConfigNode config1 = new TestConfigNode("NODE") { { "foo", "bar" }, }; ConfigNode config2 = new TestConfigNode("NODE") { { "foo", "bar" }, }; ConfigNode config3 = new ConfigNode("NODE"); ConfigNode config4 = new ConfigNode("NODE"); INodeMatcher nodeMatcher = Substitute.For <INodeMatcher>(); nodeMatcher.IsMatch(config1).Returns(false); nodeMatcher.IsMatch(config2).Returns(true); nodeMatcher.IsMatch(config3).Returns(false); nodeMatcher.IsMatch(config4).Returns(true); EditPatch patch = new EditPatch(UrlBuilder.CreateConfig("ghi/jkl", new TestConfigNode("@NODE") { { "@foo", "baz" }, { "pqr", "stw" }, }), nodeMatcher, Substitute.For <IPassSpecifier>()); IProtoUrlConfig urlConfig1 = Substitute.For <IProtoUrlConfig>(); IProtoUrlConfig urlConfig2 = Substitute.For <IProtoUrlConfig>(); IProtoUrlConfig urlConfig3 = Substitute.For <IProtoUrlConfig>(); IProtoUrlConfig urlConfig4 = Substitute.For <IProtoUrlConfig>(); urlConfig1.Node.Returns(config1); urlConfig2.Node.Returns(config2); urlConfig3.Node.Returns(config3); urlConfig4.Node.Returns(config4); urlConfig1.UrlFile.Returns(file); urlConfig2.UrlFile.Returns(file); urlConfig3.UrlFile.Returns(file); urlConfig4.UrlFile.Returns(file); LinkedList <IProtoUrlConfig> configs = new LinkedList <IProtoUrlConfig>(); configs.AddLast(urlConfig1); configs.AddLast(urlConfig2); configs.AddLast(urlConfig3); configs.AddLast(urlConfig4); IPatchProgress progress = Substitute.For <IPatchProgress>(); IBasicLogger logger = Substitute.For <IBasicLogger>(); patch.Apply(configs, progress, logger); IProtoUrlConfig[] newConfigs = configs.ToArray(); Assert.Equal(4, newConfigs.Length); Assert.Same(urlConfig1, newConfigs[0]); AssertNodesEqual(new TestConfigNode("NODE") { { "foo", "bar" }, }, newConfigs[0].Node); AssertNodesEqual(new TestConfigNode("NODE") { { "foo", "baz" }, { "pqr", "stw" }, }, newConfigs[1].Node); Assert.Same(file, newConfigs[1].UrlFile); Assert.Same(urlConfig3, newConfigs[2]); AssertNodesEqual(new ConfigNode("NODE"), newConfigs[2].Node); AssertNodesEqual(new TestConfigNode("NODE") { { "pqr", "stw" }, }, newConfigs[3].Node); Assert.Same(file, newConfigs[3].UrlFile); Received.InOrder(delegate { progress.ApplyingUpdate(urlConfig2, patch.UrlConfig); progress.ApplyingUpdate(urlConfig4, patch.UrlConfig); }); progress.DidNotReceiveWithAnyArgs().ApplyingCopy(null, null); progress.DidNotReceiveWithAnyArgs().ApplyingDelete(null, null); progress.DidNotReceiveWithAnyArgs().Error(null, null); progress.DidNotReceiveWithAnyArgs().Exception(null, null); progress.DidNotReceiveWithAnyArgs().Exception(null, null, null); }