public void PacketStreamWriteWhenReadOnlyTest() { using (INetPacketStream packetStream = new NetPacketStream(_randomizer.Bytes(_randomizer.Byte()))) { Assert.Throws <InvalidOperationException>(() => packetStream.Write <byte>(_randomizer.Byte())); } }
public void PacketStreamWriteNonPrimitiveTest() { using (INetPacketStream packetStream = new NetPacketStream()) { Assert.Throws <NotImplementedException>(() => packetStream.Write <object>(new object())); } }
private void TestWrite <T>(byte[] expected, T value) { byte[] packetStreamBuffer = null; using (INetPacketStream packetStream = new NetPacketStream()) { packetStream.Write(value); packetStreamBuffer = packetStream.Buffer; } Assert.Equal(expected, packetStreamBuffer); }
private void PacketStreamWritePrimitive <T>(T valueToWrite, byte[] expectedByteArray, bool adjustBuffer = true) { using (INetPacketStream packetStream = new NetPacketStream()) { Assert.Equal(NetPacketStateType.Write, packetStream.State); packetStream.Write(valueToWrite); byte[] adjustedBuffer = adjustBuffer ? expectedByteArray.Take(Marshal.SizeOf <T>()).ToArray() : expectedByteArray; Assert.Equal(adjustedBuffer, packetStream.Buffer); } }
public void WriteByteArray() { byte[] readByteArray = null; byte[] packetStreamBuffer = null; using (INetPacketStream packetStream = new NetPacketStream()) { packetStream.Write(ByteArrayValue); packetStreamBuffer = packetStream.Buffer; } using (INetPacketStream readPacketStream = new NetPacketStream(packetStreamBuffer)) { readByteArray = readPacketStream.Read <byte[]>(); } Assert.Equal(ByteArrayValue, readByteArray); }
public void WriteString() { string readString = null; byte[] packetStreamBuffer = null; using (INetPacketStream packetStream = new NetPacketStream()) { packetStream.Write(StringValue); packetStreamBuffer = packetStream.Buffer; } using (INetPacketStream readPacketStream = new NetPacketStream(packetStreamBuffer)) { readString = readPacketStream.Read <string>(); } Assert.Equal(StringValue, readString); }