private Func <ComparisonState> UnmatchedTestNodes(IList <XmlNode> testListForXpath, IList <XmlNode> testList, XPathContext testContext, ICollection <XmlNode> seen, XPathContext controlContext) { return(() => { ComparisonState chain = new OngoingComparisonState(this); int testSize = testList.Count; for (int i = 0; i < testSize; i++) { if (!seen.Contains(testList[i])) { testContext.NavigateToChild(testListForXpath.IndexOf(testList[i])); try { chain = chain .AndThen(new Comparison(ComparisonType.CHILD_LOOKUP, null, null, null, GetXPath(controlContext), testList[i], GetXPath(testContext), testList[i].GetQName(), GetParentXPath(testContext))); } finally { testContext.NavigateToParent(); } } } return chain; }); }
/// <summary> /// Matches nodes of two node lists and invokes compareNode on /// each pair. /// </summary> /// <remarks> /// Also performs CHILD_LOOKUP comparisons for each node that /// couldn't be matched to one of the "other" list. /// </remarks> private ComparisonState CompareNodeLists(IEnumerable <XmlNode> allControlChildren, IEnumerable <XmlNode> controlSeq, XPathContext controlContext, IEnumerable <XmlNode> allTestChildren, IEnumerable <XmlNode> testSeq, XPathContext testContext) { ComparisonState chain = new OngoingComparisonState(this); IEnumerable <KeyValuePair <XmlNode, XmlNode> > matches = NodeMatcher.Match(controlSeq, testSeq); IList <XmlNode> controlListForXpath = new List <XmlNode>(allControlChildren); IList <XmlNode> testListForXpath = new List <XmlNode>(allTestChildren); IList <XmlNode> controlList = new List <XmlNode>(controlSeq); IList <XmlNode> testList = new List <XmlNode>(testSeq); ICollection <XmlNode> seen = new HashSet <XmlNode>(); foreach (KeyValuePair <XmlNode, XmlNode> pair in matches) { XmlNode control = pair.Key; seen.Add(control); XmlNode test = pair.Value; seen.Add(test); int controlIndexForXpath = controlListForXpath.IndexOf(control); int testIndexForXpath = testListForXpath.IndexOf(test); int controlIndex = controlList.IndexOf(control); int testIndex = testList.IndexOf(test); controlContext.NavigateToChild(controlIndexForXpath); testContext.NavigateToChild(testIndexForXpath); try { chain = chain.AndThen(new Comparison(ComparisonType.CHILD_NODELIST_SEQUENCE, control, GetXPath(controlContext), controlIndex, GetParentXPath(controlContext), test, GetXPath(testContext), testIndex, GetParentXPath(testContext))) .AndThen(() => CompareNodes(control, controlContext, test, testContext)); } finally { testContext.NavigateToParent(); controlContext.NavigateToParent(); } } return(chain .AndThen(UnmatchedControlNodes(controlListForXpath, controlList, controlContext, seen, testContext)) .AndThen(UnmatchedTestNodes(testListForXpath, testList, testContext, seen, controlContext))); }
private Func <ComparisonState> NormalAttributeComparer(XmlElement control, XPathContext controlContext, Attributes controlAttributes, XmlElement test, XPathContext testContext, Attributes testAttributes) { return(() => { ComparisonState chain = new OngoingComparisonState(this); ICollection <XmlAttribute> foundTestAttributes = new HashSet <XmlAttribute>(); foreach (XmlAttribute controlAttr in controlAttributes.RemainingAttributes) { XmlQualifiedName controlAttrName = controlAttr.GetQName(); XmlAttribute testAttr = FindMatchingAttr(testAttributes.RemainingAttributes, controlAttr); XmlQualifiedName testAttrName = testAttr != null ? testAttr.GetQName() : null; controlContext.NavigateToAttribute(controlAttrName); try { chain = chain.AndThen(new Comparison(ComparisonType.ATTR_NAME_LOOKUP, control, GetXPath(controlContext), controlAttrName, GetParentXPath(controlContext), test, GetXPath(testContext), testAttrName, GetParentXPath(testContext))); if (testAttr != null) { testContext.NavigateToAttribute(testAttrName); try { chain = chain.AndThen(() => CompareNodes(controlAttr, controlContext, testAttr, testContext)); foundTestAttributes.Add(testAttr); } finally { testContext.NavigateToParent(); } } } finally { controlContext.NavigateToParent(); } } return chain.AndThen(() => { ComparisonState secondChain = new OngoingComparisonState(this); foreach (XmlAttribute testAttr in testAttributes.RemainingAttributes) { if (!foundTestAttributes.Contains(testAttr)) { XmlQualifiedName testAttrName = testAttr.GetQName(); testContext.NavigateToAttribute(testAttrName); try { secondChain = secondChain .AndThen(new Comparison(ComparisonType.ATTR_NAME_LOOKUP, control, GetXPath(controlContext), null, GetParentXPath(controlContext), test, GetXPath(testContext), testAttrName, GetParentXPath(testContext))); } finally { testContext.NavigateToParent(); } } } return secondChain; }); }); }