public async Task Add_to_projected_list()
        {
            var list = new ListReactiveCollectionSource<int>();

            var projectedList = list.ReactiveCollection
                .Select(x => x.ToString(CultureInfo.InvariantCulture));

            var notificationsTask = projectedList.Changes
                .Take(4)
                .ToArray()
                .ToTask();

            list.Add(1);
            list.Add(2);
            list.Add(3);

            var notifications = await notificationsTask;

            notifications[0].Index.Should().NotHaveValue();
            notifications[1].Index.Should().Be(0);
            notifications[2].Index.Should().Be(1);
            notifications[3].Index.Should().Be(2);
            notifications[0].Action.Should().Be(NotifyCollectionChangedAction.Reset);
            notifications[1].Action.Should().Be(NotifyCollectionChangedAction.Add);
            notifications[2].Action.Should().Be(NotifyCollectionChangedAction.Add);
            notifications[3].Action.Should().Be(NotifyCollectionChangedAction.Add);
            notifications[0].NewItems.Should().BeEmpty();
            notifications[1].NewItems.Should().Equal("1");
            notifications[2].NewItems.Should().Equal("2");
            notifications[3].NewItems.Should().Equal("3");
        }
        public async Task RemoveAt()
        {
            var list = new ListReactiveCollectionSource <int>();

            var notificationTask = list.ReactiveCollection.Changes
                                   .Skip(3)
                                   .FirstAsync()
                                   .ToTask();

            list.Add(1);
            list.Add(2);
            list.RemoveAt(1);

            await Verify(notificationTask);
        }
Ejemplo n.º 3
0
        public async Task RemoveAt()
        {
            var list = new ListReactiveCollectionSource <int>();

            var notificationTask = list.ReactiveCollection.Changes
                                   .Skip(3)
                                   .FirstAsync()
                                   .ToTask();

            list.Add(1);
            list.Add(2);
            list.RemoveAt(1);

            var notification = await notificationTask;

            notification.Index.Should().Be(1);
            notification.Action.Should().Be(NotifyCollectionChangedAction.Remove);
            notification.NewItems.Should().BeEmpty();
            notification.OldItems.Should().Equal(2);
            notification.Current.Should().Equal(1);
        }
        public async Task InsertRange()
        {
            var list = new ListReactiveCollectionSource <int>();

            var notificationTask = list.ReactiveCollection.Changes
                                   .Skip(2)
                                   .FirstAsync()
                                   .ToTask();

            list.Add(1);

            var range = new[] { 1, 2, 3 };

            list.InsertRange(1, range);

            await Verify(notificationTask);
        }
        public async Task Add()
        {
            var list = new ListReactiveCollectionSource<int>();

            var notificationTask = list.ReactiveCollection.Changes
                .Skip(1)
                .FirstAsync()
                .ToTask();

            list.Add(1);

            var notification = await notificationTask;

            notification.Index.Should().Be(0);
            notification.Action.Should().Be(NotifyCollectionChangedAction.Add);
            notification.NewItems.Should().Equal(1);
            notification.OldItems.Should().BeEmpty();
            notification.Current.Should().Equal(1);
        }
Ejemplo n.º 6
0
        public async Task Clear()
        {
            var list = new ListReactiveCollectionSource <int>();

            var notificationTask = list.ReactiveCollection.Changes
                                   .Skip(2)
                                   .FirstAsync()
                                   .ToTask();

            list.Add(1);
            list.Clear();

            var notification = await notificationTask;

            notification.Index.Should().NotHaveValue();
            notification.Action.Should().Be(NotifyCollectionChangedAction.Reset);
            notification.NewItems.Should().BeEmpty();
            notification.OldItems.Should().BeEmpty();
            notification.Current.Should().BeEmpty();
        }
Ejemplo n.º 7
0
        public async Task InsertRange()
        {
            var list = new ListReactiveCollectionSource <int>();

            var notificationTask = list.ReactiveCollection.Changes
                                   .Skip(2)
                                   .FirstAsync()
                                   .ToTask();

            list.Add(1);

            var range = new[] { 1, 2, 3 };

            list.InsertRange(1, range);

            var notification = await notificationTask;

            notification.Index.Should().Be(1);
            notification.Action.Should().Be(NotifyCollectionChangedAction.Add);
            notification.NewItems.Should().Equal(1, 2, 3);
            notification.OldItems.Should().BeEmpty();
            notification.Current.Should().Equal(1, 1, 2, 3);
        }
        public async Task Add_to_sorted_list_with_Changes()
        {
            var list = new ListReactiveCollectionSource<int>();

            var projectedList = list
                .ReactiveCollection
                .Sort();

            var notificationTask = projectedList.Changes
                .Skip(3)
                .FirstAsync()
                .ToTask();

            list.Add(3);
            list.Add(1);
            list.Add(2);

            var notification = await notificationTask;

            notification.Action.Should().Be(NotifyCollectionChangedAction.Add);
            notification.NewItems.Should().Equal(2);
            notification.Current.Should().Equal(1, 2, 3);
        }
        public async Task Add_to_filtered_list()
        {
            var list = new ListReactiveCollectionSource<int>();

            var projectedList = list
                .ReactiveCollection
                .Where(x => x % 2 == 0);

            var notificationTask = projectedList.Changes
                .Skip(1)
                .FirstAsync()
                .ToTask();

            list.Add(1);
            list.Add(3);           
            list.Add(2);

            var notification = await notificationTask;

            notification.Index.Should().Be(0);
            notification.Action.Should().Be(NotifyCollectionChangedAction.Add);
            notification.NewItems.Should().Equal(2);
        }
        public async Task Where_after_Where_behaves_correctly()
        {
            var list = new ListReactiveCollectionSource<int>();

            var changesTask = list.ReactiveCollection
                .Where(x => x % 2 == 0)
                .Where(x => x % 3 == 0)
                .Changes
                .Take(3)
                .ToArray()
                .ToTask();

            list.Add(1);
            list.Add(2);
            list.Add(3);
            list.Add(6);
            list.Remove(1);
            list.Remove(2);
            list.Remove(3);
            list.Remove(6);

            var changes = await changesTask;

            changes[0].Action.Should().Be(NotifyCollectionChangedAction.Reset);
            changes[1].Action.Should().Be(NotifyCollectionChangedAction.Add);
            changes[1].Current.Should().Equal(6);
            changes[2].Action.Should().Be(NotifyCollectionChangedAction.Remove);
            changes[2].Current.Should().BeEmpty();
        }
        public async Task Select_after_Where_behaves_correctly()
        {
            var list = new ListReactiveCollectionSource<int>();

            var changesTask = list.ReactiveCollection
                .Where(x => x % 2 == 0)
                .Select(x => x.ToString(CultureInfo.InvariantCulture))
                .Changes
                .Take(6)
                .ToArray()
                .ToTask();

            list.Add(1);
            list.Add(2);
            list.Remove(2);
            list.Remove(1);
            list.Add(4);
            list.Insert(0, 2);
            list[0] = 3;

            var changes = await changesTask;

            changes[0].Action.Should().Be(NotifyCollectionChangedAction.Reset);
            changes[1].Action.Should().Be(NotifyCollectionChangedAction.Add);
            changes[1].Current.Should().Equal("2");
            changes[2].Action.Should().Be(NotifyCollectionChangedAction.Remove);
            changes[3].Action.Should().Be(NotifyCollectionChangedAction.Add);
            changes[3].Current.Should().Equal("4");
            changes[4].Action.Should().Be(NotifyCollectionChangedAction.Add);
            changes[4].Current.Should().Equal("4", "2");
            changes[4].Index.Should().Be(1);
            changes[5].Action.Should().Be(NotifyCollectionChangedAction.Remove);
            changes[5].Index.Should().Be(1);
            changes[5].Index.Should().Be(1);
            changes[5].Current.Should().Equal("4");
        }
        public async Task Concat_Add_Delayed()
        {
            var source1 = new ListReactiveCollectionSource<int>();
            var source2 = new ListReactiveCollectionSource<int>();

            source1.Add(1);
            source2.Add(2);

            var concat = source1.ReactiveCollection.Concat(source2.ReactiveCollection);

            var notification = await concat.Changes
                .FirstAsync()
                .ToTask();

            notification.Action.Should().Be(NotifyCollectionChangedAction.Reset);
            notification.Current.Should().Equal(1, 2);
        }
        public async Task Concat_Clear()
        {
            var source1 = new ListReactiveCollectionSource<int>();
            var source2 = new ListReactiveCollectionSource<int>();

            var concat = source1.ReactiveCollection.Concat(source2.ReactiveCollection);

            var notificationsTask = concat.Changes
                .Skip(2)
                .Take(3)
                .ToArray()
                .ToTask();

            source1.Add(1);
            source2.Add(2);
            source1.Clear();
            source2.Clear();

            var notifications = await notificationsTask;

            notifications.Should().HaveCount(3);
            notifications[0].Current.Should().Equal(1, 2);
            notifications[1].Action.Should().Be(NotifyCollectionChangedAction.Remove);
            notifications[1].Index.Should().Be(0);
            notifications[1].OldItems.Should().Equal(1);
            notifications[1].Current.Should().Equal(2);
            notifications[2].Action.Should().Be(NotifyCollectionChangedAction.Remove);
            notifications[2].Index.Should().Be(0);
            notifications[2].OldItems.Should().Equal(2);
            notifications[2].Current.Should().BeEmpty();
        }
        public async Task SortedSet_ToObservableCollection_does_not_raise_events_on_event_subscription()
        {
            var list = new ListReactiveCollectionSource<int> { 1, 2, 3 };

            var observableCollection = (INotifyCollectionChanged)list.ReactiveCollection.ToObservableCollection();

            var eventsTask = Observable
                .FromEventPattern<NotifyCollectionChangedEventHandler, NotifyCollectionChangedEventArgs>(eh => observableCollection.CollectionChanged += eh, eh => observableCollection.CollectionChanged -= eh)
                .Select(x => x.EventArgs)
                .FirstAsync()
                .ToTask();

            ((ICollection)observableCollection).Should().Equal(1, 2, 3);
            list.Add(4);

            var ev = await eventsTask;

            ev.Action.Should().Be(NotifyCollectionChangedAction.Add);
            ev.NewItems.Should().Equal(4);
            ((ICollection)observableCollection).Should().Equal(1, 2, 3, 4);
        }
        public async Task List_ToObservableCollection_Replace()
        {
            var list = new ListReactiveCollectionSource<int>();
            var observableCollection = (INotifyCollectionChanged)list.ReactiveCollection.ToObservableCollection();

            var eventsTask = Observable
                .FromEventPattern<NotifyCollectionChangedEventHandler, NotifyCollectionChangedEventArgs>(eh => observableCollection.CollectionChanged += eh, eh => observableCollection.CollectionChanged -= eh)
                .Take(3)
                .Select(x => x.EventArgs)
                .ToArray()
                .ToTask();

            list.Add(1);
            list.Add(2);
            list.Replace(1, 3);

            var events = await eventsTask;

            events[0].Action.Should().Be(NotifyCollectionChangedAction.Add);
            events[1].Action.Should().Be(NotifyCollectionChangedAction.Add);
            events[2].Action.Should().Be(NotifyCollectionChangedAction.Replace);
            events[2].OldItems.Should().Equal(1);
            events[2].NewItems.Should().Equal(3);
            ((ICollection)observableCollection).Should().Equal(3, 2);
        }