コード例 #1
0
        public async Task AddRange2()
        {
            var list = new DictionaryReactiveCollectionSource <int, string>();

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

            var range = new[]
            {
                "A",
                "BB",
                "CCC"
            };

            list.AddRange(range, x => x.Length);

            var notification = await notificationTask;

            notification.Action.Should().Be(NotifyCollectionChangedAction.Add);
            notification.NewItems.Should().HaveCount(3);
            notification.OldItems.Should().BeEmpty();
            notification.Current.Should()
            .Contain(1, "A").And
            .Contain(2, "BB").And
            .Contain(3, "CCC");
        }
コード例 #2
0
        public async Task SetItem()
        {
            var list = new DictionaryReactiveCollectionSource <string, int>();

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

            var range = new Dictionary <string, int>
            {
                { "Key1", 1 },
                { "Key2", 2 },
                { "Key3", 3 }
            };

            list.AddRange(range);

            list.SetItem("Key2", 3);

            var notification = await notificationTask;

            notification.Action.Should().Be(NotifyCollectionChangedAction.Replace);
            notification.OldItems.Should().HaveCount(1);
            notification.OldItems.Should().Contain(new KeyValuePair <string, int>("Key2", 2));
            notification.NewItems.Should().Contain(new KeyValuePair <string, int>("Key2", 3));
            notification.Current.Should().Equal(new Dictionary <string, int>
            {
                { "Key1", 1 },
                { "Key2", 3 },
                { "Key3", 3 }
            });
        }
コード例 #3
0
        public async Task AddRange1()
        {
            var list = new DictionaryReactiveCollectionSource <string, int>();

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

            var range = new Dictionary <string, int>
            {
                { "Key1", 1 },
                { "Key2", 2 },
                { "Key3", 3 }
            };

            list.AddRange(range);

            var notification = await notificationTask;

            notification.Action.Should().Be(NotifyCollectionChangedAction.Add);
            notification.NewItems.Should().BeEquivalentTo(range);
            notification.OldItems.Should().BeEmpty();
            notification.Current.Should().Equal(range);
        }
コード例 #4
0
        public async Task SetItems()
        {
            var list = new DictionaryReactiveCollectionSource <string, int>(DeterministicStringKeyComparer.Instance);

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

            list.AddRange(new[]
            {
                new KeyValuePair <string, int>("Key1", 1),
                new KeyValuePair <string, int>("Key2", 2),
                new KeyValuePair <string, int>("Key3", 3)
            });

            list.SetItems(new[]
            {
                new KeyValuePair <string, int>("Key1", 4),
                new KeyValuePair <string, int>("Key2", 5),
                new KeyValuePair <string, int>("Key3", 6)
            });

            await Verify(notificationTask);
        }
コード例 #5
0
        public async Task SetItems()
        {
            var list = new DictionaryReactiveCollectionSource <string, int>();

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

            list.AddRange(new[]
            {
                new KeyValuePair <string, int>("Key1", 1),
                new KeyValuePair <string, int>("Key2", 2),
                new KeyValuePair <string, int>("Key3", 3)
            });

            list.SetItems(new[]
            {
                new KeyValuePair <string, int>("Key1", 4),
                new KeyValuePair <string, int>("Key2", 5),
                new KeyValuePair <string, int>("Key3", 6)
            });

            var notification = await notificationTask;

            notification.Action.Should().Be(NotifyCollectionChangedAction.Reset);
            notification.Current.Should().Equal(new Dictionary <string, int>
            {
                { "Key1", 4 },
                { "Key2", 5 },
                { "Key3", 6 }
            });
        }
コード例 #6
0
        public async Task RemoveRange()
        {
            var list = new DictionaryReactiveCollectionSource <string, int>();

            var notificationsTask = list.ReactiveCollection.Changes
                                    .Skip(2)
                                    .Take(2)
                                    .ToArray()
                                    .ToTask();

            list.AddRange(new[]
            {
                new KeyValuePair <string, int>("Key1", 1),
                new KeyValuePair <string, int>("Key2", 2),
                new KeyValuePair <string, int>("Key3", 3)
            });

            list.RemoveRange(new[]
            {
                "Key1",
                "Key2"
            });

            var notifications = await notificationsTask;

            notifications[0].Action.Should().Be(NotifyCollectionChangedAction.Remove);
            notifications[0].OldItems.Should().Equal(new KeyValuePair <string, int>("Key1", 1));
            notifications[1].Action.Should().Be(NotifyCollectionChangedAction.Remove);
            notifications[1].OldItems.Should().Equal(new KeyValuePair <string, int>("Key2", 2));
            notifications[1].Current.Should().Equal(new Dictionary <string, int>
            {
                { "Key3", 3 }
            });
        }
        public async Task AddRange1()
        {
            var list = new DictionaryReactiveCollectionSource<string, int>();

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

            var range = new Dictionary<string, int>
            {
                { "Key1", 1 },
                { "Key2", 2 },
                { "Key3", 3 }
            };

            list.AddRange(range);

            var notification = await notificationTask;

            notification.Action.Should().Be(NotifyCollectionChangedAction.Add);
            notification.NewItems.Should().BeEquivalentTo(range);
            notification.OldItems.Should().BeEmpty();
            notification.Current.Should().Equal(range);
        }
コード例 #8
0
        public async Task DictionaryPerformanceTest()
        {
            const int count = 10000;
            var       dict  = new DictionaryReactiveCollectionSource <string, int>();

            var stopWatch = new Stopwatch();
            var lastTask  = dict.ReactiveCollection.Changes
                            .Skip(count)
                            .FirstAsync()
                            .ToTask();

            stopWatch.Start();

            for (var i = 0; i < count; i++)
            {
                dict.Add(i.ToString(CultureInfo.InvariantCulture), i);
            }

            for (var i = count - 1; i >= 0; i--)
            {
                dict.Remove(i.ToString(CultureInfo.InvariantCulture));
            }

            await lastTask;

            stopWatch.Stop();
            Console.WriteLine(stopWatch.Elapsed);
        }
コード例 #9
0
        public async Task DictionaryPerformanceTest()
        {
            const int count = 10000;
            var dict = new DictionaryReactiveCollectionSource<string, int>();

            var stopWatch = new Stopwatch();
            var lastTask = dict.ReactiveCollection.Changes
                .Skip(count)
                .FirstAsync()
                .ToTask();

            stopWatch.Start();

            for (var i = 0; i < count; i++)
            {
                dict.Add(i.ToString(CultureInfo.InvariantCulture), i);
            }

            for (var i = count - 1; i >= 0; i--)
            {
                dict.Remove(i.ToString(CultureInfo.InvariantCulture));
            }

            await lastTask;

            stopWatch.Stop();
            Console.WriteLine(stopWatch.Elapsed);
        }
コード例 #10
0
        public async Task First_notification_is_reset()
        {
            var list = new DictionaryReactiveCollectionSource <string, int>();

            await Verify(await list.ReactiveCollection.Changes
                         .FirstAsync()
                         .ToTask());
        }
コード例 #11
0
        public void Contains()
        {
            var dict = new DictionaryReactiveCollectionSource <string, int>
            {
                { "Key", 1 }
            };

            dict.Contains(new KeyValuePair <string, int>("Key", 1)).Should().BeTrue();
            dict.Contains(new KeyValuePair <string, int>("Key1", 2)).Should().BeFalse();
        }
コード例 #12
0
        public void Item()
        {
            var list = new DictionaryReactiveCollectionSource <string, int>
            {
                { "Key1", 1 }
            };

            list["Key1"].Should().Be(1);
            list["Key1"] = 2;
            list["Key1"].Should().Be(2);
        }
コード例 #13
0
        public async Task Count_reflects_actual_count()
        {
            var list = new DictionaryReactiveCollectionSource <string, int>(DeterministicStringKeyComparer.Instance)
            {
                { "Key1", 1 },
                { "Key2", 2 },
                { "Key3", 3 }
            };

            await Verify(list);
        }
コード例 #14
0
        public async Task Contains()
        {
            var dict = new DictionaryReactiveCollectionSource <string, int>
            {
                { "Key", 1 }
            };

            await Verify((
                             dict.Contains(new KeyValuePair <string, int>("Key", 1)),
                             dict.Contains(new KeyValuePair <string, int>("Key1", 2))));
        }
コード例 #15
0
        public void Count_reflects_actual_count()
        {
            var list = new DictionaryReactiveCollectionSource <string, int>
            {
                { "Key1", 1 },
                { "Key2", 2 },
                { "Key3", 3 }
            };

            list.Should().HaveCount(3);
        }
コード例 #16
0
        public async Task TryGetValue()
        {
            var list = new DictionaryReactiveCollectionSource <string, int>
            {
                { "Key1", 1 }
            };

            await Verify((
                             list.TryGetValue("Key1", out var value),
                             value,
                             list.TryGetValue("Key2", out _)));
        }
コード例 #17
0
        public void Item2()
        {
            var list = new DictionaryReactiveCollectionSource <string, int>
            {
                { "Key1", 1 }
            };

            Assert.Throws <KeyNotFoundException>(() =>
            {
                var v = list["Key"];
            });
        }
コード例 #18
0
        public void TryGetValue()
        {
            var list = new DictionaryReactiveCollectionSource <string, int>
            {
                { "Key1", 1 }
            };

            int value;

            list.TryGetValue("Key1", out value).Should().BeTrue();
            value.Should().Be(1);
            list.TryGetValue("Key2", out value).Should().BeFalse();
        }
コード例 #19
0
        public async Task Add_null()
        {
            var list = new DictionaryReactiveCollectionSource <string, string?>();

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

            list.Add("Key", null);

            await Verify(notificationTask);
        }
        public async Task First_notification_is_reset()
        {
            var list = new DictionaryReactiveCollectionSource<string, int>();

            var notification = await list.ReactiveCollection.Changes
                .FirstAsync()
                .ToTask();

            notification.Action.Should().Be(NotifyCollectionChangedAction.Reset);
            notification.OldItems.Should().BeEmpty();
            notification.NewItems.Should().BeEmpty();
            notification.Current.Should().BeEmpty();
        }
コード例 #21
0
        public async Task First_notification_is_reset()
        {
            var list = new DictionaryReactiveCollectionSource <string, int>();

            var notification = await list.ReactiveCollection.Changes
                               .FirstAsync()
                               .ToTask();

            notification.Action.Should().Be(NotifyCollectionChangedAction.Reset);
            notification.OldItems.Should().BeEmpty();
            notification.NewItems.Should().BeEmpty();
            notification.Current.Should().BeEmpty();
        }
コード例 #22
0
        public async Task Item()
        {
            var list = new DictionaryReactiveCollectionSource <string, int>
            {
                { "Key1", 1 }
            };

            var before = list["Key1"].Should().Be(1);

            list["Key1"] = 2;
            var after = list["Key1"].Should().Be(2);

            await Verify((before, after));
        }
コード例 #23
0
        public async Task Remove()
        {
            var list = new DictionaryReactiveCollectionSource <string, int>();

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

            list.Add("Key1", 1);
            list.Remove("Key1");

            await Verify(notificationTask);
        }
コード例 #24
0
        public void GetEnumerator()
        {
            var list = new DictionaryReactiveCollectionSource <string, int>
            {
                { "Key1", 1 }
            };

            using (var enumerator = list.GetEnumerator())
            {
                enumerator.MoveNext().Should().BeTrue();
                enumerator.Current.Should().Be(new KeyValuePair <string, int>("Key1", 1));
                enumerator.MoveNext().Should().BeFalse();
            }
        }
コード例 #25
0
        public async Task Add()
        {
            var list = new DictionaryReactiveCollectionSource <string, int>();

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

            list.Add("Key", 1);

            var notification = await notificationTask;

            notification.Action.Should().Be(NotifyCollectionChangedAction.Add);
            notification.OldItems.Should().BeEmpty();
            notification.NewItems.Should().Equal(new KeyValuePair <string, int>("Key", 1));
            notification.Current.Should().Contain("Key", 1);
        }
        public async Task Add()
        {
            var list = new DictionaryReactiveCollectionSource<string, int>();

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

            list.Add("Key", 1);

            var notification = await notificationTask;

            notification.Action.Should().Be(NotifyCollectionChangedAction.Add);
            notification.OldItems.Should().BeEmpty();
            notification.NewItems.Should().Equal(new KeyValuePair<string, int>("Key", 1));
            notification.Current.Should().Contain("Key", 1);
        }
コード例 #27
0
        public async Task Clear()
        {
            var list = new DictionaryReactiveCollectionSource <string, int>();

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

            list.Add("Key", 1);
            list.Clear();

            var notification = await notificationTask;

            notification.Action.Should().Be(NotifyCollectionChangedAction.Reset);
            notification.NewItems.Should().BeEmpty();
            notification.OldItems.Should().BeEmpty();
            notification.Current.Should().BeEmpty();
        }
コード例 #28
0
        public async Task SetItem()
        {
            var list = new DictionaryReactiveCollectionSource <string, int>(DeterministicStringKeyComparer.Instance);

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

            list.AddRange(new Dictionary <string, int>
            {
                { "Key1", 1 },
                { "Key2", 2 },
                { "Key3", 3 }
            });
            list.SetItem("Key2", 3);

            await Verify(notificationTask);
        }
コード例 #29
0
        public async Task AddRange2()
        {
            var list = new DictionaryReactiveCollectionSource <int, string>();

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

            var range = new[]
            {
                "A",
                "BB",
                "CCC"
            };

            list.AddRange(range, x => x.Length);

            await Verify(notificationTask);
        }
コード例 #30
0
        public async Task RemoveRange()
        {
            var list = new DictionaryReactiveCollectionSource <string, int>(DeterministicStringKeyComparer.Instance);

            var notificationsTask = list.ReactiveCollection.Changes
                                    .Take(3)
                                    .ToArray()
                                    .ToTask();

            list.AddRange(new[]
            {
                new KeyValuePair <string, int>("Key1", 1),
                new KeyValuePair <string, int>("Key2", 2),
                new KeyValuePair <string, int>("Key3", 3)
            });

            list.RemoveRange(new[]
            {
                "Key1",
                "Key2"
            });

            await Verify(notificationsTask);
        }
        public void Where_after_Where_on_dictionaries_squashes_both_operators()
        {
            var list = new DictionaryReactiveCollectionSource<int, int>();

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

            var transformed = projectedList as DictionaryTransformationReactiveCollection<int, int, int>;

            transformed.Should().NotBeNull();
            transformed.Source.Should().BeSameAs(list.ReactiveCollection);
            transformed.Selector.Should().BeNull();
            transformed.Filter.Should().NotBeNull();
        }
        public async Task Clear()
        {
            var list = new DictionaryReactiveCollectionSource<string, int>();

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

            list.Add("Key", 1);
            list.Clear();

            var notification = await notificationTask;

            notification.Action.Should().Be(NotifyCollectionChangedAction.Reset);
            notification.NewItems.Should().BeEmpty();
            notification.OldItems.Should().BeEmpty();
            notification.Current.Should().BeEmpty();
        }
        public void Count_reflects_actual_count()
        {
            var list = new DictionaryReactiveCollectionSource<string, int>
            {
                { "Key1", 1 },
                { "Key2", 2 },
                { "Key3", 3 }
            };

            list.Should().HaveCount(3);
        }
        public void Item()
        {
            var list = new DictionaryReactiveCollectionSource<string, int>
            {
                { "Key1", 1 }
            };

            list["Key1"].Should().Be(1);
            list["Key1"] = 2;
            list["Key1"].Should().Be(2);
        }
        public async Task SetItem()
        {
            var list = new DictionaryReactiveCollectionSource<string, int>();

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

            var range = new Dictionary<string, int>
            {
                { "Key1", 1 },
                { "Key2", 2 },
                { "Key3", 3 }
            };

            list.AddRange(range);

            list.SetItem("Key2", 3);

            var notification = await notificationTask;

            notification.Action.Should().Be(NotifyCollectionChangedAction.Replace);
            notification.OldItems.Should().HaveCount(1);
            notification.OldItems.Should().Contain(new KeyValuePair<string, int>("Key2", 2));
            notification.NewItems.Should().Contain(new KeyValuePair<string, int>("Key2", 3));
            notification.Current.Should().Equal(new Dictionary<string, int>
            {
                { "Key1", 1 },
                { "Key2", 3 },
                { "Key3", 3 }
            });
        }
        public async Task GetValueObservable_Test1()
        {
            var dict = new DictionaryReactiveCollectionSource<int, int>();

            var arrayTask = dict.ReactiveCollection.GetValueObservable(1)
                .Take(4)
                .ToArray()
                .ToTask();

            dict.Add(2, 2);
            dict.Add(1, 1);
            dict[2] = 1;
            dict.Remove(1);
            dict[2] = 1;
            dict.Add(1, 2);
            dict[1] = 3;

            (await arrayTask).Should().Equal(1, 1, 2, 3);
        }
        public async Task Where_after_Where_on_dictionaries_behaves_correctly()
        {
            var list = new DictionaryReactiveCollectionSource<int, int>();

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

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

            var changes = await changesTask;

            changes[0].Action.Should().Be(NotifyCollectionChangedAction.Reset);
            changes[1].Action.Should().Be(NotifyCollectionChangedAction.Add);
            changes[1].Current.Should()
                .HaveCount(1).And
                .Contain(4, 6);
            changes[2].Action.Should().Be(NotifyCollectionChangedAction.Remove);
            changes[2].Current.Should().BeEmpty();
        }
        public async Task Select_after_SortSet_preserves_order()
        {
            var list = new DictionaryReactiveCollectionSource<int, int>();

            var lastTask = list.ReactiveCollection
                .SortSet(new Comparison<KeyValuePair<int, int>>((x, y) => x.Value.CompareTo(y.Value)).ToComparer())
                .Select(x => x.Value.ToString())
                .Changes
                .Skip(4)
                .FirstAsync()
                .ToTask();

            list.Add(1, 36);
            list.Add(2, 35);
            list.Add(4, 34);
            list.Add(0, 37);

            (await lastTask).Current.Should().Equal("34", "35", "36", "37");
        }
        public async Task Remove_in_setSorted_dictionary()
        {
            var list = new DictionaryReactiveCollectionSource<string, int>();

            var projectedList = list.ReactiveCollection
                .SortSet(Comparer<KeyValuePair<string, int>>.Create((x, y) => x.Value.CompareTo(y.Value)));

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

            list.Add("Key1", 1);
            list.Add("Key2", 2);
            list.Remove("Key1");

            var notification = await notificationTask;

            notification.Action.Should().Be(NotifyCollectionChangedAction.Remove);
            notification.OldItems.Should().Equal(new KeyValuePair<string, int>("Key1", 1));
            notification.Current.Should().Equal(new KeyValuePair<string, int>("Key2", 2));
        }
        public async Task Replace_in_filtered_dictionary_removal()
        {
            var list = new DictionaryReactiveCollectionSource<string, int>();

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

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

            list.Add("Key1", 1);
            list.Add("Key2", 2);
            list.Add("Key3", 3);

            list["Key2"] = 3;

            var notification = await notificationTask;

            notification.Action.Should().Be(NotifyCollectionChangedAction.Remove);
            notification.OldItems.Should().Equal(new KeyValuePair<string, int>("Key2", 2));
            notification.NewItems.Should().BeEmpty();
        }
        public void Contains()
        {
            var dict = new DictionaryReactiveCollectionSource<string, int>
            {
                { "Key", 1 }
            };

            dict.Contains(new KeyValuePair<string, int>("Key", 1)).Should().BeTrue();
            dict.Contains(new KeyValuePair<string, int>("Key1", 2)).Should().BeFalse();
        }
        public async Task RemoveRange()
        {
            var list = new DictionaryReactiveCollectionSource<string, int>();

            var notificationsTask = list.ReactiveCollection.Changes
                .Skip(2)
                .Take(2)
                .ToArray()
                .ToTask();

            list.AddRange(new[]
            {
                new KeyValuePair<string, int>("Key1", 1),
                new KeyValuePair<string, int>("Key2", 2),
                new KeyValuePair<string, int>("Key3", 3)
            });

            list.RemoveRange(new[]
            {
                "Key1",
                "Key2"
            });

            var notifications = await notificationsTask;

            notifications[0].Action.Should().Be(NotifyCollectionChangedAction.Remove);
            notifications[0].OldItems.Should().Equal(new KeyValuePair<string, int>("Key1", 1));
            notifications[1].Action.Should().Be(NotifyCollectionChangedAction.Remove);
            notifications[1].OldItems.Should().Equal(new KeyValuePair<string, int>("Key2", 2));
            notifications[1].Current.Should().Equal(new Dictionary<string, int>
            {
                { "Key3", 3 }
            });
        }
        public async Task Select_after_Select_on_dictionaries_behaves_correctly()
        {
            var list = new DictionaryReactiveCollectionSource<int, int>();

            var changesTask = list.ReactiveCollection
                .Select(x => x.ToString(CultureInfo.InvariantCulture))
                .Select(x => x + "!")
                .Changes
                .Take(6)
                .ToArray()
                .ToTask();

            list.Add(1, 36);
            list.Add(2, 37);
            list.Remove(2);
            list.Remove(1);
            list.Add(4, 38);

            var changes = await changesTask;

            changes[0].Action.Should().Be(NotifyCollectionChangedAction.Reset);
            changes[1].Action.Should().Be(NotifyCollectionChangedAction.Add);
            changes[1].Current.Should().HaveCount(1);
            changes[1].Current.Should().Contain(1, "36!");
            changes[2].Action.Should().Be(NotifyCollectionChangedAction.Add);
            changes[2].Current.Should().HaveCount(2);
            changes[2].Current.Should().Contain(1, "36!");
            changes[2].Current.Should().Contain(2, "37!");
            changes[3].Action.Should().Be(NotifyCollectionChangedAction.Remove);
            changes[3].Current.Should().HaveCount(1);
            changes[3].Current.Should().Contain(1, "36!");
            changes[4].Action.Should().Be(NotifyCollectionChangedAction.Remove);
            changes[4].Current.Should().BeEmpty();
            changes[5].Action.Should().Be(NotifyCollectionChangedAction.Add);
            changes[5].Current.Should().HaveCount(1);
            changes[5].Current.Should().Contain(4, "38!");
        }
        public async Task SetItems()
        {
            var list = new DictionaryReactiveCollectionSource<string, int>();

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

            list.AddRange(new[]
            {
                new KeyValuePair<string, int>("Key1", 1),
                new KeyValuePair<string, int>("Key2", 2),
                new KeyValuePair<string, int>("Key3", 3)
            });

            list.SetItems(new[]
            {
                new KeyValuePair<string, int>("Key1", 4),
                new KeyValuePair<string, int>("Key2", 5),
                new KeyValuePair<string, int>("Key3", 6)
            });

            var notification = await notificationTask;

            notification.Action.Should().Be(NotifyCollectionChangedAction.Reset);
            notification.Current.Should().Equal(new Dictionary<string, int>
            {
                { "Key1", 4 },
                { "Key2", 5 },
                { "Key3", 6 }
            });
        }
        public void GetEnumerator()
        {
            var list = new DictionaryReactiveCollectionSource<string, int>
            {
                { "Key1", 1 }
            };

            using (var enumerator = list.GetEnumerator())
            {
                enumerator.MoveNext().Should().BeTrue();
                enumerator.Current.Should().Be(new KeyValuePair<string, int>("Key1", 1));
                enumerator.MoveNext().Should().BeFalse();
            }
        }
        public void TryGetValue()
        {
            var list = new DictionaryReactiveCollectionSource<string, int>
            {
                { "Key1", 1 }
            };

            int value;

            list.TryGetValue("Key1", out value).Should().BeTrue();
            value.Should().Be(1);
            list.TryGetValue("Key2", out value).Should().BeFalse();
        }
        public async Task AddRange2()
        {
            var list = new DictionaryReactiveCollectionSource<int, string>();

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

            var range = new[]
            {
                "A",
                "BB",
                "CCC"
            };

            list.AddRange(range, x => x.Length);

            var notification = await notificationTask;

            notification.Action.Should().Be(NotifyCollectionChangedAction.Add);
            notification.NewItems.Should().HaveCount(3);
            notification.OldItems.Should().BeEmpty();
            notification.Current.Should()
                .Contain(1, "A").And
                .Contain(2, "BB").And
                .Contain(3, "CCC");
        }
        public void Item2()
        {
            var list = new DictionaryReactiveCollectionSource<string, int>
            {
                { "Key1", 1 }
            };

            Assert.Throws<KeyNotFoundException>(() =>
            {
                var v = list["Key"];
            });
        }
        public async Task Add_to_projected_dictionary()
        {
            var list = new DictionaryReactiveCollectionSource<string, int>();

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

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

            list.Add("Key1", 1);
            list.Add("Key2", 2);
            list.Add("Key3", 3);

            var notifications = await notificationsTask;

            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(new KeyValuePair<string, string>("Key1", "1"));
            notifications[2].NewItems.Should().Equal(new KeyValuePair<string, string>("Key2", "2"));
            notifications[3].NewItems.Should().Equal(new KeyValuePair<string, string>("Key3", "3"));
            notifications[3].Current.Should().Equal(new Dictionary<string, string>
            {
                { "Key1", "1" },
                { "Key2", "2" },
                { "Key3", "3" }
            });
        }
        public async Task Remove_from_projected_dictionary()
        {
            var list = new DictionaryReactiveCollectionSource<string, int>();

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

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

            list.Add("Key1", 1);
            list.Add("Key2", 2);
            list.Add("Key3", 3);
            list.Remove("Key2");

            var notification = await notificationTask;

            notification.Action.Should().Be(NotifyCollectionChangedAction.Remove);
            notification.OldItems.Should().Equal(new Dictionary<string, string> { { "Key2", "2" } });
            notification.NewItems.Should().BeEmpty();
            notification.Current.Should().Equal(new Dictionary<string, string> { { "Key1", "1" }, { "Key3", "3" }});
        }
        public void Select_after_Select_on_dictionaries_squashes_both_operators()
        {
            var list = new DictionaryReactiveCollectionSource<int, int>();

            var projectedList = list.ReactiveCollection
                .Select(x => x.ToString())
                .Select(int.Parse);

            var transformed = projectedList as DictionaryTransformationReactiveCollection<int, int, int>;

            transformed.Should().NotBeNull();
            transformed.Source.Should().BeSameAs(list.ReactiveCollection);
            transformed.Selector.Should().NotBeNull();
            transformed.Filter.Should().BeNull();
        }
        public async Task Replace_in_setSorted_dictionary()
        {
            var list = new DictionaryReactiveCollectionSource<string, int>();

            var projectedList = list.ReactiveCollection
                .SortSet(Comparer<KeyValuePair<string, int>>.Create((x, y) => x.Value.CompareTo(y.Value)));

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

            list.Add("Key1", 1);
            list.Add("Key2", 2);
            list.Add("Key3", 3);

            list["Key2"] = 4;

            var notifications = await notificationsTask;

            notifications[0].Action.Should().Be(NotifyCollectionChangedAction.Remove);
            notifications[0].OldItems.Should().Equal(new KeyValuePair<string, int>("Key2", 2));
            notifications[1].Action.Should().Be(NotifyCollectionChangedAction.Add);
            notifications[1].NewItems.Should().Equal(new KeyValuePair<string, int>("Key2", 4));
            notifications[1].Current.Should().Equal(new KeyValuePair<string, int>("Key1", 1), new KeyValuePair<string, int>("Key3", 3), new KeyValuePair<string, int>("Key2", 4));
        }
        public async Task Replace_in_filtered_dictionary_replacement()
        {
            var list = new DictionaryReactiveCollectionSource<string, int>();

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

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

            list.Add("Key1", 1);
            list.Add("Key2", 2);
            list.Add("Key3", 3);

            list["Key2"] = 4;

            var notifications = await notificationsTask;

            notifications[0].Action.Should().Be(NotifyCollectionChangedAction.Remove);
            notifications[1].Action.Should().Be(NotifyCollectionChangedAction.Add);
            notifications[0].OldItems.Should().Equal(new KeyValuePair<string, int>("Key2", 2));
            notifications[1].NewItems.Should().Equal(new KeyValuePair<string, int>("Key2", 4));
            notifications[1].Current.Should().Equal(new Dictionary<string, int>
            {
                { "Key2", 4 }
            });
        }