public void CanReceiveByte() { byte expected = 0x03; Session session = new Session("localhost", DefaultPort); AcceptAndSendBytes(new byte[] { expected }); byte actual = session.ReadByte(); session.Close(); Assert.AreEqual(expected, actual); }
public void CanSendByte() { byte expected = 0xCA; Session session = new Session("localhost", DefaultPort); session.Write(expected); TcpClient client = server.AcceptTcpClient(); int actual = client.GetStream().ReadByte(); Assert.AreEqual(expected, actual); client.Close(); session.Close(); }
public Presentation(string hostname, int port) { this.session = new Session(hostname, port); this.ResetCancellationToken(); }
public void CanSendBytes() { byte[] expected = new byte[] { 0xCA, 0xFE }; Session session = new Session("localhost", DefaultPort); session.Write(expected); TcpClient client = server.AcceptTcpClient(); byte[] actual = new byte[2]; client.GetStream().Read(actual, 0, 2); Assert.AreEqual(expected, actual); client.Close(); session.Close(); }
public void ThrowsExceptionTryingToWriteBytesOnClosed() { Session session = new Session("localhost", DefaultPort); server.AcceptTcpClient().Close(); Assert.Throws<SocketException>(() => session.Write(new byte[] { 0xCA })); }
public void ThrowsExceptionTryingToReadPacketOnClosed() { Session session = new Session("localhost", DefaultPort); server.AcceptTcpClient().Close(); Assert.Throws<SocketException>(() => session.ReadPacket(0xCA)); }
public void ReceiveUntilByteNoRepeated() { Session session = new Session("localhost", DefaultPort); TcpClient client = server.AcceptTcpClient(); byte sepByte = 0xCA; byte[] expected = new byte[] { 0xCA, 0xFE, 0xBE }; client.GetStream().Write(expected, 0, expected.Length); byte[] actual = session.ReadPacket(sepByte); Assert.AreEqual(expected, actual); client.Close(); session.Close(); }