public void The_xml_message_serializer_should_rock_the_house() { byte[] serializedMessageData; var serializer = new XmlMessageSerializer(); OutboundMessage.Set(x => { x.SetSourceAddress("msmq://localhost/queue_name"); x.SetDestinationAddress("msmq://remotehost/queue_name"); x.SetResponseAddress("msmq://localhost/response_queue"); x.SetFaultAddress("msmq://localhost/fault_queue"); x.SetRetryCount(7); }); using (MemoryStream output = new MemoryStream()) { serializer.Serialize(output, _message); serializedMessageData = output.ToArray(); Trace.WriteLine(Encoding.UTF8.GetString(serializedMessageData)); } using (MemoryStream input = new MemoryStream(serializedMessageData)) { SerializationTestMessage receivedMessage = serializer.Deserialize(input) as SerializationTestMessage; Assert.AreEqual(_message, receivedMessage); } }
private void VerifyMessageHeaderIsPassed(Action<IOutboundMessage> setHeaderAction, Action<IInboundMessageHeaders> checkHeaderAction) { byte[] data; var serializer = new XmlMessageSerializer(); OutboundMessage.Set(setHeaderAction); var message = new PingMessage(); using (MemoryStream output = new MemoryStream()) { serializer.Serialize(output, message); data = output.ToArray(); } Trace.WriteLine(OutboundMessage.Headers.MessageType); Trace.WriteLine(Encoding.UTF8.GetString(data)); using (MemoryStream input = new MemoryStream(data)) { serializer.Deserialize(input); checkHeaderAction(CurrentMessage.Headers); } }
public void Can_read_subscription_from_queue() { var serializer = new XmlMessageSerializer(new DefaultReflection(), new CastleServiceLocator(new WindsorContainer())); var msg = new Message(); serializer.Serialize(new object[] { new AddSubscription { Endpoint = TransactionalTestQueueUri, Type = typeof(TestMessage).FullName, } }, msg.BodyStream); msg.Extension = Guid.NewGuid().ToByteArray(); queue.Send(msg, MessageQueueTransactionType.None); msg = queue.Peek(TimeSpan.FromSeconds(30)); queue.MoveToSubQueue("subscriptions", msg); var subscriptionStorage = new MsmqSubscriptionStorage(new DefaultReflection(), serializer, TestQueueUri.Uri, new EndpointRouter(), new SubQueueStrategy()); subscriptionStorage.Initialize(); var uri = subscriptionStorage .GetSubscriptionsFor(typeof(TestMessage)) .Single(); Assert.Equal(TransactionalTestQueueUri.Uri, uri); }
public void Adding_then_removing_will_result_in_no_subscriptions() { var serializer = new XmlMessageSerializer(new DefaultReflection(), new DefaultKernel()); var msg = new Message(); serializer.Serialize(new object[] { new AddSubscription { Endpoint = TransactionalTestQueueUri, Type = typeof(TestMessage).FullName, } }, msg.BodyStream); msg.Extension = Guid.NewGuid().ToByteArray(); queue.Send(msg, MessageQueueTransactionType.None); msg = queue.Peek(TimeSpan.FromSeconds(30)); queue.MoveToSubQueue("subscriptions", msg); var subscriptionStorage = new MsmqSubscriptionStorage(new DefaultReflection(), serializer, TestQueueUri.Uri, new EndpointRouter(), new SubQueueStrategy()); subscriptionStorage.Initialize(); subscriptionStorage.RemoveSubscription(typeof(TestMessage).FullName, TransactionalTestQueueUri.Uri.ToString()); var uris = subscriptionStorage .GetSubscriptionsFor(typeof(TestMessage)); Assert.Equal(0, uris.Count()); }
public void Trying_to_send_more_than_256_objects_will_fail() { var serializer = new XmlMessageSerializer(new DefaultReflection(), new CastleServiceLocator(new WindsorContainer())); Assert.Throws <UnboundedResultSetException>(() => serializer.Serialize(new object[257], new MemoryStream())); }
private void VerifyMessageHeaderIsPassed(Action <IOutboundMessage> setHeaderAction, Action <IInboundMessageHeaders> checkHeaderAction) { byte[] data; var serializer = new XmlMessageSerializer(); OutboundMessage.Set(setHeaderAction); var message = new PingMessage(); using (MemoryStream output = new MemoryStream()) { serializer.Serialize(output, message); data = output.ToArray(); } Trace.WriteLine(OutboundMessage.Headers.MessageType); Trace.WriteLine(Encoding.UTF8.GetString(data)); using (MemoryStream input = new MemoryStream(data)) { serializer.Deserialize(input); checkHeaderAction(CurrentMessage.Headers); } }
public void Can_roundtrip_with_datetime_on_non_english_culture(string cultureName) { var oldCulture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = new CultureInfo(cultureName); try { var serializer = new XmlMessageSerializer(new DefaultReflection(), new CastleServiceLocator(new WindsorContainer())); var stream = new MemoryStream(); var date = DateTime.Now; serializer.Serialize(new object[] { new Bar { Date = date } }, stream); stream.Position = 0; var bar = (Bar)serializer.Deserialize(stream)[0]; Assert.Equal(date, bar.Date); } finally { Thread.CurrentThread.CurrentCulture = oldCulture; } }
public void Can_handle_dictionaries_where_values_are_objects() { var serializer = new XmlMessageSerializer(new DefaultReflection(), new CastleServiceLocator(new WindsorContainer())); var stream = new MemoryStream(); serializer.Serialize(new object[] { new ItemWithObjectDictionary() { Name = "abc", Arguments = new Dictionary <string, object> { { "abc", "cdef" }, { "def", 1 }, { "123", new Dog { Name = "Oscar" } } } } }, stream); stream.Position = 0; stream.Position = 0; var foo = (ItemWithObjectDictionary)serializer.Deserialize(stream)[0]; Assert.Equal("abc", foo.Name); Assert.Equal("cdef", foo.Arguments["abc"]); Assert.Equal(1, (int)foo.Arguments["def"]); Assert.Equal("Oscar", ((Dog)foo.Arguments["123"]).Name); }
void VerifyMessageHeaderIsPassed(Action <ISendContext <PingMessage> > setHeaderAction, Action <IConsumeContext> checkHeaderAction) { byte[] data; var serializer = new XmlMessageSerializer(); var message = new PingMessage(); using (var output = new MemoryStream()) { var sendContext = new SendContext <PingMessage>(message); setHeaderAction(sendContext); serializer.Serialize(output, sendContext); data = output.ToArray(); } //Trace.WriteLine(Encoding.UTF8.GetString(data)); using (var input = new MemoryStream(data)) { var receiveContext = ReceiveContext.FromBodyStream(input); serializer.Deserialize(receiveContext); checkHeaderAction(receiveContext); } }
public void Can_read_subscription_from_queue() { var serializer = new XmlMessageSerializer(new DefaultReflection(), new CastleServiceLocator(new WindsorContainer())); var msg = new Message(); serializer.Serialize(new object[] { new AddSubscription { Endpoint = transactionalTestQueueEndpoint, Type = typeof(TestMessage).FullName, } }, msg.BodyStream); msg.Extension = Guid.NewGuid().ToByteArray(); queue.OpenSiblngQueue(SubQueue.Subscriptions, QueueAccessMode.Send).Send(msg); var subscriptionStorage = new MsmqSubscriptionStorage(new DefaultReflection(), serializer, testQueueEndPoint.Uri, new EndpointRouter(), new FlatQueueStrategy(new EndpointRouter(), testQueueEndPoint.Uri)); subscriptionStorage.Initialize(); var uri = subscriptionStorage .GetSubscriptionsFor(typeof(TestMessage)) .Single(); Assert.Equal(transactionalTestQueueEndpoint.Uri, uri); }
public void Adding_then_removing_will_result_in_no_subscriptions() { var serializer = new XmlMessageSerializer(new DefaultReflection(), new DefaultKernel()); var msg = new Message(); serializer.Serialize(new object[] { new AddSubscription { Endpoint = transactionalTestQueueEndpoint, Type = typeof(TestMessage).FullName, } }, msg.BodyStream); msg.Extension = Guid.NewGuid().ToByteArray(); queue.OpenSiblngQueue(SubQueue.Subscriptions, QueueAccessMode.Send).Send(msg); var subscriptionStorage = new MsmqSubscriptionStorage(new DefaultReflection(), serializer, testQueueEndPoint.Uri, new EndpointRouter(), new FlatQueueStrategy(new EndpointRouter(), testQueueEndPoint.Uri)); subscriptionStorage.Initialize(); subscriptionStorage.RemoveSubscription(typeof(TestMessage).FullName, transactionalTestQueueEndpoint.Uri.ToString()); var uris = subscriptionStorage .GetSubscriptionsFor(typeof(TestMessage)); Assert.Equal(0, uris.Count()); }
public void Can_serialize_and_deserialize_byte_array() { var serializer = new XmlMessageSerializer(new DefaultReflection(), new DefaultKernel()); var stream = new MemoryStream(); serializer.Serialize(new object[] { new byte[] { 1, 2, 3, 4 } }, stream); stream.Position = 0; var actual = (byte[])serializer.Deserialize(stream)[0]; Assert.Equal(new byte[] { 1, 2, 3, 4 }, actual); }
public void Can_serialize_and_deserialize_byte_array() { var serializer = new XmlMessageSerializer(); var stream = new MemoryStream(); serializer.Serialize(new object[] { new byte[] { 1, 2, 3, 4 } }, stream); stream.Position = 0; var actual = (byte[])serializer.Deserialize(stream).As <byte[]>(); new byte[] { 1, 2, 3, 4 }.ShouldEqual(actual); }
public void Can_serialize_and_deserialize_primitive() { long ticks = DateTime.Now.Ticks; var serializer = new XmlMessageSerializer(); var stream = new MemoryStream(); serializer.Serialize(new object[] { ticks }, stream); stream.Position = 0; var actual = (long)serializer.Deserialize(stream).As <long>(); ticks.ShouldEqual(actual); }
public void Can_serialize_and_deserialize_float() { float aFloat = 1.12f; var serializer = new XmlMessageSerializer(); var stream = new MemoryStream(); serializer.Serialize(new object[] { aFloat }, stream); stream.Position = 0; var actual = (float)serializer.Deserialize(stream).As <float>(); aFloat.ShouldEqual(actual); }
public void Can_serialize_and_deserialize_double() { double aDouble = 1.12; var serializer = new XmlMessageSerializer(); var stream = new MemoryStream(); serializer.Serialize(new object[] { aDouble }, stream); stream.Position = 0; var actual = (double)serializer.Deserialize(stream).As <double>(); aDouble.ShouldEqual(actual); }
public void Can_serialize_and_deserialize_float() { float aFloat = 1.12f; var serializer = new XmlMessageSerializer(new DefaultReflection(), new CastleServiceLocator(new WindsorContainer())); var stream = new MemoryStream(); serializer.Serialize(new object[] { aFloat }, stream); stream.Position = 0; var actual = (float)serializer.Deserialize(stream)[0]; Assert.Equal(aFloat, actual); }
public void Can_serialize_and_deserialize_DateTimeOffset() { var value = DateTimeOffset.Now; var serializer = new XmlMessageSerializer(); var stream = new MemoryStream(); serializer.Serialize(new object[] { value }, stream); stream.Position = 0; var actual = (DateTimeOffset)serializer.Deserialize(stream).As <DateTimeOffset>(); value.ShouldEqual(actual); }
public void Can_serialize_and_deserialize_double() { double aDouble = 1.12; var serializer = new XmlMessageSerializer(new DefaultReflection(), new CastleServiceLocator(new WindsorContainer())); var stream = new MemoryStream(); serializer.Serialize(new object[] { aDouble }, stream); stream.Position = 0; var actual = (double)serializer.Deserialize(stream)[0]; Assert.Equal(aDouble, actual); }
public void can_serialize_and_deserialize_icpc_monitor() { var ms = new MemoryStream(); var serializer = new XmlMessageSerializer(new DefaultReflection(), new DefaultKernel()); var submission = S("testuser A AC 11"); var builder = new IcpcMonitorBuilder(contest); object monitor = builder.BuildMonitor(new[] { submission }); serializer.Serialize(new[] { monitor }, ms); ms.Position = 0; serializer.Deserialize(ms); }
public void Can_serialize_and_deserialize_DateTimeOffset() { var value = DateTimeOffset.Now; var serializer = new XmlMessageSerializer(new DefaultReflection(), new DefaultKernel()); var stream = new MemoryStream(); serializer.Serialize(new object[] { value }, stream); stream.Position = 0; var actual = (DateTimeOffset)serializer.Deserialize(stream)[0]; Assert.Equal(value, actual); }
private string GenerateXml(object message) { using (var stream = new MemoryStream()) { _tibcoMessageSerializer.Serialize(new object[] { message }, stream); //TODO: handle for json, and binary, objectMessage??? stream.Position = 0; var doc = new XmlDocument(); doc.Load(stream); return(doc.LastChild.InnerXml); } }
public void Can_serialize_and_deserialize_primitive() { long ticks = DateTime.Now.Ticks; var serializer = new XmlMessageSerializer(new DefaultReflection(), new DefaultKernel()); var stream = new MemoryStream(); serializer.Serialize(new object[] { ticks }, stream); stream.Position = 0; var actual = (long)serializer.Deserialize(stream)[0]; Assert.Equal(ticks, actual); }
public void ShouldDeserializeFromXml() { IMessageSerializer serializer = new XmlMessageSerializer(); IMessageDeserializer <TestMessageProto> deserializer = new XmlMessageDeserializer <TestMessageProto>(); var message = new TestMessageProto { Id = 123, Name = "SomeName" }; var serialize = serializer.Serialize(message); var deserialize = deserializer.Deserialize(serialize); Assert.Equal(message, deserialize); }
public void ShouldSerializeToXml() { IMessageSerializer serializer = new XmlMessageSerializer(); var message = new TestMessageProto { Id = 123, Name = "SomeName" }; var serialize = XmlSerializerDefaults.Encoding.GetString(serializer.Serialize(message)); Assert.NotNull(serialize); Assert.Contains(message.Id.ToString(), serialize); Assert.Contains(message.Name, serialize); }
public void can_round_trip_single_message() { var serializer = new XmlMessageSerializer(); var stream = new MemoryStream(); serializer.Serialize(sample, stream); stream.Position = 0; var actual = serializer.Deserialize(stream).ShouldBeOfType <Order>(); actual.OrderId.ShouldEqual(sample.OrderId); }
public void ShouldDeserializeFromXml() { IMessageSerializer serializer = new XmlMessageSerializer(); IMessageDeserializer <TestMessage> deserializer = new XmlMessageDeserializer <TestMessage>(); var message = new TestMessage { Id = 123, Name = "SomeName" }; var serialize = serializer.Serialize(message); var deserialize = deserializer.Deserialize(serialize); Assert.That(message, Is.EqualTo(deserialize)); }
public void ShouldDeserializeFromXmlAscii() { IMessageSerializer serializer = new XmlMessageSerializer(); IMessageDeserializer <TestMessageProto> deserializer = new XmlMessageDeserializer <TestMessageProto>(); var message = new TestMessageProto { Id = 123, Name = "SomeName" }; var serialize = serializer.Serialize(message); var ascii = Encoding.Convert(XmlSerializerDefaults.Encoding, Encoding.ASCII, serialize); var deserialize = deserializer.Deserialize(ascii); Assert.Equal(message, deserialize); }
public void ShouldSerializeToXml() { IMessageSerializer serializer = new XmlMessageSerializer(); var message = new TestMessage { Id = 123, Name = "SomeName" }; var serialize = XmlSerializerDefaults.Encoding.GetString(serializer.Serialize(message)); Assert.That(serialize, Is.Not.Null); Assert.That(serialize, Is.Not.Empty); Assert.That(serialize, Contains.Substring(message.Id.ToString())); Assert.That(serialize, Contains.Substring(message.Name)); }
public void Serialize_CorrectText_TextMessageCreated() { var serializer = new XmlMessageSerializer <TextMessage>(); var result = serializer.Serialize(new TextMessage { Body = "testMessage" }); var message = (TextMessage)result; var m = message.Body.Replace("\r", "") .Replace("\n", "") .Replace("> <", "><"); Assert.That(m == MessageText); }
public static TransportMessage Serialize <T>(T message) { var s = new XmlMessageSerializer(new MessageMapper()); s.Initialize(new [] { typeof(T) }); var m = EmptyTransportMessage(); using (var stream = new MemoryStream()) { s.Serialize(new object[] { message }, stream); m.Body = stream.ToArray(); } return(m); }
public void The_xml_message_serializer_should_rock_the_house() { byte[] serializedMessageData; var serializer = new XmlMessageSerializer(); OutboundMessage.Set(x => { x.SetSourceAddress("msmq://localhost/queue_name"); x.SetDestinationAddress("msmq://remotehost/queue_name"); x.SetResponseAddress("msmq://localhost/response_queue"); x.SetFaultAddress("msmq://localhost/fault_queue"); x.SetRetryCount(7); }); using (MemoryStream output = new MemoryStream()) { serializer.Serialize(output, _message); serializedMessageData = output.ToArray(); Trace.WriteLine(Encoding.UTF8.GetString(serializedMessageData)); } using (MemoryStream input = new MemoryStream(serializedMessageData)) { SerializationTestMessage receivedMessage = serializer.Deserialize(input) as SerializationTestMessage; Assert.AreEqual(_message, receivedMessage); } }
public void Just_how_fast_is_the_custom_xml_serializer() { var message = new SerializationTestMessage { DecimalValue = 123.45m, LongValue = 098123213, BoolValue = true, ByteValue = 127, IntValue = 123, DateTimeValue = new DateTime(2008, 9, 8, 7, 6, 5, 4), TimeSpanValue = 30.Seconds(), GuidValue = Guid.NewGuid(), StringValue = "Chris's Sample Code", DoubleValue = 1823.172, }; // var message = new PingMessage // { // CorrelationId = CombGuid.Generate() // }; var serializer = new XmlMessageSerializer(); for (int i = 0; i < 10; i++) { byte[] data; using (MemoryStream output = new MemoryStream()) { serializer.Serialize(output, message); data = output.ToArray(); } using (MemoryStream input = new MemoryStream(data)) { // serializer.Deserialize(input); } } Stopwatch timer = Stopwatch.StartNew(); const int iterations = 50000; for (int i = 0; i < iterations; i++) { using (MemoryStream output = new MemoryStream()) { serializer.Serialize(output, message); } } timer.Stop(); long perSecond = iterations*1000/timer.ElapsedMilliseconds; var msg = string.Format("Serialize: {0}ms, Rate: {1} m/s", timer.ElapsedMilliseconds, perSecond); Trace.WriteLine(msg); byte[] sample; using (MemoryStream output = new MemoryStream()) { serializer.Serialize(output, message); sample = output.ToArray(); } timer = Stopwatch.StartNew(); for (int i = 0; i < 50000; i++) { using (MemoryStream input = new MemoryStream(sample)) { serializer.Deserialize(input); } } timer.Stop(); perSecond = iterations*1000/timer.ElapsedMilliseconds; msg = string.Format("Deserialize: {0}ms, Rate: {1} m/s", timer.ElapsedMilliseconds, perSecond); Trace.WriteLine(msg); }