Exemplo n.º 1
0
        public async Task DoesNotWrapAsyncSeqFactory()
        {
            var seq = Substitute.For <IAsyncSeq <string> >();

            var loader = new AsyncLoader <string>(seqFactory: l => seq);


            await loader.TakeAsync(CancellationToken.None);  // --- Perform ---


            // If the factory is wrapped, a TakeAsync on loader will end up calling Take on seq
            seq.DidNotReceive().Take();
            await seq.Received().TakeAsync(Arg.Any <CancellationToken>());
        }
Exemplo n.º 2
0
        public async Task CollectionChangedHandlerInvokedForTakeAsync()
        {
            IEnumerable <int> loadedInts = new[] { 35 };
            var loader = new AsyncLoader <int>(
                Seq.ListBased,
                loadDataAsync: tok => Task.FromResult(loadedInts),
                eventContext: new RunInlineSynchronizationContext());

            await loader.LoadAsync();  // load initial items

            var listener = Substitute.For <CollectionChangedHandler <int> >();

            loader.CollectionChanged += listener;


            await loader.TakeAsync(CancellationToken.None);  // --- Perform ---


            listener.Received().Invoke(loader, Fluent.Match <IntChangesAlias>(changes =>
                                                                              changes.Should().ContainSingle().Which.ShouldBeEquivalentTo(new ItemChange <int>(ChangeType.Removed, 35))));
        }