コード例 #1
0
        public void HandleExceptionOnSendTimeoutTest()
        {
            mock.Setup(sp => sp.Send(It.Is <string>(s => s.Equals("0"))));
            mock.Setup(sp => sp.Read()).Throws(new TimeoutException());
            ISerialPort port = mock.Object;

            SerialCommand command  = new SerialCommand(port);
            string        response = "";
            string        expected = "0";

            if (command.Send(command.StatusCheck()))
            {
                response = command.Read();
            }

            Assert.False(command.ValidateResponse(expected, response));
        }
コード例 #2
0
        public void SendSuccessfulStatusCheckTest()
        {
            string expected = "0";

            mock.Setup(sp => sp.Send(It.Is <string>(s => s.Equals("0"))));
            mock.Setup(sp => sp.Read()).Returns(expected);
            ISerialPort port = mock.Object;

            SerialCommand command  = new SerialCommand(port);
            string        response = "";

            if (command.Send(command.StatusCheck()))
            {
                response = command.Read();
            }

            Assert.True(command.ValidateResponse(expected, response));
        }