public void RaisesSingleEventWhileRemovingRange() { var counter = 0; var fastCollection = new FastObservableCollection <int>(new[] { 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5 }); fastCollection.AutomaticallyDispatchChangeNotifications = false; fastCollection.CollectionChanged += (sender, e) => counter++; fastCollection.RemoveItems(new[] { 1, 2, 3, 4, 5 }); Assert.AreEqual(1, counter); fastCollection.RemoveItems(new[] { 1, 2, 3, 4, 5 }, SuspensionMode.Removing); Assert.AreEqual(2, counter); fastCollection.RemoveItems(new ArrayList(new[] { 1, 2, 3, 4, 5 })); Assert.AreEqual(3, counter); fastCollection.RemoveItems(new ArrayList(new[] { 1, 2, 3, 4, 5 }), SuspensionMode.Removing); Assert.AreEqual(4, counter); }
public void RaisesSingleEventWhileAddingRange() { int counter = 0; var fastCollection = new FastObservableCollection<int>(new [] { 1, 2, 3, 4, 5 }); fastCollection.AutomaticallyDispatchChangeNotifications = false; fastCollection.CollectionChanged += (sender, e) => counter++; fastCollection.RemoveItems(new[] { 1, 2, 3, 4, 5 }); Assert.AreEqual(1, counter); }
public void RaisesSingleRemoveEventWhileRemovingRangeWithoutSuspensionMode() { var eventArgs = default(NotifyCollectionChangedEventArgs); var fastCollection = new FastObservableCollection <int>(new[] { 1, 2, 3, 4, 5 }); fastCollection.AutomaticallyDispatchChangeNotifications = false; fastCollection.CollectionChanged += (sender, e) => eventArgs = e; fastCollection.RemoveItems(new[] { 1, 2, 3, 4, 5 }); Assert.AreEqual(NotifyCollectionChangedAction.Reset, eventArgs.Action); }
public void RaisesSingleEventWhileAddingRange() { int counter = 0; var fastCollection = new FastObservableCollection <int>(new [] { 1, 2, 3, 4, 5 }); fastCollection.AutomaticallyDispatchChangeNotifications = false; fastCollection.CollectionChanged += (sender, e) => counter++; fastCollection.RemoveItems(new[] { 1, 2, 3, 4, 5 }); Assert.AreEqual(1, counter); }
public void RaisesTwoEvents() { var eventArgsList = new List <NotifyCollectionChangedEventArgs>(); var fastCollection = new FastObservableCollection <int>(); fastCollection.AddItems(new[] { 1, 2, 3, 4 }); fastCollection.CollectionChanged += (sender, args) => { eventArgsList.Add(args); }; using (fastCollection.SuspendChangeNotifications(SuspensionMode.Mixed)) { fastCollection.RemoveItems(new[] { 4 }); fastCollection.AddItems(new[] { 5 }); } Assert.AreEqual(2, eventArgsList.Count); Assert.Contains(5, eventArgsList.First(args => args.Action == NotifyCollectionChangedAction.Add).NewItems); Assert.Contains(4, eventArgsList.First(args => args.Action == NotifyCollectionChangedAction.Remove).OldItems); }
public void RaisesSingleAddEventIfTheRemovedItemsAreASubSetOfTheAddedItems() { var count = 0; NotifyCollectionChangedEventArgs eventArgs = null; var fastCollection = new FastObservableCollection <int>(); fastCollection.CollectionChanged += (sender, args) => { count++; eventArgs = args; }; using (fastCollection.SuspendChangeNotifications(SuspensionMode.Mixed)) { fastCollection.AddItems(new[] { 1, 2, 3, 4 }); fastCollection.RemoveItems(new[] { 2, 3 }); } Assert.AreEqual(NotifyCollectionChangedAction.Add, eventArgs.Action); Assert.AreEqual(1, count); Assert.AreEqual(new[] { 1, 4 }, eventArgs.NewItems.OfType <int>().ToArray()); }
public void ThrowsArgumentNullExceptionForNullCollection() { var fastCollection = new FastObservableCollection<int>(); ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => fastCollection.RemoveItems(null)); }
public void ThrowsInvalidOperationExceptionForInvalidSuspensionMode() { var fastCollection = new FastObservableCollection <int>(new[] { 1, 2, 3, 4, 5 }); fastCollection.AutomaticallyDispatchChangeNotifications = false; ExceptionTester.CallMethodAndExpectException <InvalidOperationException>(() => fastCollection.RemoveItems(new[] { 1, 2, 3, 4, 5 }, SuspensionMode.Adding)); }
public void ThrowsArgumentNullExceptionForNullCollection() { var fastCollection = new FastObservableCollection <int>(); fastCollection.AutomaticallyDispatchChangeNotifications = false; ExceptionTester.CallMethodAndExpectException <ArgumentNullException>(() => fastCollection.RemoveItems(null)); ExceptionTester.CallMethodAndExpectException <ArgumentNullException>(() => fastCollection.RemoveItems(null, SuspensionMode.Removing)); }
public void ThrowsArgumentNullExceptionForNullCollection() { var fastCollection = new FastObservableCollection <int>(); ExceptionTester.CallMethodAndExpectException <ArgumentNullException>(() => fastCollection.RemoveItems(null)); }