コード例 #1
0
        public void RaisesCollectionChangedWithAddAndRemoveWhenFilteredCollectionChanges()
        {
            var originalCollection = new ObservableCollection<ItemMetadata>();
            IViewsCollection viewsCollection = new ViewsCollection(originalCollection, x => x.IsActive);
            bool addedToCollection = false;
            bool removedFromCollection = false;
            viewsCollection.CollectionChanged += (s, e) =>
                                                     {
                                                         if (e.Action == NotifyCollectionChangedAction.Add)
                                                         {
                                                             addedToCollection = true;
                                                         }
                                                         else if (e.Action == NotifyCollectionChangedAction.Remove)
                                                         {
                                                             removedFromCollection = true;
                                                         }
                                                     };
            var filteredInObject = new ItemMetadata(new object()) { IsActive = true };

            originalCollection.Add(filteredInObject);

            Assert.IsTrue(addedToCollection);
            Assert.IsFalse(removedFromCollection);

            originalCollection.Remove(filteredInObject);

            Assert.IsTrue(removedFromCollection);
        }
コード例 #2
0
        public void RaisesCollectionChangedWhenFilteredCollectionChanges()
        {
            var originalCollection = new ObservableCollection<ItemMetadata>();
            IViewsCollection viewsCollection = new ViewsCollection(originalCollection, x => x.IsActive);
            bool collectionChanged = false;
            viewsCollection.CollectionChanged += (s, e) => collectionChanged = true;

            originalCollection.Add(new ItemMetadata(new object()) { IsActive = true });

            Assert.IsTrue(collectionChanged);
        }
コード例 #3
0
        public void CanWrapCollectionCollection()
        {
            var originalCollection = new ObservableCollection<ItemMetadata>();
            IViewsCollection viewsCollection = new ViewsCollection(originalCollection, x => true);

            Assert.AreEqual(0, viewsCollection.Count());

            var item = new object();
            originalCollection.Add(new ItemMetadata(item));
            Assert.AreEqual(1, viewsCollection.Count());
            Assert.AreSame(item, viewsCollection.First());
        }
コード例 #4
0
        public void CanFilterCollection()
        {
            var originalCollection = new ObservableCollection<ItemMetadata>();
            IViewsCollection viewsCollection = new ViewsCollection(originalCollection, x => x.Name == "Posible");

            originalCollection.Add(new ItemMetadata(new object()));

            Assert.AreEqual(0, viewsCollection.Count());

            var item = new object();
            originalCollection.Add(new ItemMetadata(item) { Name = "Posible" });
            Assert.AreEqual(1, viewsCollection.Count());

            Assert.AreSame(item, viewsCollection.First());
        }
コード例 #5
0
        public void ChangingMetadataOnItemAddsOrRemovesItFromTheFilteredCollection()
        {
            var originalCollection = new ObservableCollection<ItemMetadata>();
            IViewsCollection viewsCollection = new ViewsCollection(originalCollection, x => x.IsActive);
            bool addedToCollection = false;
            bool removedFromCollection = false;
            viewsCollection.CollectionChanged += (s, e) =>
                                                     {
                                                         if (e.Action == NotifyCollectionChangedAction.Add)
                                                         {
                                                             addedToCollection = true;
                                                         }
                                                         else if (e.Action == NotifyCollectionChangedAction.Remove)
                                                         {
                                                             removedFromCollection = true;
                                                         }
                                                     };

            originalCollection.Add(new ItemMetadata(new object()) { IsActive = true });
            Assert.IsFalse(removedFromCollection);

            originalCollection[0].IsActive = false;

            Assert.AreEqual(0, viewsCollection.Count());
            Assert.IsTrue(removedFromCollection);
            Assert.IsTrue(addedToCollection);
            Assert.AreEqual(0, viewsCollection.Count());

            addedToCollection = false;
            removedFromCollection = false;

            originalCollection[0].IsActive = true;

            Assert.AreEqual(1, viewsCollection.Count());
            Assert.IsTrue(addedToCollection);
            Assert.IsFalse(removedFromCollection);
        }
コード例 #6
0
        public void EnumeratesWrappedItems()
        {
            var originalCollection = new ObservableCollection<ItemMetadata>()
                                         {
                                             new ItemMetadata(new object()),
                                             new ItemMetadata(new object())
                                         };
            IViewsCollection viewsCollection = new ViewsCollection(originalCollection, x => true);
            Assert.AreEqual(2, viewsCollection.Count());

            Assert.AreSame(originalCollection[0].Item, viewsCollection.ElementAt(0));
            Assert.AreSame(originalCollection[1].Item, viewsCollection.ElementAt(1));
        }
コード例 #7
0
        public void CollectionChangedPassesWrappedItemInArgumentsWhenRemoving()
        {
            var originalCollection = new ObservableCollection<ItemMetadata>();
            IViewsCollection viewsCollection = new ViewsCollection(originalCollection, x => true);
            IList newItemsPassed = null;
            viewsCollection.CollectionChanged += (s, e) =>
            {
                newItemsPassed = e.NewItems;
            };
            var filteredInObject = new ItemMetadata(new object());

            originalCollection.Add(filteredInObject);

            Assert.IsNotNull(newItemsPassed);
            Assert.AreEqual(1, newItemsPassed.Count);
            Assert.AreSame(filteredInObject.Item, newItemsPassed[0]);
        }
コード例 #8
0
        public void DoesNotRaiseCollectionChangedWhenAddingOrRemovingFilteredOutObject()
        {
            var originalCollection = new ObservableCollection<ItemMetadata>();
            IViewsCollection viewsCollection = new ViewsCollection(originalCollection, x => x.IsActive);
            bool collectionChanged = false;
            viewsCollection.CollectionChanged += (s, e) => collectionChanged = true;
            var filteredOutObject = new ItemMetadata(new object()) { IsActive = false };

            originalCollection.Add(filteredOutObject);
            originalCollection.Remove(filteredOutObject);

            Assert.IsFalse(collectionChanged);
        }