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

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

            Assert.IsTrue(filteredCollection.Remove("Item 2"));
            Assert.AreEqual("Item 1", filteredCollection.First());
            Assert.AreEqual("Item 3", filteredCollection.Last());
        }
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());
        }