diff options
author | Eric Maupin <me@ermau.com> | 2018-05-04 21:05:11 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-04 21:05:11 +0300 |
commit | 1986a238c1b7dbb2d63f52b02d57ddde835bc911 (patch) | |
tree | 57396c6042fa2be9d8f1bcb84864e0dbe6d70119 /Xamarin.PropertyEditing.Tests | |
parent | 6ccc70355e4b85205360cbb70362c67527d9040e (diff) | |
parent | a52eb1d5429963424a754280a51355dabf5b09ed (diff) |
Merge pull request #297 from xamarin/ermau-fix-scollectionview
Fix filtering issue with SimpleCollectionView
Diffstat (limited to 'Xamarin.PropertyEditing.Tests')
-rw-r--r-- | Xamarin.PropertyEditing.Tests/SimpleCollectionViewTests.cs | 61 |
1 files changed, 59 insertions, 2 deletions
diff --git a/Xamarin.PropertyEditing.Tests/SimpleCollectionViewTests.cs b/Xamarin.PropertyEditing.Tests/SimpleCollectionViewTests.cs index e77db91..00f65b0 100644 --- a/Xamarin.PropertyEditing.Tests/SimpleCollectionViewTests.cs +++ b/Xamarin.PropertyEditing.Tests/SimpleCollectionViewTests.cs @@ -1,3 +1,4 @@ +using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -555,8 +556,6 @@ namespace Xamarin.PropertyEditing.Tests }); Assume.That (view, Is.Not.Empty); - - var topKvp = view.Cast<KeyValuePair<string, SimpleCollectionView>>().First(); var leafKvp = topKvp.Value.Cast<KeyValuePair<string, SimpleCollectionView>>().First(); var leafItem = leafKvp.Value.Cast<object>().First(); @@ -631,6 +630,64 @@ namespace Xamarin.PropertyEditing.Tests Assert.That (view.Cast<TestNode>().ElementAt (2), Is.EqualTo (nodes[1])); } + [Test] + public void AddBackInUnorderedPartial() + { + var nodes = new ObservableCollection<TestNode> { + new TestNode ("B"), + new TestNode ("Xamarin"), + new TestNode ("A"), + new TestNode ("Xamagon"), + }; + + var view = new SimpleCollectionView (nodes, new SimpleCollectionViewOptions { + DisplaySelector = TestNodeDisplaySelector + }); + + Assume.That (view.Cast<TestNode>().ElementAt (0), Is.EqualTo (nodes[2])); + Assume.That (view.Cast<TestNode>().ElementAt (1), Is.EqualTo (nodes[0])); + Assume.That (view.Cast<TestNode>().ElementAt (2), Is.EqualTo (nodes[3])); + Assume.That (view.Cast<TestNode>().ElementAt (3), Is.EqualTo (nodes[1])); + + view.Options.Filter = o => ((TestNode)o).Key.StartsWith ("Xamarin"); + + Assume.That (view.Cast<TestNode>().Count(), Is.EqualTo (1)); + Assume.That (view.Cast<TestNode>().ElementAt (0), Is.EqualTo (nodes[1])); + + view.Options.Filter = o => ((TestNode)o).Key.StartsWith ("Xama"); + + Assert.That (view.Cast<TestNode>().ElementAt (0), Is.EqualTo (nodes[3])); + Assert.That (view.Cast<TestNode>().ElementAt (1), Is.EqualTo (nodes[1])); + } + + [Test] + public void SettingEvenSameFilterTriggersUpdate () + { + var nodes = new ObservableCollection<TestNode> { + new TestNode ("Baz"), + new TestNode ("Bar"), + new TestNode ("A") + }; + + var view = new SimpleCollectionView (nodes, new SimpleCollectionViewOptions { + DisplaySelector = TestNodeDisplaySelector + }); + + string textFilter = "B"; + Predicate<object> filter = o => ((TestNode) o).Key.StartsWith (textFilter, StringComparison.OrdinalIgnoreCase); + view.Options.Filter = filter; + + Assume.That (view, Contains.Item (nodes[0])); + Assume.That (view, Contains.Item (nodes[1])); + Assume.That (view, Does.Not.Contain (nodes[2])); + + textFilter = "Bar"; + view.Options.Filter = filter; + Assert.That (view, Does.Not.Contain (nodes[0])); + Assert.That (view, Contains.Item (nodes[1])); + Assert.That (view, Does.Not.Contain (nodes[2])); + } + private IEnumerable TestNodeChildrenSelector (object o) { return ((TestNode)o).Children; |