public void CanFindByMatchingAttributeNames() { const string sourceXml = @"<?xml version='1.0' encoding='utf-8'?> <ldml> <special xmlns:palaso='urn://palaso.org/ldmlExtensions/v1' /> </ldml>"; const string otherXml = @"<?xml version='1.0' encoding='utf-8'?> <ldml> <special xmlns:fw='urn://fieldworks.sil.org/ldmlExtensions/v1' /> <special xmlns:palaso='urn://palaso.org/ldmlExtensions/v1' /> </ldml>"; var sourceDoc = new XmlDocument(); sourceDoc.LoadXml(sourceXml); var nodeToMatch = sourceDoc.DocumentElement.FirstChild; var otherDoc = new XmlDocument(); otherDoc.LoadXml(otherXml); var nodeMatcher = new FindByMatchingAttributeNames(new HashSet <string> { "xmlns:palaso" }); Assert.AreSame(otherDoc.DocumentElement.ChildNodes[1], nodeMatcher.GetNodeToMerge(nodeToMatch, otherDoc.DocumentElement, SetFromChildren.Get(otherDoc.DocumentElement))); }
public void FindsNoMatchWhereTooFewOccurrences() { var doc = new XmlDocument(); var parent = XmlUtilities.GetDocumentNodeFromRawXml(@"<a><b key='one'/><b key='two'/></a>", doc); var target = XmlUtilities.GetDocumentNodeFromRawXml(@"<a><b key='one'/><b key='one'/></a>", doc).ChildNodes[1]; var finder = new FindByKeyAttributeInList("key"); Assert.That(finder.GetNodeToMerge(target, parent, SetFromChildren.Get(parent)), Is.Null); }
public void FindsCorrespondingMatchInSecondPlace() { var doc = new XmlDocument(); var parent = XmlUtilities.GetDocumentNodeFromRawXml(@"<a><b key='one'/><b key='two'/><b key='one'/></a>", doc); var target = XmlUtilities.GetDocumentNodeFromRawXml(@"<a><b key='one'/><b key='one'/></a>", doc).ChildNodes[1]; var finder = new FindByKeyAttributeInList("key"); Assert.That(finder.GetNodeToMerge(target, parent, SetFromChildren.Get(parent)), Is.EqualTo(parent.ChildNodes[2])); }
public void FindsNothingWithNoKey() { var doc = new XmlDocument(); var parent = XmlUtilities.GetDocumentNodeFromRawXml(@"<a><b key='one'/></a>", doc); var target = XmlUtilities.GetDocumentNodeFromRawXml(@"<b/>", doc); var finder = new FindByKeyAttributeInList("key"); Assert.That(finder.GetNodeToMerge(target, parent, SetFromChildren.Get(parent)), Is.Null); }
public void GetNodeToMerge_TextOnlyRegression_DoesntThrow() { var doc1 = new XmlDocument(); doc1.LoadXml(@"<dummy/>"); var doc2 = new XmlDocument(); doc2.LoadXml(@"<textHolder>hello</textHolder>"); var node = doc2.SelectSingleNode("//textHolder"); var finder = new FindByEqualityOfTree(); finder.GetNodeToMerge(doc1, node, SetFromChildren.Get(node)); }
public void GetNodeToMerge_WithoutKeyAttr_ReturnsNull() { const string xml = @"<a> <b /> </a>" ; var doc1 = new XmlDocument(); doc1.LoadXml(xml); var finder = new FindByKeyAttribute("id"); var node = doc1.SelectSingleNode("//b"); Assert.That(finder.GetNodeToMerge(node, doc1.DocumentElement, SetFromChildren.Get(doc1.DocumentElement)), Is.Null); }
public void GetNodeToMerge_WithDoubleAndSingleQuotesInAttribute_FindsIt() { string xml = @"<lift> <entry id='she said "It's raining!"' /> </lift>" ; var doc1 = new XmlDocument(); doc1.LoadXml(xml); var finder = new FindByKeyAttribute("id"); var node = doc1.SelectSingleNode("//entry"); var result = finder.GetNodeToMerge(node, doc1.DocumentElement, SetFromChildren.Get(doc1.DocumentElement)); Assert.AreEqual(node, result); }
public void GetNodeToMerge_ReturnsNode() { string xml = @"<lift> <entry id='test' /> </lift>" ; var doc1 = new XmlDocument(); doc1.LoadXml(xml); var finder = new FindByKeyAttribute("id"); var node = doc1.SelectSingleNode("//entry"); var result = finder.GetNodeToMerge(node, doc1.DocumentElement, SetFromChildren.Get(doc1.DocumentElement)); Assert.NotNull(result); XmlTestHelper.AssertXPathMatchesExactlyOne(result, "entry[@id=\"test\"]"); }
public void ExampleSentenceFinder_SingleIdenticalForm_FindsIt() { string ancestor = @"<?xml version='1.0' encoding='utf-8'?> <sense id='123'> <example> <form lang='chorus'> <text>This is my example sentence.</text> </form> </example> </sense>"; var dom = new XmlDocument(); dom.LoadXml(ancestor); var parent = dom.SelectSingleNode("//sense"); var guyToMatch = dom.SelectSingleNode("//example"); var finder = new ExampleSentenceFinder(); var match = finder.GetNodeToMerge(guyToMatch, parent, SetFromChildren.Get(parent)); Assert.AreEqual(guyToMatch.OuterXml, match.OuterXml); }
public void MultipleAttributeKeyedElement_IsFound() { const string sourceXml = @"<root> <CustomField name='Certified' class='WfiWordform' type='Boolean' /> </root>"; const string otherXml = @"<root> <CustomField name='IsComplete' class='WfiWordform' type='Boolean' /> <CustomField name='Certified' class='WfiWordform' type='Boolean' /> <CustomField name='Checkpoint' class='WfiWordform' type='String' /> </root>"; var sourceDoc = new XmlDocument(); sourceDoc.LoadXml(sourceXml); var nodeToMatch = sourceDoc.DocumentElement.FirstChild; var otherDoc = new XmlDocument(); otherDoc.LoadXml(otherXml); var nodeMatcher = new FindByMultipleKeyAttributes(new List <string> { "name", "class" }); var result = nodeMatcher.GetNodeToMerge(nodeToMatch, otherDoc.DocumentElement, SetFromChildren.Get(otherDoc.DocumentElement)); Assert.AreSame(otherDoc.DocumentElement.ChildNodes[1], result); }