Esempio n. 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 });
        }
Esempio n. 2
0
        public void CollectionChangedHandlerInvokedForConj()
        {
            var loader   = new AsyncLoader <int>(Seq.ListBased, eventContext: new RunInlineSynchronizationContext());
            var listener = Substitute.For <CollectionChangedHandler <int> >();

            loader.CollectionChanged += listener;


            loader.Conj(1);  // --- Perform ---


            listener.Received().Invoke(loader, Fluent.Match <IntChangesAlias>(changes =>
                                                                              changes.Should().ContainSingle().Which.ShouldBeEquivalentTo(new ItemChange <int>(ChangeType.Added, 1))));
        }
Esempio n. 3
0
        public async Task LoadAsyncPreservesItemsAddedDuringLoad()
        {
            IEnumerable <int> itemsToLoad = new[] { 2, 3, 4 };
            var loadTask = new TaskCompletionSource <IEnumerable <int> >();
            var loader   = new AsyncLoader <int>(seqFactory: Seq.ListBased, loadDataAsync: tok => loadTask.Task);


            // --- Perform ---
            var loadComplete = loader.LoadAsync();  // Will get stuck, waiting for loadTask to complete

            loader.Conj(1);


            loader.Should().BeEquivalentTo(new[] { 1 }); // sanity check
            loadTask.SetResult(itemsToLoad);             // complete loading
            await loadComplete;                          // wait for LoadAsync to finish

            loader.Should().BeEquivalentTo(new[] { 1, 2, 3, 4 });
        }
Esempio n. 4
0
        public void CanConjWithoutLoadOrUpdate()
        {
            var loader = new AsyncLoader <int>(Seq.ListBased);

            loader.Conj(1);
        }