Esempio n. 1
0
        public void WriteTest()
        {
            byte[] buffer             = Encoding.ASCII.GetBytes("Hello");
            byte[] receivedBytes      = new byte[1024];
            int    receivedBytesCount = 0;

            tcpListenerComPort.Write(buffer, 0, buffer.Length);

            Assert.IsTrue(tcpClient.Client.Available == buffer.Length);

            receivedBytesCount = tcpClient.GetStream().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) { }
            });
        }