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);
        }
        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);
        }
Пример #3
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);
        }
Пример #4
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);
        }
        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);
        }
Пример #6
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);
        }
Пример #7
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();
        }
        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_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 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 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 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 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 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 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 }
            });
        }
        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 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 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();
        }