Example #1
0
        public void TestMpackOpenPlusDataWriteRead()
        {
            // Arrange
            var args1 = OpenRequest.Create(new Reference(), (int)CodecId.Mpack,
                                           "dfksjaödfjkasdfölskajdfölsadfjkslöajksadlöjksdlöfsjkadflösdajkfösdlafj", 0, false);
            var args2 = DataMessage.Create(new byte[600], new AnySocketAddress(), 12);

            new Random().NextBytes(args2.Payload);

            var datagramIn1 = Message.Create(null, null, null, args1);
            var datagramIn2 = Message.Create(null, null, null, args2);
            var stream      = new MemoryStream();

            // Act
            datagramIn1.Encode(stream, CodecId.Mpack);
            datagramIn2.Encode(stream, CodecId.Mpack);
            byte[] buf = Interop.MessageDecodeEncode(CodecId.Mpack, 2, stream.GetBuffer(), stream.Length, buffer, buffer.Length);

            stream = new MemoryStream(buf);
            Message returned1 = Serializable.Decode <Message>(stream, CodecId.Mpack);
            Message returned2 = Serializable.Decode <Message>(stream, CodecId.Mpack);

            // Assert
            Assert.IsTrue(datagramIn1.Equals(returned1));
            Assert.IsTrue(datagramIn2.Equals(returned2));
        }
Example #2
0
        public void TestMpackOpenPlusDataWriteRead()
        {
            // Arrange
            OpenRequest args1 = new OpenRequest();

            args1.StreamId         = new Reference();
            args1.ConnectionString = "dfksjaödfjkasdfölskajdfölsadfjkslöajksadlöjksdlöfsjkadflösdajkfösdlafj";
            args1.IsPolled         = false;
            DataMessage args2 = new DataMessage();

            args2.Source  = new NullSocketAddress();
            args2.Payload = new byte[600];
            args2.Control = new byte[0];
            new Random().NextBytes(args2.Payload);

            Message      datagramIn1 = new Message(null, null, null, args1);
            Message      datagramIn2 = new Message(null, null, null, args2);
            MemoryStream stream      = new MemoryStream();

            // Act
            datagramIn1.Encode(stream, CodecId.Mpack);
            datagramIn2.Encode(stream, CodecId.Mpack);
            byte[] buf = Interop.MessageDecodeEncode(CodecId.Mpack, 2, stream.GetBuffer(), stream.Length, buffer, buffer.Length);

            stream = new MemoryStream(buf);
            Message returned1 = Message.Decode(stream, CodecId.Mpack);
            Message returned2 = Message.Decode(stream, CodecId.Mpack);

            // Assert
            Assert.IsTrue(datagramIn1.Equals(returned1));
            Assert.IsTrue(datagramIn2.Equals(returned2));
        }
Example #3
0
        public void TestMpackOpenRequestWriteRead()
        {
            // Arrange
            var args = OpenRequest.Create(new Reference(), (int)CodecId.Mpack,
                                          "dfksjaödfjkasdfölskajdfölsadfjkslöajksadlöjksdlöfsjkadflösdajkfösdlafj", 0, true);
            var request = Message.Create(null, null, null, args);
            var stream  = new MemoryStream();

            // Act
            request.Encode(stream, CodecId.Mpack);
            byte[] buf      = Interop.MessageDecodeEncode(CodecId.Mpack, 1, stream.GetBuffer(), stream.Length, buffer, buffer.Length);
            var    returned = Serializable.Decode <Message>(new MemoryStream(buf), CodecId.Mpack);

            // Assert
            Assert.IsTrue(request.Equals(returned));
        }
Example #4
0
        public void TestJsonOpenRequestWriteRead()
        {
            // Arrange
            OpenRequest args = new OpenRequest();

            args.StreamId         = new Reference();
            args.ConnectionString = "dfksjaödfjkasdfölskajdfölsadfjkslöajksadlöjksdlöfsjkadflösdajkfösdlafj";
            args.IsPolled         = true;

            Message      request = new Message(null, null, null, args);
            MemoryStream stream  = new MemoryStream();

            // Act
            request.Encode(stream, CodecId.Json);
            byte[]  buf      = Interop.MessageDecodeEncode(CodecId.Json, 1, stream.GetBuffer(), stream.Length, buffer, buffer.Length);
            Message returned = Message.Decode(new MemoryStream(buf), CodecId.Json);

            // Assert
            Assert.IsTrue(request.Equals(returned));
        }