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()); }
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(); _content.Should().BeEquivalentTo(targetStream.ToArray()); } }
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(); } }
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(); }