Example #1
0
        public void TargetStreamIsNotCommittedIfSourceStreamNotExhausted()
        {
            var targetStream = new Mock <System.IO.Stream> {
                CallBase = true
            };

            targetStream.As <ITransactionalStream>();
            using (var stream = new ReplicatingReadStream(new MemoryStream(_content), targetStream.Object))
            {
                // don't drain the whole stream
                stream.Read(new byte[1024], 0, 1024);
            }
            // Rollback() is never called explicitly when targetStream is disposed, but neither is Commit()
            targetStream.As <ITransactionalStream>().Verify(s => s.Commit(), Times.Never());
        }
Example #2
0
 public void SourceStreamCannotBeSoughtBeforeExhaustion()
 {
     using (var stream = new ReplicatingReadStream(new MemoryStream(_content), new MemoryStream()))
     {
         stream.CanSeek.Should().BeFalse();
         // don't drain the whole stream
         stream.Read(new byte[1024], 0, 1024);
         Invoking(() => stream.Position = 0)
         .Should().Throw <InvalidOperationException>()
         .WithMessage($"{nameof(ReplicatingReadStream)} is not seekable while the inner stream has not been thoroughly read and replicated.");
         Invoking(() => stream.Seek(0, SeekOrigin.Begin))
         .Should().Throw <InvalidOperationException>()
         .WithMessage($"{nameof(ReplicatingReadStream)} cannot be sought while the inner stream has not been thoroughly read and replicated.");
     }
 }