diff options
author | Eric Maupin <me@ermau.com> | 2018-07-16 17:05:55 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-16 17:05:55 +0300 |
commit | 8a2e35636b82e40b19cc3291e422fde2dd7bc894 (patch) | |
tree | c034e7b2c81c46fb08ac025cbd08ca2b795433e8 /Xamarin.PropertyEditing.Tests | |
parent | 24f1ee38e8baa1e084275aedfb27dc3ac541d020 (diff) | |
parent | 1e127fed95aa8a94aa8c0bba8cab8c9321275f60 (diff) |
Merge pull request #339 from xamarin/ermau-list-collection-view
[Core] Add IList to SimpleCollectionView
Diffstat (limited to 'Xamarin.PropertyEditing.Tests')
-rw-r--r-- | Xamarin.PropertyEditing.Tests/SimpleCollectionViewTests.cs | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/Xamarin.PropertyEditing.Tests/SimpleCollectionViewTests.cs b/Xamarin.PropertyEditing.Tests/SimpleCollectionViewTests.cs index 00f65b0..fdb58df 100644 --- a/Xamarin.PropertyEditing.Tests/SimpleCollectionViewTests.cs +++ b/Xamarin.PropertyEditing.Tests/SimpleCollectionViewTests.cs @@ -688,6 +688,72 @@ namespace Xamarin.PropertyEditing.Tests Assert.That (view, Does.Not.Contain (nodes[2])); } + [Test] + public void IndexOf () + { + var nodes = new ObservableCollection<TestNode> { + new TestNode ("A"), + new TestNode ("Baz"), + new TestNode ("Bar"), + }; + + var view = new SimpleCollectionView (nodes, new SimpleCollectionViewOptions { + DisplaySelector = TestNodeDisplaySelector + }); + + Assume.That (view, Contains.Item (nodes[0])); + Assume.That (view, Contains.Item (nodes[1])); + Assume.That (view, Contains.Item (nodes[2])); + + Assert.That (view.IndexOf (nodes[0]), Is.EqualTo (0), "IndexOf didn't return the re-sorted order index"); + Assert.That (view.IndexOf (nodes[1]), Is.EqualTo (2), "IndexOf didn't return the re-sorted order index"); + Assert.That (view.IndexOf (nodes[2]), Is.EqualTo (1), "IndexOf didn't return the re-sorted order index"); + + string textFilter = "B"; + view.Options.Filter = o => ((TestNode)o).Key.StartsWith (textFilter, StringComparison.OrdinalIgnoreCase); + + Assume.That (view, Does.Not.Contain (nodes[0])); + Assume.That (view, Contains.Item (nodes[1])); + Assume.That (view, Contains.Item (nodes[2])); + + Assert.That (view.IndexOf (nodes[0]), Is.EqualTo (-1), "IndexOf didn't return not-found for filtered out item"); + Assert.That (view.IndexOf (nodes[1]), Is.EqualTo (1), "IndexOf didn't return the filtred order index"); + Assert.That (view.IndexOf (nodes[2]), Is.EqualTo (0), "IndexOf didn't return the filtered order index"); + } + + [Test] + public void Indexer () + { + var nodes = new ObservableCollection<TestNode> { + new TestNode ("A"), + new TestNode ("Baz"), + new TestNode ("Bar"), + }; + + var view = new SimpleCollectionView (nodes, new SimpleCollectionViewOptions { + DisplaySelector = TestNodeDisplaySelector + }); + + Assume.That (view, Contains.Item (nodes[0])); + Assume.That (view, Contains.Item (nodes[1])); + Assume.That (view, Contains.Item (nodes[2])); + + Assert.That (view[0], Is.EqualTo (nodes[0]), "this[] didn't return the re-sorted order index"); + Assert.That (view[2], Is.EqualTo (nodes[1]), "this[] didn't return the re-sorted order index"); + Assert.That (view[1], Is.EqualTo (nodes[2]), "this[] didn't return the re-sorted order index"); + + string textFilter = "B"; + view.Options.Filter = o => ((TestNode)o).Key.StartsWith (textFilter, StringComparison.OrdinalIgnoreCase); + + Assume.That (view, Does.Not.Contain (nodes[0])); + Assume.That (view, Contains.Item (nodes[1])); + Assume.That (view, Contains.Item (nodes[2])); + + Assert.That (view[0], Is.EqualTo (nodes[2])); + Assert.That (view[1], Is.EqualTo (nodes[1])); + Assert.Throws<ArgumentOutOfRangeException> (() => view[2].ToString(), "this[] didn't throw out of range on filtered out item"); + } + private IEnumerable TestNodeChildrenSelector (object o) { return ((TestNode)o).Children; |