public void TargetStreamIsCommittedOnlyOnceEvenIfStreamIsRewinded()
        {
            var targetStream = new Mock <Stream> {
                CallBase = true
            };
            var streamTransacted = targetStream.As <IStreamTransacted>();

            streamTransacted.Setup(s => s.Commit());
            using (var stream = new ReplicatingReadStream(new MemoryStream(_content), targetStream.Object))
            {
                stream.Drain();
                stream.Position = 0;
                stream.Drain();
            }
            streamTransacted.Verify(s => s.Commit(), Times.Once());
        }
 public void LengthCanBeReadAfterStreamExhaustion()
 {
     using (var stream = new ReplicatingReadStream(new MemoryStream(_content), new MemoryStream()))
     {
         stream.Drain();
         Assert.That(stream.Length, Is.EqualTo(_content.Length));
     }
 }
 public void LengthCanBeReadAfterStreamExhaustion()
 {
     using (var stream = new ReplicatingReadStream(new MemoryStream(_content), new MemoryStream()))
     {
         stream.Drain();
         stream.Length.Should().Be(_content.Length);
     }
 }
 public void SourceStreamIsReplicatedToTargetStreamWhileBeingRead()
 {
     using (var targetStream = new MemoryStream())
         using (var stream = new ReplicatingReadStream(new MemoryStream(_content), targetStream))
         {
             stream.Drain();
             Assert.That(_content, Is.EqualTo(targetStream.ToArray()));
         }
 }
 public void SourceStreamIsReplicatedToTargetStreamWhileBeingRead()
 {
     using (var targetStream = new MemoryStream())
         using (var stream = new ReplicatingReadStream(new MemoryStream(_content), targetStream))
         {
             stream.Drain();
             _content.Should().BeEquivalentTo(targetStream.ToArray());
         }
 }
 public void SourceStreamIsSeekableAfterExhaustion()
 {
     using (var stream = new ReplicatingReadStream(new MemoryStream(_content), new MemoryStream()))
     {
         Assert.That(stream.CanSeek, Is.False);
         stream.Drain();
         Assert.That(stream.CanSeek);
         Assert.That(() => stream.Position = 0, Throws.Nothing);
     }
 }
 public void SourceStreamIsSeekableAfterExhaustion()
 {
     using (var stream = new ReplicatingReadStream(new MemoryStream(_content), new MemoryStream()))
     {
         stream.CanSeek.Should().BeFalse();
         stream.Drain();
         stream.CanSeek.Should().BeTrue();
         Action act = () => stream.Position = 0;
         act.Should().NotThrow();
     }
 }
        public void TargetStreamIsCommittedUponSourceStreamExhaustion()
        {
            var targetStream = new Mock <Stream> {
                CallBase = true
            };

            targetStream.As <IStreamTransacted>().Setup(st => st.Commit()).Verifiable("targetStream");
            using (var stream = new ReplicatingReadStream(new MemoryStream(_content), targetStream.Object))
            {
                stream.Drain();
            }
            targetStream.VerifyAll();
        }