public void PoolMemoryStreamReadWriteBytes() { //assume const int count = 20000; var bytes = new byte[count]; for (int i = 0; i < count; i++) { bytes[i] = (byte)((i - byte.MinValue) % byte.MaxValue); } //act var stream = new PoolMemoryStream(); stream.Write(bytes, 0, count); stream.Position = 0; var readBytes = new byte[count]; int actual = 0; int read = 0; do { read = stream.Read(readBytes, read, count - read); actual += read; } while (read > 0); //assert Assert.AreEqual(stream.Length, actual, "not all written bytes can be read"); Assert.IsTrue(readBytes.SequenceEqual(bytes), "returned bytes differ from written bytes"); stream.Dispose(); }
public void PoolMemoryStreamWriteCopyToAsync() { //assume const int count = 20000; var bytes = new byte[count]; for (int i = 0; i < count; i++) { bytes[i] = (byte)((i - byte.MinValue) % byte.MaxValue); } //act var stream = new PoolMemoryStream(); stream.Write(bytes, 0, count); stream.Position = 0; var target = new MemoryStream(); stream.CopyToAsync(target).Wait(); var readBytes = target.ToArray(); //assert Assert.AreEqual(stream.Length, readBytes.Length, "not all written bytes are copied"); Assert.IsTrue(readBytes.SequenceEqual(bytes), "returned bytes differ from written bytes"); }
public void PoolMemoryStreamWriteBytes() { //assume const int count = 20000; var bytes = new byte[count]; for (int i = 0; i < count; i++) { bytes[i] = (byte)((i - byte.MinValue) % byte.MaxValue); } //act var stream = new PoolMemoryStream(); stream.Write(bytes, 0, count); //assert Assert.AreEqual(stream.Length, count, "Unexpected stream length"); Assert.AreEqual(stream.Position, count, "Unexpected position"); Assert.IsTrue(stream.Capacity >= count, "Unexpected capacity"); }