예제 #1
0
        public void VerifyIndexOfBehavior()
        {
            RunOnUIThread.Execute(() =>
            {
                var collections = new List <IEnumerable>();
                collections.Add(new ObservableVectorWithUniqueIds(Enumerable.Range(0, 10)));
                collections.Add(new ObservableCollection <int>(Enumerable.Range(0, 10)));

                foreach (var collection in collections)
                {
                    var dataSource = new ItemsSourceView(collection);
                    foreach (int i in collection)
                    {
                        Verify.AreEqual(i, dataSource.IndexOf(i));
                    }

                    Verify.AreEqual(-1, dataSource.IndexOf(11));
                }

                // Enumerabl.Range returns IEnumerable which does not provide IndexOf
                var testingItemsSourceView = new ItemsSourceView(Enumerable.Range(0, 10));
                var index = -1;
                try
                {
                    index = testingItemsSourceView.IndexOf(0);
                }catch (Exception) { }
                Verify.AreEqual(-1, index);


                var nullContainingEnumerable = new CustomEnumerable();
                testingItemsSourceView       = new ItemsSourceView(nullContainingEnumerable);

                Verify.AreEqual(1, testingItemsSourceView.IndexOf(null));
            });
        }
예제 #2
0
        public void VerifyReadOnlyListCompatibility()
        {
            RunOnUIThread.Execute(() =>
            {
                var collection = new ReadOnlyNotifyPropertyChangedCollection <object>();
                var firstItem  = "something1";

                collection.Data = new ObservableCollection <object>();

                collection.Data.Add(firstItem);
                collection.Data.Add("something2");
                collection.Data.Add("something3");

                var itemsSourceView = new ItemsSourceView(collection);
                Verify.AreEqual(3, itemsSourceView.Count);

                collection.Data.Add("something4");
                Verify.AreEqual(4, itemsSourceView.Count);

                Verify.AreEqual(firstItem, itemsSourceView.GetAt(0));
                Verify.AreEqual(0, itemsSourceView.IndexOf(firstItem));
            });
        }