public void ReadZeroTest() { NoSeekMemoryStream ms = new NoSeekMemoryStream(new byte[10]); byte[] buffer = new byte[10]; int read = ms.Read(buffer, 0, 10); read = ms.Read(buffer, 0, 10); if (read != 0) { Assert.Fail(); } }
public void ReadThenSeekTest() { NoSeekMemoryStream stream = new NoSeekMemoryStream(new byte[1024]); stream.Read(new byte[1024], 0, 1024); Assert.Throws <NotSupportedException>(() => stream.Position = 0); }
public void ReadNegativeOffsetOrCountTest() { NoSeekMemoryStream ms = new NoSeekMemoryStream(new byte[10]); byte[] buffer = new byte[10]; try{ ms.Read(buffer, -1, 1); Assert.Fail(); } catch (ArgumentOutOfRangeException) { } try{ ms.Read(buffer, 0, -1); Assert.Fail(); } catch (ArgumentOutOfRangeException) { } }
public void ReadBufferNullTest() { NoSeekMemoryStream ms = new NoSeekMemoryStream(new byte[10]); try{ ms.Read(null, 0, 4); Assert.Fail(); } catch (ArgumentNullException) { } }
public void ReadMoreThanWeCanTest() { NoSeekMemoryStream ms = new NoSeekMemoryStream(new byte[10]); byte[] buffer = new byte[10]; try { ms.Read(buffer, 5, 6); Assert.Fail(); } catch (ArgumentException) { } }
public void SecondStreamWrongPositionWriteTest() { NoSeekMemoryStream s = new NoSeekMemoryStream(new byte[20]); s.Read(new byte[5], 0, 5); ConcatStream stream = new ConcatStream( new MemoryStream(new byte[10]), s); Assert.Throws <ArgumentOutOfRangeException>(() => stream.Write(new byte[40], 0, 40)); }
public void ReadMovesPositionTest() { NoSeekMemoryStream ms = new NoSeekMemoryStream(new byte[10]); byte[] buffer = new byte[10]; int read = ms.Read(buffer, 3, 5); if (ms.Position != 5) { Assert.Fail(); } }
public void NetworkStream_ConstructedWithBuffer_StoresBytes() { byte[] bytes = System.Text.Encoding.Unicode.GetBytes(TEST_STRING); NoSeekMemoryStream stream = new NoSeekMemoryStream(bytes); byte[] buffer = new byte[bytes.Length]; stream.Read(buffer, 0, buffer.Length); Assert.AreEqual(bytes, buffer); }
public void TestMethod13() { byte[] buf = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; NoSeekMemoryStream nsms = new NoSeekMemoryStream(buf); byte[] buf2 = { 11, 12, 13, 14, 15 }; nsms.Write(buf2, 0, 5); // not at Position = 5 byte[] expected = { 6, 7, 8, 9, 10, 0, 0, 0, 0, 0 }; byte[] result = new byte[expected.Length]; nsms.Read(result, 0, expected.Length); Assert.AreEqual(expected, result); // checking without offset }
public void ReadTest() { byte[] buffer = new byte[1024]; for (int i = 0; i < 1024; i++) { buffer[i] = (byte)i; } NoSeekMemoryStream stream = new NoSeekMemoryStream(buffer); byte[] readBytes = new byte[1024]; stream.Read(readBytes, 0, readBytes.Length); for (int j = 0; j < 1024; j++) { if (buffer[j] != readBytes[j]) { Assert.Fail(); } } }