public void CollectionChangeHandlerInvokedForLoadWithContravariantHandler() { IEnumerable <Item> loadedItems = new[] { new Item(), new Item() }; var loader = new AsyncLoader <Item>( seqFactory: Seq.ListBased, loadDataAsync: t => Task.FromResult(loadedItems), eventContext: new RunInlineSynchronizationContext()); // Simulate an external consumer of this collection IAsyncCollection <IItem> externalView = loader; var listener = Substitute.For <CollectionChangedHandler <IItem> >(); externalView.CollectionChanged += listener; loader.LoadAsync(); // --- Perform --- var expectedChanges = loadedItems.Select(item => new ItemChange <Item>(ChangeType.Added, item)); listener.Received().Invoke(loader, Fluent.Match <IEnumerable <IItemChange <Item> > >(coll => coll.Should().BeEquivalentTo(expectedChanges))); }
public async Task CollectionChangedHandlerInvokedForConjAsync() { var loader = new AsyncLoader <int>(Seq.ListBased, eventContext: new RunInlineSynchronizationContext()); var listener = Substitute.For <CollectionChangedHandler <int> >(); loader.CollectionChanged += listener; await loader.ConjAsync(1, CancellationToken.None); // --- Perform --- listener.Received().Invoke(loader, Fluent.Match <IntChangesAlias>(changes => changes.Should().ContainSingle().Which.ShouldBeEquivalentTo(new ItemChange <int>(ChangeType.Added, 1)))); }
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)))); }
public void CollectionChangedHandlerInvokedForLoadOfInts() { var loadedItems = new[] { 1, 2, 3 }; var loader = new AsyncLoader <int>( seqFactory: Seq.ListBased, loadDataAsync: t => Task.FromResult(loadedItems.AsEnumerable()), eventContext: new RunInlineSynchronizationContext()); var listener = Substitute.For <CollectionChangedHandler <int> >(); loader.CollectionChanged += listener; loader.LoadAsync(); // --- Perform --- var expectedChanges = loadedItems.Select(i => new ItemChange <int>(ChangeType.Added, i)); listener.Received().Invoke(loader, Fluent.Match <IntChangesAlias>(coll => coll.Should().BeEquivalentTo(expectedChanges))); }