Example #1
0
        public void ReadsData()
        {
            string targetString = "OK";

            byte[] bytes = Encoding.ASCII.GetBytes(targetString + '\0');

            Mock <ILibc> mock = new Mock <ILibc>();

            mock.Setup(o => o.Read(It.IsAny <int>(), It.IsAny <IntPtr>(), It.IsAny <IntPtr>()))
            .Returns(new IntPtr(1))
            .Callback <int, IntPtr, IntPtr>((i, p, c) => Marshal.Copy(bytes, 0, p, bytes.Length));


            SerialCommunication serial = new SerialCommunication(mock.Object);

            serial.Open("dummy");

            string received = serial.ReadOnce();

            Assert.AreEqual(targetString, received);
        }