Beispiel #1
0
        public void FilteredObservableCollection_Clear_RaisesCollectionChangedForUnfilteredItems()
        {
            var filteredCollection = new FilteredObservableCollection <int>();

            filteredCollection.Filter = item => item != 13;

            filteredCollection.Add(5);
            filteredCollection.Add(7);
            filteredCollection.Add(13);
            filteredCollection.Add(17);

            var collectionChangedRaisedCounter = 0;

            void collectionChanged(object sender, NotifyCollectionChangedEventArgs e)
            {
                if (e.Action == NotifyCollectionChangedAction.Reset)
                {
                    collectionChangedRaisedCounter++;
                }
            }

            filteredCollection.CollectionChanged += collectionChanged;

            filteredCollection.Clear();
            filteredCollection.Clear();     // CollectionChanged raised allthough collection already empty!

            filteredCollection.CollectionChanged -= collectionChanged;

            Assert.AreEqual(2, collectionChangedRaisedCounter);
        }
Beispiel #2
0
        public void FilteredObservableCollection_Clear_RaisesPropertyChanged()
        {
            var filteredCollection = new FilteredObservableCollection <int>();

            filteredCollection.Filter = item => item != 13;

            filteredCollection.Add(5);
            filteredCollection.Add(7);
            filteredCollection.Add(13);
            filteredCollection.Add(17);

            var propertyChangedRaisedCounter = 0;

            void propertyChanged(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == nameof(filteredCollection.Count))
                {
                    propertyChangedRaisedCounter++;
                }
            }

            filteredCollection.PropertyChanged += propertyChanged;

            filteredCollection.Clear();

            filteredCollection.PropertyChanged -= propertyChanged;

            Assert.AreEqual(1, propertyChangedRaisedCounter);
        }
Beispiel #3
0
        public void FilteredObservableCollection_Clear_RemovesAllItems()
        {
            var filteredCollection = new FilteredObservableCollection <string>();

            filteredCollection.Add("Item 1");
            filteredCollection.Add("Item 2");
            filteredCollection.Add("Item 3");

            filteredCollection.Clear();

            foreach (var item in filteredCollection)
            {
                Assert.Fail("Collection must not contain items after Clear()!");
            }
        }
Beispiel #4
0
        public void FilteredObservableCollection_Count_ShowsItemCount()
        {
            var filteredCollection = new FilteredObservableCollection <string>();

            filteredCollection.Add("Item 1");
            Assert.AreEqual(1, filteredCollection.Count);

            filteredCollection.Add("Item 2");
            filteredCollection.Add("Item 3");
            Assert.AreEqual(3, filteredCollection.Count);

            filteredCollection.Remove("Item 2");
            Assert.AreEqual(2, filteredCollection.Count);

            filteredCollection.Clear();
            Assert.AreEqual(0, filteredCollection.Count);
        }