public void when_write_and_read_envelope() { var serializer = new TestMessageSerializer(new[] { typeof(SerializerTest1), typeof(SerializerTest2), }); var streamer = new EnvelopeStreamer(serializer); var date = DateTime.UtcNow; var savedBytes = streamer.SaveEnvelopeData(new ImmutableEnvelope("EnvId", date, new SerializerTest1 { Name = "Test1" }, new[] { new MessageAttribute("key1", "val1"), new MessageAttribute("key2", "val2"), })); var envelope = streamer.ReadAsEnvelopeData(savedBytes); Assert.AreEqual("EnvId", envelope.EnvelopeId); Assert.AreEqual(date, envelope.CreatedUtc); Assert.AreEqual(2, envelope.Attributes.Count); Assert.AreEqual("key1", envelope.Attributes.ToArray()[0].Key); Assert.AreEqual("val1", envelope.Attributes.ToArray()[0].Value); Assert.AreEqual("key2", envelope.Attributes.ToArray()[1].Key); Assert.AreEqual("val2", envelope.Attributes.ToArray()[1].Value); Assert.AreEqual(typeof(SerializerTest1), envelope.Message.GetType()); Assert.AreEqual("Test1", (envelope.Message 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); }
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 create_MessageSender() { var path = Path.Combine(Path.GetTempPath(), "lokad-cqrs-test", Guid.NewGuid().ToString()); var config = FileStorage.CreateConfig(new DirectoryInfo(path)); var serializer = new TestMessageSerializer(new[] { typeof(SerializerTest1), typeof(SerializerTest2), }); var streamer = new EnvelopeStreamer(serializer); var sender = config.CreateMessageSender(streamer, "QueueName"); Assert.IsNotNull(sender); }
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_send_message() { var serializer = new TestMessageSerializer(new[] { typeof(SerializerTest1), typeof(SerializerTest2), }); var streamer = new EnvelopeStreamer(serializer); var queueWriter = new FileQueueWriter(new DirectoryInfo(_path), "test"); var sender = new MessageSender(streamer, queueWriter); sender.Send(new SerializerTest1("Name1"), "EnvId", new[] { new MessageAttribute("key1", "val1"), new MessageAttribute("key2", "val2"), }); sender.Send(new SerializerTest1("Name1"), "EnvId"); Assert.AreEqual(2, Directory.GetFiles(_path).Length); }
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() { var serializer = new TestMessageSerializer(new[] { typeof(SerializerTest1), typeof(SerializerTest2), }); var stream = new MemoryStream(); serializer.WriteAttributes(new List<MessageAttribute> { new MessageAttribute("attr1", "val1"), new MessageAttribute("attr2", "val2") }, stream); stream.Seek(0, SeekOrigin.Begin); var readedAttributes = serializer.ReadAttributes(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); }
public void when_write_and_read_attributes() { var serializer = new TestMessageSerializer(new[] { typeof(SerializerTest1), typeof(SerializerTest2), }); var stream = new MemoryStream(); serializer.WriteAttributes(new List <MessageAttribute> { new MessageAttribute("attr1", "val1"), new MessageAttribute("attr2", "val2") }, stream); stream.Seek(0, SeekOrigin.Begin); var readedAttributes = serializer.ReadAttributes(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); }
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); }