예제 #1
0
        public void WhenOperationWasCanceledCollectionShouldNotBeChanged()
        {
            SynchronizedNotifiableCollection <Item> collection = CreateNotifiableCollection <Item>(ExecutionMode.None,
                                                                                                   ThreadManagerMock);

            collection.Add(new Item {
                Id = new Guid("0C32E17E-020C-4E05-9B90-AE247B8BE703")
            });

            collection.CollectionChanging += (sender, args) => args.Cancel = true;
            var collectionTracker = new NotifiableCollectionTracker <Item>(collection);

            var item = new Item {
                Id = new Guid("3C39C0C0-DFBA-4683-8473-0950085478E9")
            };

            collection.Add(item);
            collection.Remove(item);
            collection[0] = item;
            collection.Clear();

            collection.Count.ShouldEqual(1);
            collection[0].ShouldNotEqual(item);

            collectionTracker.ChangedItems.SequenceEqual(collection).ShouldBeTrue();
            collectionTracker.ChangingItems.SequenceEqual(collection).ShouldBeTrue();
        }
예제 #2
0
        public void WhenOperationWasCanceledCollectionShouldNotBeChanged()
        {
            SynchronizedNotifiableCollection <Item> collection = CreateNotifiableCollection <Item>(ExecutionMode.None, ThreadManagerMock);

            collection.Add(new Item {
                Id = -1
            });
            collection.CollectionChanging += (sender, args) => args.Cancel = true;
            var collectionTracker = new NotifiableCollectionTracker <Item>(collection, false);

            var item = new Item {
                Id = -2
            };

            collection.Add(item);
            collection.Remove(item);
            collection[0] = item;
            collection.Clear();

            collection.Count.ShouldEqual(1);
            collection[0].ShouldNotEqual(item);

            collectionTracker.ChangedItems.SequenceEqual(collection).ShouldBeTrue();
            collectionTracker.ChangingItems.SequenceEqual(collection).ShouldBeTrue();
        }
예제 #3
0
        public void CollectionShouldReturnCountUsingMode()
        {
            SynchronizedNotifiableCollection <Item> collection =
                CreateNotifiableCollection <Item>(ExecutionMode.AsynchronousOnUiThread, ThreadManagerMock);
            IList        list        = collection;
            IList <Item> genericList = collection;

            collection.Add(new Item());

            collection.NotificationMode = NotificationCollectionMode.None;
            list.Count.ShouldEqual(1);
            genericList.Count.ShouldEqual(1);
            collection.Count.ShouldEqual(1);
            collection.NotificationCount.ShouldEqual(0);

            collection.NotificationMode = NotificationCollectionMode.CollectionIntefaceUseNotificationValue;
            list.Count.ShouldEqual(0);
            genericList.Count.ShouldEqual(1);
            collection.Count.ShouldEqual(1);
            collection.NotificationCount.ShouldEqual(0);

            collection.NotificationMode = NotificationCollectionMode.GenericCollectionInterfaceUseNotificationValue;
            list.Count.ShouldEqual(1);
            genericList.Count.ShouldEqual(0);
            collection.Count.ShouldEqual(1);
            collection.NotificationCount.ShouldEqual(0);

            collection.NotificationMode = NotificationCollectionMode.GenericCollectionInterfaceUseNotificationValue
                                          | NotificationCollectionMode.CollectionIntefaceUseNotificationValue;
            list.Count.ShouldEqual(0);
            genericList.Count.ShouldEqual(0);
            collection.Count.ShouldEqual(1);
            collection.NotificationCount.ShouldEqual(0);
        }
예제 #4
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();
        }
예제 #5
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);
        }
예제 #6
0
        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();
        }
예제 #7
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();
        }