Beispiel #1
0
        /// <summary>
        /// Adds the diff items contained into the specified set to the current set.
        /// </summary>
        /// <param name="items">The diff items to be added.</param>
        /// <returns>A reference to the builder itself.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="items"/> is null.</exception>
        public DiffSetBuilder Add(DiffSet items)
        {
            if (items == null)
            {
                throw new ArgumentNullException("items");
            }

            foreach (var item in items)
            {
                Add(item);
            }

            return(this);
        }
Beispiel #2
0
        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());
        }