Ejemplo n.º 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));
        }
Ejemplo n.º 2
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));
        }