public void Read_EmptyAndNullByteArrays() { using (var stream = new ChunkedReadStream(new[] { new byte[0], null, new byte[0] })) { var buffer = new byte[1]; for (var i = 0; i < 10; i++) { Assert.AreEqual(0, stream.Read(buffer, 0, buffer.Length)); } } }
public void Dispose_ThenReadThrowsObjectDisposedException() { var stream = new ChunkedReadStream(new[] { new byte[0] }); stream.Dispose(); Assert.Throws<ObjectDisposedException>(() => stream.Read(new byte[10], 0, 10)); }
public void Read_ChunkSizesMismatchReadCount() { var chunks = new[] { new byte[] { 1, 2, 3 }, new byte[] { 4 }, new byte[] { 5, 6, 7 }, }; var chunkEnumerator = chunks.AsEnumerable().GetEnumerator(); using (var stream = new ChunkedReadStream(chunkEnumerator)) { byte[] tempBuffer = new byte[8]; Assert.AreEqual(2, stream.Read(tempBuffer, offset: 0, count: 2)); Assert.AreEqual(3, stream.Read(tempBuffer, offset: 2, count: 3)); Assert.AreEqual(2, stream.Read(tempBuffer, offset: 5, count: 3)); Assert.AreEqual(0, stream.Read(tempBuffer, offset: 7, count: 1)); CollectionAssert.AreEqual(chunks.SelectMany(c => c), tempBuffer.Take(7)); } }