Exemplo n.º 1
0
        public void CanSerializeNullableArrayWithNullString()
        {
            var message = new MessageWithNullableArray
            {
                SagaId   = Guid.Empty,
                SomeInts = new int?[] { null }
            };

            using (var stream = new MemoryStream())
            {
                SerializerFactory.Create <MessageWithNullableArray>().Serialize(message, stream);
                stream.Position = 0;
                var reader = new StreamReader(stream);
                var xml    = reader.ReadToEnd().Replace("\r\n", "\n").Replace("\n", "\r\n");

                Assert.AreEqual(@"<?xml version=""1.0"" ?>
<MessageWithNullableArray xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns=""http://tempuri.net/NServiceBus.Serializers.XML.Test"">
<SagaId>00000000-0000-0000-0000-000000000000</SagaId>
<SomeInts>
<NullableOfInt32>
null</NullableOfInt32>
</SomeInts>
</MessageWithNullableArray>
", xml);
            }
        }
Exemplo n.º 2
0
        public void CanSerializeMessageWithNullableArray()
        {
            // Issue https://github.com/Particular/NServiceBus/issues/2706
            var message = new MessageWithNullableArray
            {
                SomeInts = new int?[] { null, 1, null, 3, null }
            };

            var result = ExecuteSerializer.ForMessage <MessageWithNullableArray>(message);

            Assert.IsNull(result.SomeInts[0]);
            Assert.AreEqual(1, result.SomeInts[1]);
            Assert.IsNull(result.SomeInts[2]);
            Assert.AreEqual(3, result.SomeInts[3]);
            Assert.IsNull(result.SomeInts[4]);
        }
        public void CanSerializeMessageWithNullableArray()
        {
            // Issue https://github.com/Particular/NServiceBus/issues/2706

            var message = new MessageWithNullableArray
            {
                SomeInts = new int?[] { null, 1, null, 3, null }
            };

            var result = ExecuteSerializer.ForMessage<MessageWithNullableArray>(message);

            Assert.IsNull(result.SomeInts[0]);
            Assert.AreEqual(1, result.SomeInts[1]);
            Assert.IsNull(result.SomeInts[2]);
            Assert.AreEqual(3, result.SomeInts[3]);
            Assert.IsNull(result.SomeInts[4]);
        }
        public void CanSerializeNullableArrayWithNullString()
        {
            var message = new MessageWithNullableArray
            {
                SagaId = Guid.Empty,
                SomeInts = new int?[] { null }
            };

            using (var stream = new MemoryStream())
            {
                SerializerFactory.Create<MessageWithNullableArray>().Serialize(message, stream);
                stream.Position = 0;
                var reader = new StreamReader(stream);
                var xml = reader.ReadToEnd();

                var expected = XDocument.Parse(@"<?xml version=""1.0"" ?>
<MessageWithNullableArray xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns=""http://tempuri.net/NServiceBus.Serializers.XML.Test"">
<SagaId>00000000-0000-0000-0000-000000000000</SagaId>
<SomeInts>
<NullableOfInt32>null</NullableOfInt32>
</SomeInts>
</MessageWithNullableArray>
");
                var actual = XDocument.Parse(xml);

                Assert.AreEqual(expected.ToString(), actual.ToString());
            }
        }