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());
        }
        public void CanFilterCollection()
        {
            var originalCollection = new ObservableCollection<ItemMetadata>();
            IViewsCollection viewsCollection = new ViewsCollection(originalCollection, x => x.Name == "Possible");

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

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

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

            Assert.AreSame(item, viewsCollection.First());
        }
        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.IsTrue(addedToCollection);
            Assert.IsFalse(removedFromCollection);
            addedToCollection = false;

            originalCollection[0].IsActive = false;

            Assert.AreEqual(0, viewsCollection.Count());
            Assert.IsTrue(removedFromCollection);
            Assert.IsFalse(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);
        }
        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));
        }