public async Task ShouldRaiseCollectionChangedEventForRemoveRange() { // Arrange List <TestObservableObject> objectsToRemove = TestObservableObjectFaker.Create().Generate(10); var collection = new ObservableItemCollection <TestObservableObject>(); var tcs = new TaskCompletionSource <NotifyCollectionChangedEventArgs>(); collection.CollectionChanged += (sender, args) => { tcs.SetResult(args); }; // Act collection.RemoveRange(objectsToRemove); // Assert NotifyCollectionChangedEventArgs collectionChanged = await tcs.Task; collectionChanged.ShouldNotBeNull(); collectionChanged.OldItems.Count.ShouldBe(objectsToRemove.Count); foreach (object item in collectionChanged.OldItems) { objectsToRemove.ShouldContain(item); } }
public async Task ShouldRaiseCollectionChangedEventForAdd() { // Arrange TestObservableObject objectToAdd = TestObservableObjectFaker.Create().Generate(); var collection = new ObservableItemCollection <TestObservableObject>(); var tcs = new TaskCompletionSource <NotifyCollectionChangedEventArgs>(); collection.CollectionChanged += (sender, args) => { tcs.SetResult(args); }; // Act collection.Add(objectToAdd); // Assert NotifyCollectionChangedEventArgs collectionChanged = await tcs.Task; collectionChanged.ShouldNotBeNull(); collectionChanged.NewItems.Contains(objectToAdd).ShouldBeTrue(); }