public void FlushAsync_should_call_wrapped_stream() { var stream = Substitute.For<Stream>(); var subject = new BsonStreamAdapter(stream); var task = new TaskCompletionSource<object>().Task; var cancellationToken = new CancellationTokenSource().Token; stream.FlushAsync(cancellationToken).Returns(task); var result = subject.FlushAsync(cancellationToken); result.Should().Be(task); stream.Received(1).FlushAsync(cancellationToken); }
public void FlushAsync_should_throw_when_subject_is_disposed() { var stream = Substitute.For<Stream>(); var subject = new BsonStreamAdapter(stream); var cancellationToken = new CancellationTokenSource().Token; subject.Dispose(); Action action = () => subject.FlushAsync(cancellationToken); action.ShouldThrow<ObjectDisposedException>().And.ObjectName.Should().Be("BsonStreamAdapter"); }
public void FlushAsync_should_call_wrapped_stream() { var mockStream = new Mock<Stream>(); var subject = new BsonStreamAdapter(mockStream.Object); var task = new TaskCompletionSource<object>().Task; var cancellationToken = new CancellationTokenSource().Token; mockStream.Setup(s => s.FlushAsync(cancellationToken)).Returns(task); var result = subject.FlushAsync(cancellationToken); result.Should().Be(task); mockStream.Verify(s => s.FlushAsync(cancellationToken), Times.Once); }