Exemplo n.º 1
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]);
        }
Exemplo n.º 2
0
        public void Messages_with_generic_properties_closing_nullables_should_be_supported()
        {
            var theTime = DateTime.Now;

            var result = ExecuteSerializer.ForMessage <MessageWithGenericPropClosingNullable>(
                m =>
            {
                m.GenericNullable = new GenericPropertyWithNullable <DateTime?>
                {
                    TheType = theTime
                };
                m.Whatever = "fdsfsdfsd";
            });

            Assert.IsNotNull(result.GenericNullable.TheType == theTime);
        }
Exemplo n.º 3
0
        public void Messages_with_polymorphic_properties_should_be_supported()
        {
            var message = new PolyMessage
            {
                BaseType = new ChildOfBase
                {
                    BaseTypeProp = "base",
                    ChildProp    = "Child"
                }
            };

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

            Assert.AreEqual(message.BaseType.BaseTypeProp, result.BaseType.BaseTypeProp);

            Assert.AreEqual(((ChildOfBase)message.BaseType).ChildProp, ((ChildOfBase)result.BaseType).ChildProp);
        }
Exemplo n.º 4
0
        public void System_classes_with_non_default_constructors_should_be_supported()
        {
            var message = new MailMessage("*****@*****.**", "*****@*****.**")
            {
                Subject = "Testing the NSB email support",
                Body    = "Hello"
            };

            var result = ExecuteSerializer.ForMessage <MessageWithSystemClassAsProperty>(
                m => { m.MailMessage = message; });

            Assert.IsNotNull(result.MailMessage);
            Assert.AreEqual("*****@*****.**", result.MailMessage.From.Address);
            Assert.AreEqual(message.To.First(), result.MailMessage.To.First());
            Assert.AreEqual(message.BodyEncoding.CodePage, result.MailMessage.BodyEncoding.CodePage);
            Assert.AreEqual(message.BodyEncoding.EncoderFallback.MaxCharCount, result.MailMessage.BodyEncoding.EncoderFallback.MaxCharCount);
        }
Exemplo n.º 5
0
        public void When_Using_Property_WithXContainerAssignable_should_preserve_xml()
        {
            const string XmlElement  = "<SomeClass xmlns=\"http://nservicebus.com\"><SomeProperty value=\"Bar\" /></SomeClass>";
            const string XmlDocument = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + XmlElement;

            var messageWithXDocument = new MessageWithXDocument {
                Document = XDocument.Load(new StringReader(XmlDocument))
            };
            var messageWithXElement = new MessageWithXElement {
                Document = XElement.Load(new StringReader(XmlElement))
            };

            var resultXDocument = ExecuteSerializer.ForMessage <MessageWithXDocument>(messageWithXDocument);
            var resultXElement  = ExecuteSerializer.ForMessage <MessageWithXElement>(messageWithXElement);

            Assert.AreEqual(messageWithXDocument.Document.ToString(), resultXDocument.Document.ToString());
            Assert.AreEqual(messageWithXElement.Document.ToString(), resultXElement.Document.ToString());
        }
Exemplo n.º 6
0
        public void CanSerializeNullElements()
        {
            var message = new MessageWithEnumerableOfString
            {
                SomeStrings = new[]
                {
                    "element 1",
                    null,
                    null,
                    "element 2"
                }
            };

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

            Assert.IsNotNull(result.SomeStrings);
            Assert.AreEqual(4, result.SomeStrings.Count());
        }
Exemplo n.º 7
0
        public void NestedObjectWithNullPropertiesShouldBeSerialized()
        {
            var result = ExecuteSerializer.ForMessage <MessageWithNestedObject>(m => { m.NestedObject = new MessageWithNullProperty(); });

            Assert.IsNotNull(result.NestedObject);
        }
Exemplo n.º 8
0
        public void Should_deserialize_list()
        {
            var expected = new MessageWithLists
            {
                Bools = new List <bool> {
                    true, false
                },
                Chars = new List <char> {
                    'a', 'b', 'c', 'd', 'e', 'f'
                },
                Bytes = new List <byte> {
                    byte.MinValue, byte.MaxValue, 11, 1, 1, 0
                },
                Ints = new List <int> {
                    int.MinValue, int.MaxValue, 1, 2, 3, 4, 5, 6
                },
                Decimals =
                    new List <decimal> {
                    decimal.MinValue, decimal.MaxValue, .2m, 4m, .5m, .4234m
                },
                Doubles =
                    new List <double>
                {
                    double.MinValue, double.MaxValue, .223d, 234d, .513d, .4212334d
                },
                Floats =
                    new List <float> {
                    float.MinValue, float.MaxValue, .223f, 234f, .513f, .4212334f
                },
                Enums = new List <DateTimeStyles>
                {
                    DateTimeStyles.AdjustToUniversal,
                    DateTimeStyles.AllowLeadingWhite,
                    DateTimeStyles.AllowTrailingWhite
                },
                Longs =
                    new List <long>
                {
                    long.MaxValue, long.MinValue, 34234, 234324, 45345345, 34534534565
                },
                SBytes = new List <sbyte> {
                    sbyte.MaxValue, sbyte.MaxValue, 56, 13
                },
                Shorts = new List <short> {
                    short.MinValue, short.MaxValue, 5231, 6123
                },
                Strings = new List <string> {
                    "Key1", "Value1", "Key2", "Value2", "Key3", "Value3"
                },
                UInts = new List <uint> {
                    uint.MinValue, 23, uint.MaxValue, 34324
                },
                ULongs = new List <ulong> {
                    ulong.MinValue, ulong.MaxValue, 34324234, 3243243245
                },
                UShorts = new List <ushort> {
                    ushort.MinValue, ushort.MaxValue, 42324, 32
                }
            };

            var result = ExecuteSerializer.ForMessage <MessageWithLists>(expected);

            CollectionAssert.AreEqual(expected.Bools, result.Bools);
            CollectionAssert.AreEqual(expected.Chars, result.Chars);
            CollectionAssert.AreEqual(expected.Bytes, result.Bytes);
            CollectionAssert.AreEqual(expected.Ints, result.Ints);
            CollectionAssert.AreEqual(expected.Decimals, result.Decimals);
            CollectionAssert.AreEqual(expected.Doubles, result.Doubles);
            CollectionAssert.AreEqual(expected.Floats, result.Floats);
            CollectionAssert.AreEqual(expected.Enums, result.Enums);
            CollectionAssert.AreEqual(expected.Longs, result.Longs);
            CollectionAssert.AreEqual(expected.SBytes, result.SBytes);
            CollectionAssert.AreEqual(expected.Shorts, result.Shorts);
            CollectionAssert.AreEqual(expected.Strings, result.Strings);
            CollectionAssert.AreEqual(expected.UInts, result.UInts);
            CollectionAssert.AreEqual(expected.ULongs, result.ULongs);
            CollectionAssert.AreEqual(expected.UShorts, result.UShorts);
        }
Exemplo n.º 9
0
        public void Should_deserialize_dictionaries()
        {
            var expected = new MessageWithDictionaries
            {
                Bools = new Dictionary <bool, bool>
                {
                    { true, true },
                    { false, false }
                },
                Chars = new Dictionary <char, char>
                {
                    //{char.MinValue, char.MaxValue}, // doesn't work becayse we use UTF8
                    { 'a', 'b' },
                    { 'c', 'd' },
                    { 'e', 'f' }
                },
                Bytes = new Dictionary <byte, byte>
                {
                    { byte.MinValue, byte.MaxValue },
                    { 11, 1 },
                    { 1, 0 }
                },
                Ints = new Dictionary <int, int>
                {
                    { int.MinValue, int.MaxValue },
                    { 1, 2 },
                    { 3, 4 },
                    { 5, 6 }
                },
                Decimals = new Dictionary <decimal, decimal>
                {
                    { decimal.MinValue, decimal.MaxValue },
                    { .2m, 4m },
                    { .5m, .4234m }
                },
                Doubles = new Dictionary <double, double>
                {
                    { double.MinValue, double.MaxValue },
                    { .223d, 234d },
                    { .513d, .4212334d }
                },
                Floats = new Dictionary <float, float>
                {
                    { float.MinValue, float.MaxValue },
                    { .223f, 234f },
                    { .513f, .4212334f }
                },
                Enums = new Dictionary <DateTimeStyles, DateTimeKind>
                {
                    { DateTimeStyles.AdjustToUniversal, DateTimeKind.Local },
                    { DateTimeStyles.AllowLeadingWhite, DateTimeKind.Unspecified },
                },
                Longs = new Dictionary <long, long>
                {
                    { long.MaxValue, long.MinValue },
                    { 34234, 234324 },
                    { 45345345, 34534534565 }
                },
                SBytes = new Dictionary <sbyte, sbyte>
                {
                    { sbyte.MaxValue, sbyte.MaxValue },
                    { 56, 13 }
                },
                Shorts = new Dictionary <short, short>
                {
                    { short.MinValue, short.MaxValue },
                    { 5231, 6123 }
                },
                Strings = new Dictionary <string, string>
                {
                    { "Key1", "Value1" },
                    { "Key2", "Value2" },
                    { "Key3", "Value3" },
                },
                UInts = new Dictionary <uint, uint>
                {
                    { uint.MinValue, 23 },
                    { uint.MaxValue, 34324 }
                },
                ULongs = new Dictionary <ulong, ulong>
                {
                    { ulong.MinValue, ulong.MaxValue },
                    { 34324234, 3243243245 }
                },
                UShorts = new Dictionary <ushort, ushort>
                {
                    { ushort.MinValue, ushort.MaxValue },
                    { 42324, 32 }
                }
            };

            var result = ExecuteSerializer.ForMessage <MessageWithDictionaries>(expected);

            CollectionAssert.AreEqual(expected.Bools, result.Bools);
            CollectionAssert.AreEqual(expected.Chars, result.Chars);
            CollectionAssert.AreEqual(expected.Bytes, result.Bytes);
            CollectionAssert.AreEqual(expected.Ints, result.Ints);
            CollectionAssert.AreEqual(expected.Decimals, result.Decimals);
            CollectionAssert.AreEqual(expected.Doubles, result.Doubles);
            CollectionAssert.AreEqual(expected.Floats, result.Floats);
            CollectionAssert.AreEqual(expected.Enums, result.Enums);
            CollectionAssert.AreEqual(expected.Longs, result.Longs);
            CollectionAssert.AreEqual(expected.SBytes, result.SBytes);
            CollectionAssert.AreEqual(expected.Shorts, result.Shorts);
            CollectionAssert.AreEqual(expected.Strings, result.Strings);
            CollectionAssert.AreEqual(expected.UInts, result.UInts);
            CollectionAssert.AreEqual(expected.ULongs, result.ULongs);
            CollectionAssert.AreEqual(expected.UShorts, result.UShorts);
        }