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_attributes_and_messages() { var serializer = new TestMessageSerializer(new[] { typeof(SerializerTest1), typeof(SerializerTest2), }); var msg = new SerializerTest1() { Name = "test name" }; var stream = new MemoryStream(); serializer.WriteAttributes(new List <MessageAttribute> { new MessageAttribute("attr1", "val1"), new MessageAttribute("attr2", "val2") }, stream); serializer.WriteMessage(msg, msg.GetType(), stream); stream.Seek(0, SeekOrigin.Begin); var readedAttributes = serializer.ReadAttributes(stream); var readedMessage = 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), readedMessage.GetType()); Assert.AreEqual("test name", (readedMessage as SerializerTest1).Name); }
public void when_write_and_read_message() { var serializer = new TestMessageSerializer(new[] { typeof(SerializerTest1), typeof(SerializerTest2), }); var msg = new SerializerTest1() { Name = "test name" }; var stream = new MemoryStream(); serializer.WriteMessage(msg, msg.GetType(), stream); stream.Seek(0, SeekOrigin.Begin); var readedMessage = serializer.ReadMessage(stream); Assert.AreEqual(typeof(SerializerTest1), readedMessage.GetType()); Assert.AreEqual("test name", (readedMessage as SerializerTest1).Name); }
public void when_write_and_read_message() { var serializer = new TestMessageSerializer(new[] { typeof(SerializerTest1), typeof(SerializerTest2), }); var msg = new SerializerTest1() { Name = "test name" }; var stream = new MemoryStream(); serializer.WriteMessage(msg, msg.GetType(), stream); stream.Seek(0, SeekOrigin.Begin); var readedMessage = serializer.ReadMessage(stream); Assert.AreEqual(typeof(SerializerTest1), readedMessage.GetType()); Assert.AreEqual("test name", (readedMessage as SerializerTest1).Name); }
public void when_write_and_read_attributes_and_messages() { var serializer = new TestMessageSerializer(new[] { typeof(SerializerTest1), typeof(SerializerTest2), }); var msg = new SerializerTest1() { Name = "test name" }; var stream = new MemoryStream(); serializer.WriteAttributes(new List<MessageAttribute> { new MessageAttribute("attr1", "val1"), new MessageAttribute("attr2", "val2") }, stream); serializer.WriteMessage(msg, msg.GetType(), stream); stream.Seek(0, SeekOrigin.Begin); var readedAttributes = serializer.ReadAttributes(stream); var readedMessage = 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), readedMessage.GetType()); Assert.AreEqual("test name", (readedMessage as SerializerTest1).Name); }
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); }