public void TestParsePayload()
        {
            PayloadParser parser = new PayloadParser();
            parser.AppendData(ValidPayloads.payloadWithTitlePingAndTextValueHello);
            Payload payload = parser.FindAndRemoveNextPayload();

            Assert.AreEqual("ping", payload.Title);
            CollectionAssert.AreEqual(new byte[] { 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x00 }, payload.Value);
        }
        /// <summary>
        /// Creates an object for communicating (serial over Bluetooth) with the EV3.
        /// </summary>
        public Communicator()
        {
            payloadParser = new PayloadParser();
            readPayloadsQueue = new ConcurrentQueue<Payload>();

            serialPort = new SerialPort();
            serialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);

            connectLock = new Object();
        }
        public void TestParsePayloadWithEmptyTextValueThatIsNotAtheStartOfTheBuffer()
        {
            PayloadParser parser = new PayloadParser();
            parser.AppendData(new byte[] { 0x00 });
            parser.AppendData(ValidPayloads.payloadWithTitlePingAndEmptyTextValue);
            Payload payload = parser.FindAndRemoveNextPayload();

            Assert.AreEqual("ping", payload.Title);
            CollectionAssert.AreEqual(new byte[] { 0x00 }, payload.Value);
        }
        public void TestParsePayloadWithMissingFirstTwoBytes()
        {
            PayloadParser parser = new PayloadParser();
            parser.AppendData(InvalidPayloads.payloadWithMissingFirstByte);
            Payload payload = parser.FindAndRemoveNextPayload();

            Assert.AreEqual(null, payload);
        }
        public void TestParsePayloadWithMissingFirstByteAndAddedOtherByte()
        {
            PayloadParser parser = new PayloadParser();
            parser.AppendData(new byte[] { 0x00 });
            parser.AppendData(InvalidPayloads.payloadWithMissingFirstByte);
            Payload payload = parser.FindAndRemoveNextPayload();

            Assert.AreEqual(null, payload);
        }