コード例 #1
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();
        }
コード例 #2
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();
        }
コード例 #3
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();
        }