public void CopyToAsync_CopiesFromStart_AfterReset(TestStreamInitInfo info) { var skippedBytes = info.SegmentSize; var writeStream = new SegmentWriteStream(info.SegmentSize); var stream = new SegmentReadStream(info.Segments, info.Length); stream.Read(new byte[skippedBytes], 0, skippedBytes); stream.CopyTo(writeStream); // Assert bytes read from current location to the end Assert.Equal(stream.Length, stream.Position); Assert.Equal(stream.Length - skippedBytes, writeStream.Length); // Reset stream.Position = 0; writeStream = new SegmentWriteStream(info.SegmentSize); stream.CopyTo(writeStream); Assert.Equal(stream.Length, stream.Position); Assert.Equal(stream.Length, writeStream.Length); var writeSegments = writeStream.GetSegments(); for (var i = 0; i < info.Segments.Count; i++) { Assert.True(writeSegments[i].SequenceEqual(info.Segments[i])); } }
public void CopyToAsync_CopiesAllBytes(TestStreamInitInfo info) { var stream = new SegmentReadStream(info.Segments, info.Length); var writeStream = new SegmentWriteStream(info.SegmentSize); stream.CopyTo(writeStream); Assert.Equal(stream.Length, stream.Position); Assert.Equal(stream.Length, writeStream.Length); var writeSegments = writeStream.GetSegments(); for (var i = 0; i < info.Segments.Count; i++) { Assert.True(writeSegments[i].SequenceEqual(info.Segments[i])); } }
public void CopyToAsync_CopiesFromCurrentPosition(TestStreamInitInfo info) { var skippedBytes = info.SegmentSize; var writeStream = new SegmentWriteStream((int)info.Length); var stream = new SegmentReadStream(info.Segments, info.Length); stream.Read(new byte[skippedBytes], 0, skippedBytes); stream.CopyTo(writeStream); Assert.Equal(stream.Length, stream.Position); Assert.Equal(stream.Length - skippedBytes, writeStream.Length); var writeSegments = writeStream.GetSegments(); for (var i = skippedBytes; i < info.Length; i++) { Assert.Equal(info.Segments[i / info.SegmentSize][i % info.SegmentSize], writeSegments[0][i - skippedBytes]); } }