public void CopyToAsync_should_call_wrapped_stream()
        {
            var stream = Substitute.For<Stream>();
            var subject = new BsonStreamAdapter(stream);
            var destination = Substitute.For<Stream>();
            var bufferSize = 1;
            var cancellationToken = new CancellationTokenSource().Token;
            var task = new TaskCompletionSource<object>().Task;
            stream.CopyToAsync(destination, bufferSize, cancellationToken).Returns(task);

            var result = subject.CopyToAsync(destination, bufferSize, cancellationToken);

            result.Should().Be(task);
            stream.Received(1).CopyToAsync(destination, bufferSize, cancellationToken);
        }
        public void CopyToAsync_should_throw_when_subject_is_disposed()
        {
            var stream = Substitute.For<Stream>();
            var subject = new BsonStreamAdapter(stream);
            var destination = Substitute.For<Stream>();
            var bufferSize = 1;
            var cancellationToken = new CancellationTokenSource().Token;
            subject.Dispose();

            Action action = () => subject.CopyToAsync(destination, bufferSize, cancellationToken);

            action.ShouldThrow<ObjectDisposedException>().And.ObjectName.Should().Be("BsonStreamAdapter");
        }
        public void CopyToAsync_should_call_wrapped_stream()
        {
            var mockStream = new Mock<Stream>();
            var subject = new BsonStreamAdapter(mockStream.Object);
            var mockDestination = new Mock<Stream>();
            var bufferSize = 1;
            var cancellationToken = new CancellationTokenSource().Token;
            var task = new TaskCompletionSource<object>().Task;
            mockStream.Setup(s => s.CopyToAsync(mockDestination.Object, bufferSize, cancellationToken)).Returns(task);

            var result = subject.CopyToAsync(mockDestination.Object, bufferSize, cancellationToken);

            result.Should().Be(task);
            mockStream.Verify(s => s.CopyToAsync(mockDestination.Object, bufferSize, cancellationToken), Times.Once);
        }