public void ReadTest() { byte[] buffer = Encoding.ASCII.GetBytes("Hello"); byte[] receivedBytes = new byte[1024]; int receivedBytesCount = 0; tcpClient.GetStream().Write(buffer, 0, buffer.Length); Assert.IsTrue(tcpListenerComPort.BytesToRead == buffer.Length); receivedBytesCount = tcpListenerComPort.Read(receivedBytes, 0, receivedBytes.Length); Assert.IsTrue(receivedBytesCount == buffer.Length); Assert.AreEqual("Hello", Encoding.ASCII.GetString(receivedBytes, 0, receivedBytesCount)); }
public void InvalidOperationExceptionTest() { Assert.DoesNotThrow(() => { try { tcpListenerComPort.Write(new byte[] { }, 0, 0); } catch (InvalidOperationException) { } try { tcpListenerComPort.Read(new byte[] { }, 0, 0); } catch (InvalidOperationException) { } try { var bytesToRead = tcpListenerComPort.BytesToRead; } catch (InvalidOperationException) { } }); }