Ejemplo n.º 1
0
        public void when_write_and_read_more_messages_with_attribute()
        {
            var serializer = new TestMessageSerializer(new[] { typeof(SerializerTest1), typeof(SerializerTest2), });
            var msg1       = new SerializerTest1()
            {
                Name = "message1"
            };
            var msg2 = new SerializerTest2()
            {
                Name = "message2"
            };
            var stream = new MemoryStream();

            serializer.WriteAttributes(new List <MessageAttribute> {
                new MessageAttribute("attr1", "val1"), new MessageAttribute("attr2", "val2")
            }, stream);
            serializer.WriteCompactInt(2, stream);
            serializer.WriteMessage(msg1, msg1.GetType(), stream);
            serializer.WriteMessage(msg2, msg2.GetType(), stream);
            stream.Seek(0, SeekOrigin.Begin);
            var readedAttributes = serializer.ReadAttributes(stream);
            var count            = serializer.ReadCompactInt(stream);
            var readedMessage1   = serializer.ReadMessage(stream);
            var readedMessage2   = serializer.ReadMessage(stream);

            Assert.AreEqual(2, readedAttributes.Length);
            Assert.AreEqual("attr1", readedAttributes[0].Key);
            Assert.AreEqual("val1", readedAttributes[0].Value);
            Assert.AreEqual("attr2", readedAttributes[1].Key);
            Assert.AreEqual("val2", readedAttributes[1].Value);
            Assert.AreEqual(typeof(SerializerTest1), readedMessage1.GetType());
            Assert.AreEqual("message1", (readedMessage1 as SerializerTest1).Name);
            Assert.AreEqual(typeof(SerializerTest2), readedMessage2.GetType());
            Assert.AreEqual("message2", (readedMessage2 as SerializerTest2).Name);
        }
        public void when_write_and_read_compactint()
        {
            var serializer = new TestMessageSerializer(new[] { typeof(SerializerTest1), typeof(SerializerTest2), });
            var stream = new MemoryStream();
            serializer.WriteCompactInt(10, stream);
            stream.Seek(0, SeekOrigin.Begin);
            var count = serializer.ReadCompactInt(stream);

            Assert.AreEqual(10, count);
        }
Ejemplo n.º 3
0
        public void when_write_and_read_compactint()
        {
            var serializer = new TestMessageSerializer(new[] { typeof(SerializerTest1), typeof(SerializerTest2), });
            var stream     = new MemoryStream();

            serializer.WriteCompactInt(10, stream);
            stream.Seek(0, SeekOrigin.Begin);
            var count = serializer.ReadCompactInt(stream);

            Assert.AreEqual(10, count);
        }
        public void when_write_and_read_more_messages_with_attribute()
        {
            var serializer = new TestMessageSerializer(new[] { typeof(SerializerTest1), typeof(SerializerTest2), });
            var msg1 = new SerializerTest1() { Name = "message1" };
            var msg2 = new SerializerTest2() { Name = "message2" };
            var stream = new MemoryStream();
            serializer.WriteAttributes(new List<MessageAttribute> { new MessageAttribute("attr1", "val1"), new MessageAttribute("attr2", "val2") }, stream);
            serializer.WriteCompactInt(2, stream);
            serializer.WriteMessage(msg1, msg1.GetType(), stream);
            serializer.WriteMessage(msg2, msg2.GetType(), stream);
            stream.Seek(0, SeekOrigin.Begin);
            var readedAttributes = serializer.ReadAttributes(stream);
            var count = serializer.ReadCompactInt(stream);
            var readedMessage1 = serializer.ReadMessage(stream);
            var readedMessage2 = serializer.ReadMessage(stream);

            Assert.AreEqual(2, readedAttributes.Length);
            Assert.AreEqual("attr1", readedAttributes[0].Key);
            Assert.AreEqual("val1", readedAttributes[0].Value);
            Assert.AreEqual("attr2", readedAttributes[1].Key);
            Assert.AreEqual("val2", readedAttributes[1].Value);
            Assert.AreEqual(typeof(SerializerTest1), readedMessage1.GetType());
            Assert.AreEqual("message1", (readedMessage1 as SerializerTest1).Name);
            Assert.AreEqual(typeof(SerializerTest2), readedMessage2.GetType());
            Assert.AreEqual("message2", (readedMessage2 as SerializerTest2).Name);
        }