Ejemplo n.º 1
0
        public void TargetStreamIsCommittedOnlyOnceEvenIfStreamIsRewound()
        {
            var targetStream = new Mock <System.IO.Stream> {
                CallBase = true
            };
            var streamTransacted = targetStream.As <ITransactionalStream>();

            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());
        }
Ejemplo n.º 2
0
 public void LengthCanBeReadAfterStreamExhaustion()
 {
     using (var stream = new ReplicatingReadStream(new MemoryStream(_content), new MemoryStream()))
     {
         stream.Drain();
         stream.Length.Should().Be(_content.Length);
     }
 }
Ejemplo n.º 3
0
 public void SourceStreamIsReplicatedToTargetStreamWhileBeingRead()
 {
     using (var targetStream = new MemoryStream())
         using (var stream = new ReplicatingReadStream(new MemoryStream(_content), targetStream))
         {
             stream.Drain();
             _content.Should().BeEquivalentTo(targetStream.ToArray());
         }
 }
Ejemplo n.º 4
0
 public void SourceStreamIsSeekableAfterExhaustion()
 {
     using (var stream = new ReplicatingReadStream(new MemoryStream(_content), new MemoryStream()))
     {
         stream.CanSeek.Should().BeFalse();
         stream.Drain();
         stream.CanSeek.Should().BeTrue();
         Invoking(() => stream.Position = 0).Should().NotThrow();
     }
 }
Ejemplo n.º 5
0
        public void TargetStreamIsCommittedUponSourceStreamExhaustion()
        {
            var targetStream = new Mock <System.IO.Stream> {
                CallBase = true
            };

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