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 Position_ResetToZero_Succeeds() { var stream = new SegmentReadStream(new List <byte[]>(), 0); // This should not throw stream.Position = 0; }
public void WriteOperations_Throws() { var stream = new SegmentReadStream(new List <byte[]>(), 0); Assert.Throws <NotSupportedException>(() => stream.Flush()); Assert.Throws <NotSupportedException>(() => stream.Write(new byte[1], 0, 0)); }
public void ReadByte_CanReadAllBytes(TestStreamInitInfo info) { var stream = new SegmentReadStream(info.Segments, info.Length); for (var i = 0; i < stream.Length; i++) { Assert.Equal(i, stream.Position); Assert.Equal(i, stream.ReadByte()); } Assert.Equal(stream.Length, stream.Position); Assert.Equal(-1, stream.ReadByte()); Assert.Equal(stream.Length, stream.Position); }
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]); } }
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 Position_SetToNonZero_Throws(long position) { var stream = new SegmentReadStream(new List <byte[]>(new[] { new byte[100] }), 100); Assert.Throws <ArgumentOutOfRangeException>(() => stream.Position = position); }
public void Seek_NotZero_Throws(long offset) { var stream = new SegmentReadStream(new List <byte[]>(), 0); Assert.Throws <ArgumentOutOfRangeException>(() => stream.Seek(offset, SeekOrigin.Begin)); }
public void Seek_NotBegin_Throws(SeekOrigin origin) { var stream = new SegmentReadStream(new List <byte[]>(), 0); Assert.Throws <ArgumentException>(() => stream.Seek(0, origin)); }
public void SetLength_Throws() { var stream = new SegmentReadStream(new List <byte[]>(), 0); Assert.Throws <NotSupportedException>(() => stream.SetLength(0)); }