Ejemplo n.º 1
0
        public void SerilaizeTest()
        {
            var sid = 1;
            var cid = "3-1-3";
            var mid = "4-2-3";

            var m = new TestMessage
            {
                SourceID       = sid,
                ConversationID = cid,
                MessageID      = mid
            };

            var serailizedMessage = MessageFactory.GetMessage(m.Encode(), false);

            Assert.AreEqual(serailizedMessage.SourceID, m.SourceID);
            Assert.AreEqual(serailizedMessage.ConversationID, m.ConversationID);
            Assert.AreEqual(serailizedMessage.MessageID, m.MessageID);
        }
Ejemplo n.º 2
0
        public static void Test()
        {
            int iMessagesComplete = 0;

            var p = new MessageProtocol();

            p.MessageComplete += bytes =>
            {
                var messageReceived = Message.Decode(bytes);
                System.Diagnostics.Debug.Assert(messageReceived is TestMessage);
                System.Diagnostics.Debug.Assert(((TestMessage)messageReceived).Text == "Hello World!");
                iMessagesComplete++;
            };

            var m = new TestMessage()
            {
                Text = "Hello World!"
            };

            byte[] b = m.Encode();
            p.Receive(b);
            System.Diagnostics.Debug.Assert(iMessagesComplete == 1);

            byte[] firstHalf  = new byte[10];
            byte[] secondHalf = new byte[b.Length - firstHalf.Length];
            Array.Copy(b, firstHalf, firstHalf.Length);
            Array.Copy(b, firstHalf.Length, secondHalf, 0, secondHalf.Length);

            p.Receive(firstHalf);
            System.Diagnostics.Debug.Assert(iMessagesComplete == 1);
            p.Receive(secondHalf);
            System.Diagnostics.Debug.Assert(iMessagesComplete == 2);

            byte[] twoMessages = new byte[b.Length * 2];
            b.CopyTo(twoMessages, 0);
            b.CopyTo(twoMessages, b.Length);

            p.Receive(twoMessages);
            System.Diagnostics.Debug.Assert(iMessagesComplete == 4);
        }