public void Test_RemoveRangeRemoveTestMethod() { devDhMagic.MgcObservableCollection <int> collection = new devDhMagic.MgcObservableCollection <int>(); var toAdd = new[] { 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3 }; var toRemove = new[] { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 0, 0 }; collection.MgcAddRange(toAdd); collection.CollectionChanged += (s, e) => { if (e.Action != System.Collections.Specialized.NotifyCollectionChangedAction.Remove) { Assert.Fail("RemoveRange didn't use Remove like requested."); } if (e.OldItems == null) { Assert.Fail("OldItems should not be null."); } var expected = new int[] { 1, 1, 2, 2, 3, 3, 4, 5, 5, 6, 7, 8, 9, 9 }; if (expected.Length != e.OldItems.Count) { Assert.Fail("Expected and actual OldItems don't match."); } for (var i = 0; i < expected.Length; i++) { if (expected[i] != (int)e.OldItems[i]) { Assert.Fail("Expected and actual OldItems don't match."); } } }; collection.MgcRemoveRange(toRemove, NotifyCollectionChangedAction.Remove); }
public void Test_RemoveRange_should_NOT_mutate_source_when_source_data_is_present() { var sourceData = new List <int>(new[] { 1, 2, 3 }); devDhMagic.MgcObservableCollection <int> collection = new devDhMagic.MgcObservableCollection <int>(new[] { 1, 2, 3, 4, 5, 6 }); collection.MgcRemoveRange(sourceData, NotifyCollectionChangedAction.Remove); Assert.IsTrue(sourceData.Count == 3, "source data was mutated"); }
public void Test_RemoveRange_should_NOT_mutate_collection_when_source_data_is_not_present() { var sourceData = new List <int>(new[] { 1, 2, 3 }); devDhMagic.MgcObservableCollection <int> collection = new devDhMagic.MgcObservableCollection <int>(new[] { 4, 5, 6, 7, 8, 9 }); collection.MgcRemoveRange(sourceData, NotifyCollectionChangedAction.Remove); // the collection should not be modified if the source items are not found Assert.IsTrue(collection.Count == 6, "collection was mutated"); }
public void Test_RemoveRangeEmpty() { devDhMagic.MgcObservableCollection <int> collection = new devDhMagic.MgcObservableCollection <int>(); var toAdd = new[] { 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3 }; var toRemove = new int[0]; collection.MgcAddRange(toAdd); collection.CollectionChanged += (s, e) => { Assert.Fail("The event is raised."); }; collection.MgcRemoveRange(toRemove, NotifyCollectionChangedAction.Remove); }