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

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

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

            Assert.AreEqual(3, filteredCollection.Count);

            Assert.AreEqual(5, filteredCollection.First());
            Assert.AreEqual(7, filteredCollection.ElementAt(1));
            Assert.AreEqual(17, filteredCollection.ElementAt(2));
        }
Beispiel #2
0
        public void FilteredObservableCollection_FilterChanged_ItemsAreFilteredByNewFilter()
        {
            var filteredCollection = new FilteredObservableCollection <string>();

            filteredCollection.Filter = item => item != "Filter me!";

            filteredCollection.Add("Not me");
            filteredCollection.Add("Nor me");
            filteredCollection.Add("Filter me!");
            filteredCollection.Add("But not me");

            Assert.AreEqual(3, filteredCollection.Count);
            Assert.AreEqual("Not me", filteredCollection.First());
            Assert.AreEqual("Nor me", filteredCollection.ElementAt(1));
            Assert.AreEqual("But not me", filteredCollection.ElementAt(2));

            filteredCollection.Filter = item => !item.StartsWith("No");

            Assert.AreEqual(2, filteredCollection.Count);
            Assert.AreEqual("Filter me!", filteredCollection.First());
            Assert.AreEqual("But not me", filteredCollection.Last());
        }