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); }
public void MultipleAttributeKeyedElement_WithDoubleAndSingleQuoteInAttribute_IsFound() { const string sourceXml = @"<root> <CustomField name='First quoted "Apostrophe's"' class='Second quoted "Apostrophe's"' type='Boolean' /> </root>"; const string otherXml = @"<root> <CustomField name='IsComplete' class='WfiWordform' type='Boolean' /> <CustomField name='First quoted "Apostrophe's"' class='Second quoted "Apostrophe's"' 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" }); if (Platform.IsMono || otherDoc.DocumentElement == null) { return; } var acceptableTargets = new HashSet <XmlNode>(); foreach (XmlNode node in otherDoc.DocumentElement.ChildNodes) { acceptableTargets.Add(node); } var result = nodeMatcher.GetNodeToMerge(nodeToMatch, otherDoc.DocumentElement, acceptableTargets); Assert.AreSame(otherDoc.DocumentElement.ChildNodes[1], result); }