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 Read_CountGreaterThanSegmentSize_CanReadAllBytes(TestStreamInitInfo info) { var stream = new SegmentReadStream(info.Segments, info.Length); var count = info.SegmentSize + 1; for (var i = 0; i < stream.Length; i += count) { var output = new byte[count]; var expectedOutput = new byte[count]; var expectedBytesRead = Math.Min(count, stream.Length - i); for (var j = 0; j < expectedBytesRead; j++) { expectedOutput[j] = (byte)(i + j); } Assert.Equal(i, stream.Position); Assert.Equal(expectedBytesRead, stream.Read(output, 0, count)); Assert.True(expectedOutput.SequenceEqual(output)); } Assert.Equal(stream.Length, stream.Position); Assert.Equal(0, stream.Read(new byte[count], 0, count)); Assert.Equal(stream.Length, stream.Position); }
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]); } }