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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 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");

            var notification = await notificationTask;

            notification.Action.Should().Be(NotifyCollectionChangedAction.Remove);
            notification.NewItems.Should().BeEmpty();
            notification.OldItems.Should().Equal(new KeyValuePair <string, int>("Key1", 1));
            notification.Current.Should().BeEmpty();
        }
        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");

            var notification = await notificationTask;

            notification.Action.Should().Be(NotifyCollectionChangedAction.Remove);
            notification.NewItems.Should().BeEmpty();
            notification.OldItems.Should().Equal(new KeyValuePair<string, int>("Key1", 1));
            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_filtered_dictionary()
        {
            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.Remove("Key2");

            var notification = await notificationTask;

            notification.Action.Should().Be(NotifyCollectionChangedAction.Remove);
            notification.NewItems.Should().BeEmpty();
            notification.OldItems.Should().Equal(new KeyValuePair<string, int>("Key2", 2));
            notification.Current.Should().BeEmpty();
        }
        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_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 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 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);
        }