public void RemoveRangeTest() { var source = new RangedObservableCollection <Person>(new[] { new Person { Name = "tanaka1", IsRemoved = false }, new Person { Name = "tanaka2", IsRemoved = true }, new Person { Name = "tanaka3", IsRemoved = false }, new Person { Name = "tanaka4", IsRemoved = true }, new Person { Name = "tanaka5", IsRemoved = false }, }); var filtered = source.ToFilteredReadOnlyObservableCollection(x => !x.IsRemoved); var buffer = new List <NotifyCollectionChangedEventArgs>(); filtered.Is(source[0], source[2], source[4]); source.RemoveRange(new[] { source[0], source[1], source[2], }); filtered.Is(source.Last()); }
public void RemoveRangeRaisesCorrectCollectionChangedEventForNonExistentRemoves() { var collection = new RangedObservableCollection <int>(); collection.AddRange(ItemsToAdd); collection.CollectionChanged += (s, e) => { Assert.Equal(NotifyCollectionChangedAction.Remove, e.Action); Assert.Equal(new[] { 1, 2, 3, 4, 5 }, e.OldItems); Assert.Null(e.NewItems); }; collection.RemoveRange(new[] { 1, 2, 3, 4, 5, 60, 70, 80, 90, 100 }); Assert.Equal(new[] { 6, 7, 8, 9, 0 }, collection.ToArray()); }
public void RemoveRangeRaisesCorrectCollectionChangedEvent() { var collection = new RangedObservableCollection <int>(); collection.AddRange(ItemsToAdd); collection.CollectionChanged += (s, e) => { Assert.Equal(NotifyCollectionChangedAction.Remove, e.Action); Assert.Equal(ItemsToAdd, e.OldItems); Assert.Null(e.NewItems); }; collection.RemoveRange(ItemsToAdd); Assert.Equal(new int[0], collection.ToArray()); }
public void RemoveRangeDoesNotRaiseCollectionChangedForMismatchingItems() { var collection = new RangedObservableCollection <int>(); collection.AddRange(ItemsToAdd); var didTrigger = false; collection.CollectionChanged += (s, e) => { Assert.False(didTrigger); didTrigger = true; }; collection.RemoveRange(AlternateItemsToAdd); Assert.False(didTrigger); }
public void RemoveRangeRaisesCollectionChangedOnce() { var collection = new RangedObservableCollection <int>(); collection.AddRange(ItemsToAdd); var didTrigger = false; collection.CollectionChanged += (s, e) => { Assert.False(didTrigger); didTrigger = true; }; collection.RemoveRange(ItemsToAdd); Assert.True(didTrigger); }