private void MergeTestCore <T>(IList <T> source, IList <T> target, ExpectedCollectionChange expectedCollectionChange, IEqualityComparer <T>?comparer = null, bool useMoveAction = false) { var insertCounter = 0; var removeCounter = 0; var resetCounter = 0; var moveCounter = 0; void InsertAction(int idx, T item) { target.Insert(idx, item); insertCounter++; } void RemoveAction(int idx) { target.RemoveAt(idx); removeCounter++; } void ResetAction() { target.Clear(); foreach (var item in source) { target.Add(item); } resetCounter++; } Action <int, int>?moveAction = null; if (useMoveAction) { moveAction = (oldIndex, newIndex) => { T item = target[oldIndex]; target.RemoveAt(oldIndex); target.Insert(newIndex, item); moveCounter++; } } ; if (useMoveAction) { target.Merge(new ReadOnlyCollection <T>(source), comparer, InsertAction, RemoveAction, ResetAction, moveAction); } else { target.Merge(new ReadOnlyCollection <T>(source), comparer, InsertAction, RemoveAction, ResetAction); } AssertHelper.SequenceEqual(target, source, comparer ?? EqualityComparer <T> .Default); Assert.AreEqual(expectedCollectionChange == ExpectedCollectionChange.Insert ? 1 : 0, insertCounter); Assert.AreEqual(expectedCollectionChange == ExpectedCollectionChange.Remove ? 1 : 0, removeCounter); Assert.AreEqual(expectedCollectionChange == ExpectedCollectionChange.Reset ? 1 : 0, resetCounter); Assert.AreEqual(expectedCollectionChange == ExpectedCollectionChange.Move ? 1 : 0, moveCounter); }
private void MergeTestCore <T>(IList <T> source, IList <T> target, ExpectedCollectionChange expectedCollectionChange, IEqualityComparer <T> comparer = null) { var insertCounter = 0; var removeCounter = 0; var resetCounter = 0; Action <int, T> insertAction = (idx, item) => insertCounter++; Action <int> removeAction = idx => removeCounter++; Action resetAction = () => resetCounter++; ListMerger.Merge(new ReadOnlyCollection <T>(source), target, comparer, insertAction, removeAction, resetAction); Assert.AreEqual(expectedCollectionChange == ExpectedCollectionChange.Insert ? 1 : 0, insertCounter); Assert.AreEqual(expectedCollectionChange == ExpectedCollectionChange.Remove ? 1 : 0, removeCounter); Assert.AreEqual(expectedCollectionChange == ExpectedCollectionChange.Reset ? 1 : 0, resetCounter); }
private void MergeTestCore <T>(IList <T> source, IList <T> target, ExpectedCollectionChange expectedCollectionChange, IEqualityComparer <T> comparer = null, bool useMoveAction = false) { var insertCounter = 0; var removeCounter = 0; var resetCounter = 0; var moveCounter = 0; Action <int, T> insertAction = (idx, item) => { target.Insert(idx, item); insertCounter++; }; Action <int> removeAction = idx => { target.RemoveAt(idx); removeCounter++; }; Action resetAction = () => { target.Clear(); foreach (var item in source) { target.Add(item); } resetCounter++; }; Action <int, int> moveAction = null; if (useMoveAction) { moveAction = (int oldIndex, int newIndex) => { T item = target[oldIndex]; target.RemoveAt(oldIndex); target.Insert(newIndex, item); moveCounter++; } } ; target.Merge(new ReadOnlyCollection <T>(source), comparer, insertAction, removeAction, resetAction, moveAction); Assert.IsTrue(target.SequenceEqual(source, comparer ?? EqualityComparer <T> .Default)); Assert.AreEqual(expectedCollectionChange == ExpectedCollectionChange.Insert ? 1 : 0, insertCounter); Assert.AreEqual(expectedCollectionChange == ExpectedCollectionChange.Remove ? 1 : 0, removeCounter); Assert.AreEqual(expectedCollectionChange == ExpectedCollectionChange.Reset ? 1 : 0, resetCounter); Assert.AreEqual(expectedCollectionChange == ExpectedCollectionChange.Move ? 1 : 0, moveCounter); }