Beispiel #1
0
        public async Task UpdateAsyncPreservesItemsAddedDuringUpdate()
        {
            IEnumerable <ItemChange <int> > changes = new[]
            {
                new ItemChange <int>(ChangeType.Added, 2),
                new ItemChange <int>(ChangeType.Added, 3)
            };

            var updateTask = new TaskCompletionSource <IEnumerable <ItemChange <int> > >();
            var loader     = new AsyncLoader <int>(
                seqFactory: Seq.ListBased,
                fetchUpdatesAsync: (_, __) => updateTask.Task);


            // --- Perform ---
            var finishUpdate = loader.UpdateAsync();  // returns a continuation stuck waiting for updateTask to complete

            loader.Conj(1);

            updateTask.SetResult(changes); // complete updateTask...
            await finishUpdate;            // ...and wait for completion to finish


            loader.ShouldAllBeEquivalentTo(new[] { 1, 2, 3 });
        }
Beispiel #2
0
        public async Task CanUpdateEmptyLoaderWithSingleAddition()
        {
            IEnumerable <ItemChange <int> > changes = new[] { new ItemChange <int>(ChangeType.Added, 1) };

            var loader = new AsyncLoader <int>(
                seqFactory: Seq.ListBased,
                fetchUpdatesAsync: (_, __) => Task.FromResult(changes));

            await loader.UpdateAsync(); // --- Perform ---

            loader.ShouldAllBeEquivalentTo(new[] { 1 });
        }
Beispiel #3
0
        public async Task CanUpdateNonEmptyLoaderWithEmptyChanges()
        {
            IEnumerable <int> initialItems = new[] { 1, 2, 3 };

            var loader = new AsyncLoader <int>(
                seqFactory: Seq.ListBased,
                loadDataAsync: _ => Task.FromResult(initialItems),
                fetchUpdatesAsync: (_, __) => Task.FromResult(Enumerable.Empty <ItemChange <int> >()));
            await loader.LoadAsync();   // load initial data

            await loader.UpdateAsync(); // --- Perform ---

            loader.ShouldAllBeEquivalentTo(initialItems);
        }