public void GetBufferAfterMultipleAppend() { var buffer = new NetworkBuffer(8); buffer.Append(new byte[] { 0, 1, 2, 3 }); buffer.Append(new byte[] { 4, 5, 6, 7 }); byte[] data = buffer.ToArray(); Assert.AreEqual <int>(8, buffer.Received, "Received was not the right size."); //An impossible test case Assert.AreEqual <int>(8, buffer.Size, "Size was not assign the right value."); //An impossible test case Assert.AreEqual <int>(buffer.Received, data.Length, "Received and length should be the same size."); Assert.AreEqual <byte>(0, data[0], "First byte in buffer should be zero."); Assert.AreEqual <byte>(7, data[7], "Eight byte in buffer should be seven."); Assert.IsTrue(buffer.Completed, "Completed should be true.");//An impossible test case buffer.Dispose(); }
public void AppendFillBuffer() { var buffer = new NetworkBuffer(10); buffer.Append(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); Assert.AreEqual <int>(10, buffer.Received, "Received was not the right size."); //An impossible test case Assert.AreEqual <int>(10, buffer.Size, "Size was not assign the right value."); //An impossible test case Assert.IsTrue(buffer.Completed, "Completed should be true."); //An impossible test case buffer.Dispose(); }
public void GetBufferAfterOneAppend() { var buffer = new NetworkBuffer(10); buffer.Append(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }); byte[] data = buffer.ToArray(); Assert.AreEqual <int>(8, buffer.Received, "Received was not the right size."); //An impossible test case Assert.AreEqual <int>(10, buffer.Size, "Size was not assign the right value."); //An impossible test case Assert.AreEqual <int>(buffer.Received, data.Length, "Received and length should be the same size."); Assert.IsFalse(buffer.Completed, "Completed should be false."); //An impossible test case buffer.Dispose(); }
public void AppendAfterCompletedBuffer() { var buffer = new NetworkBuffer(10); buffer.Append(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); try { buffer.Append(new byte[] { 0 }); Assert.Fail("Argument out of range exception should be thrown."); } catch (ArgumentOutOfRangeException) { } catch (Exception) { Assert.Fail("Nothing other than argument out of range exception should be thrown."); } Assert.AreEqual <int>(10, buffer.Received, "Received was not the right size."); //An impossible test case Assert.AreEqual <int>(10, buffer.Size, "Size was not assign the right value."); //An impossible test case Assert.IsTrue(buffer.Completed, "Completed should be true."); //An impossible test case buffer.Dispose(); }
public void AppendHugeBuffer() { var buffer = new NetworkBuffer(HUGE_BUFFER_DATA.Length); buffer.Append(HUGE_BUFFER_DATA); byte[] data = buffer.ToArray(); Assert.AreEqual <int>(HUGE_BUFFER_DATA.Length, buffer.Received, "Received was not the right size."); //An impossible test case Assert.AreEqual <int>(HUGE_BUFFER_DATA.Length, buffer.Size, "Size was not assign the right value."); //An impossible test case Assert.AreEqual <int>(buffer.Received, data.Length, "Received and length should be the same size."); Assert.AreEqual <byte>(HUGE_BUFFER_DATA[5], data[5], "First byte in buffer should be zero."); Assert.AreEqual <byte>(HUGE_BUFFER_DATA[1024], data[1024], "Eight byte in buffer should be seven."); Assert.IsTrue(buffer.Completed, "Completed should be true.");//An impossible test case buffer.Dispose(); }
public void AppendBigBufferInChunks() { var buffer = new NetworkBuffer(BIG_BUFFER_DATA.Length); for (int i = 0; i < 3000; i += 100) { byte[] copy = new byte[100]; Array.ConstrainedCopy(BIG_BUFFER_DATA, i, copy, 0, 100); buffer.Append(copy); } byte[] data = buffer.ToArray(); Assert.AreEqual <int>(BIG_BUFFER_DATA.Length, buffer.Received, "Received was not the right size."); //An impossible test case Assert.AreEqual <int>(BIG_BUFFER_DATA.Length, buffer.Size, "Size was not assign the right value."); //An impossible test case Assert.AreEqual <int>(buffer.Received, data.Length, "Received and length should be the same size."); Assert.AreEqual <byte>(BIG_BUFFER_DATA[5], data[5], "First byte in buffer should be zero."); Assert.AreEqual <byte>(BIG_BUFFER_DATA[1024], data[1024], "Eight byte in buffer should be seven."); Assert.IsTrue(buffer.Completed, "Completed should be true.");//An impossible test case buffer.Dispose(); }
public void ResetPositionTest1() { MemoryStream bytesRead = new MemoryStream(); var buffer = new NetworkBuffer(BIG_BUFFER_DATA.Length); buffer.Append(BIG_BUFFER_DATA); buffer.ResetPosition(); try { byte[] read = buffer.Read(1); Assert.AreEqual <byte>(BIG_BUFFER_DATA[0], read[0]); } catch (Exception) { Assert.Fail("Reset position should have allowed for the buffer to be readable again."); } finally { buffer.Dispose(); } }