private DiffSet FindAttributes(IList <int> notified, bool invert, DiffType diffType) { var builder = new DiffSetBuilder(); var mask = new List <int>(); var source = invert ? expected : actual; var pool = invert ? actual : expected; for (int i = 0; i < source.Count; i++) { int j = Find(pool, source[i], mask); if (j < 0) { var targets = invert ? DiffTargets.Expected : DiffTargets.Actual; builder.Add(new Diff(diffType, (invert ? pathExpected : path).Attribute(i), targets)); } else { int k = invert ? j : i; DiffSet diffSet = actual[k].Diff(expected[invert ? i : j], path, pathExpected, options); if (!diffSet.IsEmpty && !notified.Contains(k)) { builder.Add(diffSet); notified.Add(k); } mask.Add(j); } } return(builder.ToDiffSet()); }
private DiffSet FindElements(IList <int> notified, bool invert, DiffType diffType) { var builder = new DiffSetBuilder(); var mask = new List <int>(); var noExactMatch = new List <int>(); var source = invert ? expected : actual; var pool = invert ? actual : expected; // Find first exact match (= empty diff) for (int i = 0; i < source.Count; i++) { int j = pool.FindIndex(x => !mask.Contains(x) && source[i].Diff(pool[x], XmlPathRoot.Strict.Empty, XmlPathRoot.Strict.Empty, options).IsEmpty); if (j < 0) { noExactMatch.Add(i); } else { mask.Add(j); } } // Find first name-only match for the remaining items without exact match. foreach (int i in noExactMatch) { int j = pool.FindIndex(x => !mask.Contains(x) && source[i].AreNamesEqual(pool[x].Name, options)); if (j < 0) { builder.Add(new Diff(diffType, (invert ? pathExpected : path).Element(i), invert ? DiffTargets.Expected : DiffTargets.Actual)); } else { int k = invert ? j : i; DiffSet diffSet = actual[k].Diff(expected[invert ? i : j], path, pathExpected, options); if (!diffSet.IsEmpty && !notified.Contains(k)) { builder.Add(diffSet); notified.Add(k); } mask.Add(j); } } return(builder.ToDiffSet()); }
/// <summary> /// Constructs a diff item. /// </summary> /// <param name="diffType">The type of the diff.</param> /// <param name="path">The path of the difference.</param> /// <param name="targets">Indicates which XML fragment is targeted by the diff.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="diffType"/> or <paramref name="path"/> is null.</exception> /// <exception cref="ArgumentException">Thrown if <paramref name="diffType"/> or <paramref name="path"/> is empty.</exception> public Diff(DiffType diffType, IXmlPathStrict path, DiffTargets targets) { if (diffType == null) { throw new ArgumentNullException("diffType"); } if (path == null) { throw new ArgumentNullException("path"); } this.diffType = diffType; this.path = path; this.targets = targets; }
private OrderedItemType(DiffType diffTypeUnexpected, DiffType diffTypeMissing, Func <IXmlPathStrict, int, IXmlPathStrict> pathExtender) { this.diffTypeUnexpected = diffTypeUnexpected; this.diffTypeMissing = diffTypeMissing; this.pathExtender = pathExtender; }