public void ClearDelegatesToUnderlyingSeq() { var seq = Substitute.For <ISeq <int> >(); var loader = new ThreadSafeAsyncLoader <int>(enumerable => seq); loader.Clear(); // --- Perform --- seq.Received().Clear(); }
public void ClearDoesNotNotifyIfNoChangesWereMade() { var loader = new ThreadSafeAsyncLoader <int>(Seq.ListBased, eventContext: new RunInlineSynchronizationContext()); var listener = Substitute.For <CollectionChangedHandler <int> >(); loader.CollectionChanged += listener; loader.Clear(); // --- Perform --- listener.DidNotReceive().Invoke(loader, Arg.Any <IntChangesAlias>()); }
public void ClearNotifiesOfChangesMade() { IEnumerable <int> initialValues = new[] { 1, 2, 3 }; var expectedChanges = initialValues.Select(i => new ItemChange <int>(ChangeType.Removed, i)); var loader = new ThreadSafeAsyncLoader <int>( Seq.ListBased, loadDataAsync: tok => Task.FromResult(initialValues), eventContext: new RunInlineSynchronizationContext()); loader.LoadAsync(); // load initial values var listener = Substitute.For <CollectionChangedHandler <int> >(); loader.CollectionChanged += listener; loader.Clear(); // --- Perform --- listener.Received().Invoke(loader, Fluent.Match <IntChangesAlias>( changes => changes.Should().BeEquivalentTo(expectedChanges))); }
public void ClearNotifiesOfChangeForSingletonSeq() { IEnumerable <int> initialValues = new[] { 1 }; var loader = new ThreadSafeAsyncLoader <int>( Seq.ListBased, loadDataAsync: tok => Task.FromResult(initialValues), eventContext: new RunInlineSynchronizationContext()); loader.LoadAsync(); // load initial values var listener = Substitute.For <CollectionChangedHandler <int> >(); loader.CollectionChanged += listener; loader.Clear(); // --- Perform --- listener.Received().Invoke(loader, Fluent.Match <IntChangesAlias>(changes => changes .Should().ContainSingle("because loader contained single item before Clear") .Which.Should().BeRemovalOf(1, "because loader contained the value 1 before Clear"))); }