public void TestExtractPatch__NeedsUnsatisfiedPassSpecifier() { 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(true); passSpecifier.CheckNeeds(needsChecker, progress).Returns(false); Assert.Null(patchExtractor.ExtractPatch(urlConfig)); AssertNoErrors(); Assert.Empty(root.AllConfigs); needsChecker.DidNotReceiveWithAnyArgs().CheckNeedsRecursive(null, null); patchCompiler.DidNotReceiveWithAnyArgs().CompilePatch(null); progress.DidNotReceiveWithAnyArgs().NeedsUnsatisfiedRoot(null); }
public void TestPassSpecifier() { IPassSpecifier passSpecifier = Substitute.For <IPassSpecifier>(); EditPatch patch = new EditPatch(UrlBuilder.CreateConfig("abc/def", new ConfigNode()), Substitute.For <INodeMatcher>(), passSpecifier); Assert.Same(passSpecifier, patch.PassSpecifier); }
public void TestPassSpecifier() { IPassSpecifier passSpecifier = Substitute.For <IPassSpecifier>(); InsertPatch patch = new InsertPatch(UrlBuilder.CreateConfig("abc/def", new ConfigNode()), "A_NODE", passSpecifier); Assert.Same(passSpecifier, patch.PassSpecifier); }
public EditPatch(UrlDir.UrlConfig urlConfig, INodeMatcher nodeMatcher, IPassSpecifier passSpecifier) { UrlConfig = urlConfig ?? throw new ArgumentNullException(nameof(urlConfig)); NodeMatcher = nodeMatcher ?? throw new ArgumentNullException(nameof(nodeMatcher)); PassSpecifier = passSpecifier ?? throw new ArgumentNullException(nameof(passSpecifier)); loop = urlConfig.config.HasNode("MM_PATCH_LOOP"); }
public ProtoPatch(UrlDir.UrlConfig urlConfig, Command command, string nodeType, string nodeName, string needs, string has, IPassSpecifier passSpecifier) { this.urlConfig = urlConfig; this.command = command; this.nodeType = nodeType; this.nodeName = nodeName; this.needs = needs; this.has = has; this.passSpecifier = passSpecifier; }
public void TestExtractPatch__Insert() { 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.Insert, "NODE_TYPE", null, "needs", null, passSpecifier ); protoPatchBuilder.Build(urlConfig, Command.Insert, tagList).Returns(protoPatch); needsChecker.CheckNeedsExpression("needs").Returns(true); passSpecifier.CheckNeeds(needsChecker, progress).Returns(true); ConfigNode needsCheckedNode = null; needsChecker.CheckNeedsRecursive(Arg.Do <ConfigNode>(node => needsCheckedNode = node), urlConfig); Assert.Null(patchExtractor.ExtractPatch(urlConfig)); AssertNoErrors(); Received.InOrder(delegate { tagListParser.Parse("NODE_TYPE", urlConfig); protoPatchBuilder.Build(urlConfig, Command.Insert, tagList); needsChecker.CheckNeedsExpression("needs"); passSpecifier.CheckNeeds(needsChecker, progress); needsChecker.CheckNeedsRecursive(needsCheckedNode, urlConfig); }); patchCompiler.DidNotReceiveWithAnyArgs().CompilePatch(null); Assert.Equal(1, root.AllConfigs.Count()); UrlDir.UrlConfig newUrlConfig = root.AllConfigs.First(); Assert.NotSame(urlConfig, newUrlConfig); Assert.NotSame(urlConfig.config, newUrlConfig.config); AssertConfigNodesEqual(urlConfig.config, newUrlConfig.config); Assert.Same(needsCheckedNode, newUrlConfig.config); progress.DidNotReceiveWithAnyArgs().NeedsUnsatisfiedRoot(null); }
public void TestConstructor__UnknownPassSpecifier() { IPatch patch = Substitute.For <IPatch>(); UrlDir.UrlConfig urlConfig = UrlBuilder.CreateConfig("abc/def", new ConfigNode("NODE")); IPassSpecifier passSpecifier = Substitute.For <IPassSpecifier>(); passSpecifier.Descriptor.Returns(":SOMEPASS"); patch.PassSpecifier.Returns(passSpecifier); IPatchProgress progress = Substitute.For <IPatchProgress>(); NotImplementedException ex = Assert.Throws <NotImplementedException>(delegate { new PatchList(new string[0], new[] { patch }, progress); }); Assert.Equal("Don't know what to do with pass specifier: :SOMEPASS", ex.Message); progress.DidNotReceive().PatchAdded(); }
public CopyPatch(UrlDir.UrlConfig urlConfig, INodeMatcher nodeMatcher, IPassSpecifier passSpecifier) { UrlConfig = urlConfig ?? throw new ArgumentNullException(nameof(urlConfig)); NodeMatcher = nodeMatcher ?? throw new ArgumentNullException(nameof(nodeMatcher)); PassSpecifier = passSpecifier ?? throw new ArgumentNullException(nameof(passSpecifier)); }
public InsertPatch(UrlDir.UrlConfig urlConfig, string nodeType, IPassSpecifier passSpecifier) { UrlConfig = urlConfig ?? throw new ArgumentNullException(nameof(urlConfig)); NodeType = nodeType ?? throw new ArgumentNullException(nameof(nodeType)); PassSpecifier = passSpecifier ?? throw new ArgumentNullException(nameof(passSpecifier)); }
public ProtoPatch Build(UrlDir.UrlConfig urlConfig, Command command, ITagList tagList) { if (urlConfig == null) { throw new ArgumentNullException(nameof(urlConfig)); } if (tagList == null) { throw new ArgumentNullException(nameof(tagList)); } if (progress == null) { throw new ArgumentNullException(nameof(progress)); } bool error = false; string nodeType = tagList.PrimaryTag.key; string nodeName = tagList.PrimaryTag.value; if (command == Command.Insert && nodeName != null) { progress.Error(urlConfig, "name specifier detected on insert node (not a patch): " + urlConfig.SafeUrl()); error = true; } if (nodeName == string.Empty) { progress.Warning(urlConfig, "empty brackets detected on patch name: " + urlConfig.SafeUrl()); nodeName = null; } if (tagList.PrimaryTag.trailer != null) { progress.Warning(urlConfig, "unrecognized trailer: '" + tagList.PrimaryTag.trailer + "' on: " + urlConfig.SafeUrl()); } string needs = null; string has = null; IPassSpecifier passSpecifier = null; foreach (Tag tag in tagList) { if (tag.trailer != null) { progress.Warning(urlConfig, "unrecognized trailer: '" + tag.trailer + "' on: " + urlConfig.SafeUrl()); } if (tag.key.Equals("NEEDS", StringComparison.CurrentCultureIgnoreCase)) { if (needs != null) { progress.Warning(urlConfig, "more than one :NEEDS tag detected, ignoring all but the first: " + urlConfig.SafeUrl()); continue; } if (string.IsNullOrEmpty(tag.value)) { progress.Error(urlConfig, "empty :NEEDS tag detected: " + urlConfig.SafeUrl()); error = true; continue; } needs = tag.value; } else if (tag.key.Equals("HAS", StringComparison.CurrentCultureIgnoreCase)) { if (command == Command.Insert) { progress.Error(urlConfig, ":HAS detected on insert node (not a patch): " + urlConfig.SafeUrl()); error = true; continue; } if (has != null) { progress.Warning(urlConfig, "more than one :HAS tag detected, ignoring all but the first: " + urlConfig.SafeUrl()); continue; } if (string.IsNullOrEmpty(tag.value)) { progress.Error(urlConfig, "empty :HAS tag detected: " + urlConfig.SafeUrl()); error = true; continue; } has = tag.value; } else if (tag.key.Equals("FIRST", StringComparison.CurrentCultureIgnoreCase)) { if (tag.value != null) { progress.Warning(urlConfig, "value detected on :FIRST tag: " + urlConfig.SafeUrl()); } if (command == Command.Insert) { progress.Error(urlConfig, "pass specifier detected on insert node (not a patch): " + urlConfig.SafeUrl()); error = true; continue; } if (passSpecifier != null) { progress.Warning(urlConfig, "more than one pass specifier detected, ignoring all but the first: " + urlConfig.SafeUrl()); continue; } passSpecifier = new FirstPassSpecifier(); } else if (tag.key.Equals("BEFORE", StringComparison.CurrentCultureIgnoreCase)) { if (string.IsNullOrEmpty(tag.value)) { progress.Error(urlConfig, "empty :BEFORE tag detected: " + urlConfig.SafeUrl()); error = true; continue; } if (command == Command.Insert) { progress.Error(urlConfig, "pass specifier detected on insert node (not a patch): " + urlConfig.SafeUrl()); error = true; continue; } if (passSpecifier != null) { progress.Warning(urlConfig, "more than one pass specifier detected, ignoring all but the first: " + urlConfig.SafeUrl()); continue; } passSpecifier = new BeforePassSpecifier(tag.value, urlConfig); } else if (tag.key.Equals("FOR", StringComparison.CurrentCultureIgnoreCase)) { if (string.IsNullOrEmpty(tag.value)) { progress.Error(urlConfig, "empty :FOR tag detected: " + urlConfig.SafeUrl()); error = true; continue; } if (command == Command.Insert) { progress.Error(urlConfig, "pass specifier detected on insert node (not a patch): " + urlConfig.SafeUrl()); error = true; continue; } if (passSpecifier != null) { progress.Warning(urlConfig, "more than one pass specifier detected, ignoring all but the first: " + urlConfig.SafeUrl()); continue; } passSpecifier = new ForPassSpecifier(tag.value, urlConfig); } else if (tag.key.Equals("AFTER", StringComparison.CurrentCultureIgnoreCase)) { if (string.IsNullOrEmpty(tag.value)) { progress.Error(urlConfig, "empty :AFTER tag detected: " + urlConfig.SafeUrl()); error = true; continue; } if (command == Command.Insert) { progress.Error(urlConfig, "pass specifier detected on insert node (not a patch): " + urlConfig.SafeUrl()); error = true; continue; } if (passSpecifier != null) { progress.Warning(urlConfig, "more than one pass specifier detected, ignoring all but the first: " + urlConfig.SafeUrl()); continue; } passSpecifier = new AfterPassSpecifier(tag.value, urlConfig); } else if (tag.key.Equals("LAST", StringComparison.CurrentCultureIgnoreCase)) { if (string.IsNullOrEmpty(tag.value)) { progress.Error(urlConfig, "empty :LAST tag detected: " + urlConfig.SafeUrl()); error = true; continue; } if (command == Command.Insert) { progress.Error(urlConfig, "pass specifier detected on insert node (not a patch): " + urlConfig.SafeUrl()); error = true; continue; } if (passSpecifier != null) { progress.Warning(urlConfig, "more than one pass specifier detected, ignoring all but the first: " + urlConfig.SafeUrl()); continue; } passSpecifier = new LastPassSpecifier(tag.value); } else if (tag.key.Equals("FINAL", StringComparison.CurrentCultureIgnoreCase)) { if (tag.value != null) { progress.Warning(urlConfig, "value detected on :FINAL tag: " + urlConfig.SafeUrl()); } if (command == Command.Insert) { progress.Error(urlConfig, "pass specifier detected on insert node (not a patch): " + urlConfig.SafeUrl()); error = true; continue; } if (passSpecifier != null) { progress.Warning(urlConfig, "more than one pass specifier detected, ignoring all but the first: " + urlConfig.SafeUrl()); continue; } passSpecifier = new FinalPassSpecifier(); } else { progress.Warning(urlConfig, "unrecognized tag: '" + tag.key + "' on: " + urlConfig.SafeUrl()); } } if (error) { return(null); } if (passSpecifier == null) { if (command == Command.Insert) { passSpecifier = new InsertPassSpecifier(); } else { passSpecifier = new LegacyPassSpecifier(); } } return(new ProtoPatch(urlConfig, command, nodeType, nodeName, needs, has, passSpecifier)); }