Пример #1
0
        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);
        }
Пример #2
0
        public void CollectionShouldNotRaiseEventsUsingThreadManagerIfModeNone()
        {
            SynchronizedNotifiableCollection <Item> collection = CreateNotifiableCollection <Item>(ExecutionMode.None,
                                                                                                   ThreadManagerMock);

            collection.Add(new Item());
            var collectionTracker = new NotifiableCollectionTracker <Item>(collection);

            collectionTracker.AssertEquals();
            collection.Count.ShouldEqual(1);
        }
Пример #3
0
        public void CollectionShouldRaiseEventsUsingThreadManager()
        {
            SynchronizedNotifiableCollection <Item> collection = CreateNotifiableCollection <Item>(ExecutionMode.AsynchronousOnUiThread, ThreadManagerMock);

            collection.Add(new Item());

            ThreadManagerMock.InvokeOnUiThreadAsync();
            var collectionTracker = new NotifiableCollectionTracker <Item>(collection);

            collectionTracker.AssertEquals();
        }
Пример #4
0
        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 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);
        }