コード例 #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());
        }
コード例 #2
0
 public void LengthCanBeReadAfterStreamExhaustion()
 {
     using (var stream = new ReplicatingReadStream(new MemoryStream(_content), new MemoryStream()))
     {
         stream.Drain();
         stream.Length.Should().Be(_content.Length);
     }
 }
コード例 #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());
         }
 }
コード例 #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();
     }
 }
コード例 #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();
        }