public void Can_serialize_and_deserialize_byte_array() { var serializer = new XmlMessageSerializer(new DefaultReflection(), new CastleServiceLocator(new WindsorContainer())); 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_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_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_primitive() { long ticks = DateTime.Now.Ticks; var serializer = new XmlMessageSerializer(new DefaultReflection(), new CastleServiceLocator(new WindsorContainer())); 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 Can_roundtrip() { var serializer = new XmlMessageSerializer(new DefaultReflection(),new DefaultKernel()); var stream = new MemoryStream(); serializer.Serialize(new object[] {new Foo {Name = "abc"}}, stream); stream.Position = 0; var foo = (Foo)serializer.Deserialize(stream)[0]; Assert.Equal("abc", foo.Name); Assert.Equal("ABC", foo.UName); }
public void Roundtrip_with_datetime_should_preserved_DateTimeKind(DateTimeKind kind) { var serializer = new XmlMessageSerializer(new DefaultReflection(), new CastleServiceLocator(new WindsorContainer())); var stream = new MemoryStream(); var date = new DateTime(DateTime.Now.Ticks, kind); serializer.Serialize(new object[] { new Bar { Date = date } }, stream); stream.Position = 0; var bar = (Bar)serializer.Deserialize(stream)[0]; Assert.Equal(date, bar.Date); Assert.Equal(kind, bar.Date.Kind); }
public void Can_serialize_and_deserialize_array() { var serializer = new XmlMessageSerializer(new DefaultReflection(), new DefaultKernel()); var stream = new MemoryStream(); serializer.Serialize(new object[] { new ClassWithObjectArray { Items = new object[] {new OrderLine {Product = "ayende"}} } }, stream); stream.Position = 0; var actual = (ClassWithObjectArray) serializer.Deserialize(stream)[0]; Assert.Equal("ayende", ((OrderLine)actual.Items[0]).Product); }
public void Can_use_dictionaries_initialized() { var serializer = new XmlMessageSerializer(new DefaultReflection(), new CastleServiceLocator(new WindsorContainer())); var stream = new MemoryStream(); serializer.Serialize(new object[] { new ItemWithInitDictionary { Name = "abc", Arguments = new Dictionary<string, string> { {"abc","cdef"} }} }, stream); stream.Position = 0; var foo = (ItemWithInitDictionary)serializer.Deserialize(stream)[0]; Assert.Equal("abc", foo.Name); Assert.Equal("cdef", foo.Arguments["abc"]); }
public void Can_deserialize_complex_object_graph() { var serializer = new XmlMessageSerializer(new DefaultReflection(), new DefaultKernel()); var stream = new MemoryStream(); serializer.Serialize(new[] {sample}, stream); stream.Position = 0; var order = (Order) serializer.Deserialize(stream)[0]; Assert.Equal(sample.Url, order.Url); Assert.Equal(sample.At, order.At); Assert.Equal(sample.Count, order.Count); Assert.Equal(sample.OrderId, order.OrderId); Assert.Equal(sample.TimeToDelivery, order.TimeToDelivery); Assert.Equal(2, order.OrderLines.Length); Assert.Equal(sample.OrderLines[0].Product, order.OrderLines[0].Product); Assert.Equal(sample.OrderLines[1].Product, order.OrderLines[1].Product); }
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 DefaultKernel()); 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_serialize_and_deserialize_DateTimeOffset() { var value = DateTimeOffset.Now; var serializer = new XmlMessageSerializer(new DefaultReflection(), new CastleServiceLocator(new WindsorContainer())); var stream = new MemoryStream(); serializer.Serialize(new object[] { value }, stream); stream.Position = 0; var actual = (DateTimeOffset)serializer.Deserialize(stream)[0]; Assert.Equal(value, actual); }
public void Can_serialize_and_deserialize_array_with_null_item() { var serializer = new XmlMessageSerializer(new DefaultReflection(), new CastleServiceLocator(new WindsorContainer())); var stream = new MemoryStream(); serializer.Serialize(new object[] { new ClassWithObjectArray { Items = new object[] {new OrderLine {Product = "ayende"}, null, new OrderLine {Product = "rahien"}} } }, stream); stream.Position = 0; var actual = (ClassWithObjectArray)serializer.Deserialize(stream)[0]; Assert.Equal(3, actual.Items.Length); Assert.Equal("ayende", ((OrderLine)actual.Items[0]).Product); Assert.Null(actual.Items[1]); Assert.Equal("rahien", ((OrderLine)actual.Items[2]).Product); }
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); }