public virtual void CollectionShouldTrackChangesCorrectBatchSize() { const int count = 10; SynchronizedNotifiableCollection <Item> collection = CreateNotifiableCollection <Item>(ExecutionMode.None, ThreadManagerMock); collection.BatchSize = 10; var collectionTracker = new NotifiableCollectionTracker <Item>(collection); using (collection.SuspendNotifications()) { var item = new Item(); var items = new[] { new Item(), new Item(), new Item() }; var items2 = new[] { new Item(), new Item(), new Item() }; for (int i = 0; i < count; i++) { collection.AddRange(items); collection.AddRange(items2); collection.RemoveRange(items); } for (int i = 0; i < collection.Count; i++) { collection[i] = item; } } ThreadManagerMock.InvokeOnUiThreadAsync(); collectionTracker.AssertEquals(); collection.Count.ShouldEqual(count * 3); }
public void WhenNotificationSuspendedEventsShouldNotBeRaised() { SynchronizedNotifiableCollection <Item> collection = CreateNotifiableCollection <Item>(ExecutionMode.None, ThreadManagerMock); var collectionTracker = new NotifiableCollectionTracker <Item>(collection); using (collection.SuspendNotifications()) { for (int i = 0; i < 10; i++) { var item = new Item(); collection.Add(item); collection.Remove(item); } using (collection.SuspendNotifications()) { collection.Add(new Item()); } collectionTracker.ChangedItems.ShouldBeEmpty(); } ThreadManagerMock.InvokeOnUiThreadAsync(); collectionTracker.AssertEquals(); }
public void CollectionShouldChangeEventToClearIfUsingBatchSize() { bool isInvoked = false; SynchronizedNotifiableCollection <Item> collection = CreateNotifiableCollection <Item>(ExecutionMode.None, ThreadManagerMock); collection.CollectionChanged += (sender, args) => { args.Action.ShouldEqual(NotifyCollectionChangedAction.Reset); isInvoked = true; }; collection.BatchSize = 1; using (collection.SuspendNotifications()) { collection.Add(new Item()); collection.Add(new Item()); } isInvoked.ShouldBeTrue(); }
public override void CollectionShouldTrackChangesCorrect() { const int count = 10; SynchronizedNotifiableCollection <Item> collection = CreateNotifiableCollection <Item>(ExecutionMode.None, ThreadManagerMock); var collectionTracker = new NotifiableCollectionTracker <Item>(collection); collection.BatchSize = int.MaxValue; var items = new[] { new Item(), new Item(), new Item() }; var items2 = new[] { new Item(), new Item(), new Item() }; using (collection.SuspendNotifications()) { for (int i = 0; i < count; i++) { collection.AddRange(items); collection.AddRange(items2); collection.RemoveRange(items); } } collectionTracker.AssertEquals(); collection.Count.ShouldEqual(count * 3); }