public void AddingToOriginalCollectionFiresResetNotificationIfSortComparisonSet()
        {
            // Reset is fired to support the need to resort after updating the collection
            var originalCollection = new ObservableCollection<ItemMetadata>();
            var viewsCollection = new ViewsCollection(originalCollection, (i) => true);
            viewsCollection.SortComparison = (a, b) => { return 0; };

            var eventTracker = new CollectionChangedTracker(viewsCollection);

            originalCollection.Add(new ItemMetadata(new object()));

            Assert.IsTrue(eventTracker.ActionsFired.Contains(NotifyCollectionChangedAction.Add));
            Assert.AreEqual(
                1,
                eventTracker.ActionsFired.Count(a => a == NotifyCollectionChangedAction.Reset));
        }
        public void AddingToOriginalCollectionFiresAddCollectionChangeEvent()
        {
            var originalCollection = new ObservableCollection<ItemMetadata>();
            IViewsCollection viewsCollection = new ViewsCollection(originalCollection, (i) => true);

            var eventTracker = new CollectionChangedTracker(viewsCollection);

            originalCollection.Add(new ItemMetadata(new object()));

            Assert.IsTrue(eventTracker.ActionsFired.Contains(NotifyCollectionChangedAction.Add));
        }
        public void OnAddNotifyCollectionChangedThenIndexProvided()
        {
            var originalCollection = new ObservableCollection<ItemMetadata>();
            IViewsCollection viewsCollection = new ViewsCollection(originalCollection, (i) => true);

            var eventTracker = new CollectionChangedTracker(viewsCollection);

            originalCollection.Add(new ItemMetadata("a"));

            var addEvent = eventTracker.NotifyEvents.Single(e => e.Action == NotifyCollectionChangedAction.Add);
            Assert.AreEqual(0, addEvent.NewStartingIndex);
        }
        public void OnRemoveOfFilterMatchingItemThenViewCollectionRelativeIndexProvided()
        {
            var originalCollection = new ObservableCollection<ItemMetadata>();
            originalCollection.Add(new ItemMetadata("a"));
            originalCollection.Add(new ItemMetadata("b"));
            originalCollection.Add(new ItemMetadata("c"));
            IViewsCollection viewsCollection = new ViewsCollection(originalCollection, (i) => !"b".Equals(i.Item));

            var eventTracker = new CollectionChangedTracker(viewsCollection);
            originalCollection.RemoveAt(2);

            var removeEvent = eventTracker.NotifyEvents.Single(e => e.Action == NotifyCollectionChangedAction.Remove);
            Assert.IsNotNull(removeEvent);
            Assert.AreEqual(1, removeEvent.OldStartingIndex);
        }
        public async Task OnRemoveNotifyCollectionChangedThenIndexProvided()
        {
            await ExecuteOnUIThread(() =>
                {
                    var originalCollection = new ObservableCollection<ItemMetadata>();
                    originalCollection.Add(new ItemMetadata("a"));
                    originalCollection.Add(new ItemMetadata("b"));
                    originalCollection.Add(new ItemMetadata("c"));
                    IViewsCollection viewsCollection = new ViewsCollection(originalCollection, (i) => true);

                    var eventTracker = new CollectionChangedTracker(viewsCollection);
                    originalCollection.RemoveAt(1);

                    var removeEvent = eventTracker.NotifyEvents.Single(e => e.Action == NotifyCollectionChangedAction.Remove);
                    Assert.IsNotNull(removeEvent);
                    Assert.AreEqual(1, removeEvent.OldStartingIndex);
                });
        }