Exemplo n.º 1
0
        public void TestArrayOfObjectsNullablesNull()
        {
            var service = this.GetService();

            var item = new MyItemNullables();

            var item2 = new MyItemNullables();

            var xmlArray = new XmlArray("MyItems")
                           .Add(new XmlObject("MyItem")
                                .AddNullable("MyGuid", item.MyGuid)
                                .AddNullable("MyInt", item.MyInt)
                                .AddNullable("MyDouble", item.MyDouble)
                                .AddString("MyString", item.MyString)
                                .AddNullable("MyEnumValue", item.MyEnumValue)
                                .AddNullable("MyDate", item.MyDate)
                                .AddObject("MyObj", XmlValue.CreateObject("MyObj").SetNil())
                                .AddArray("MyList", XmlValue.CreateArray("MyList").SetNil())
                                .AddArray("MyArray", XmlValue.CreateArray("MyArray").SetNil()))
                           .Add(new XmlObject("MyItem")
                                .AddNullable("MyGuid", item2.MyGuid)
                                .AddNullable("MyInt", item2.MyInt)
                                .AddNullable("MyDouble", item2.MyDouble)
                                .AddString("MyString", item2.MyString)
                                .AddNullable("MyEnumValue", item2.MyEnumValue)
                                .AddNullable("MyDate", item2.MyDate)
                                .AddObject("MyObj", XmlValue.CreateObject("MyObj").SetNil())
                                .AddArray("MyList", XmlValue.CreateArray("MyList").SetNil())
                                .AddArray("MyArray", XmlValue.CreateArray("MyArray").SetNil()));

            var result = service.GetRoot(xmlArray);

            Assert.AreEqual("<MyItems xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><MyItem><MyGuid xsi:nil=\"true\" /><MyInt xsi:nil=\"true\" /><MyDouble xsi:nil=\"true\" /><MyString xsi:nil=\"true\" /><MyEnumValue xsi:nil=\"true\" /><MyDate xsi:nil=\"true\" /><MyObj xsi:nil=\"true\" /><MyList xsi:nil=\"true\" /><MyArray xsi:nil=\"true\" /></MyItem><MyItem><MyGuid xsi:nil=\"true\" /><MyInt xsi:nil=\"true\" /><MyDouble xsi:nil=\"true\" /><MyString xsi:nil=\"true\" /><MyEnumValue xsi:nil=\"true\" /><MyDate xsi:nil=\"true\" /><MyObj xsi:nil=\"true\" /><MyList xsi:nil=\"true\" /><MyArray xsi:nil=\"true\" /></MyItem></MyItems>", result);
        }
Exemplo n.º 2
0
        public void TestCreateObject()
        {
            var result = XmlValue.CreateObject("myitem")
                         .AddString("mystring", "my value")
                         .AddNumber("mynumber", 10)
                         .AddBool("mybool", true)
                         .AddNullable <int?>("mynullable", 100);

            Assert.AreEqual(XmlValueType.Object, result.ValueType);
            Assert.AreEqual("myitem", result.NodeName);

            Assert.IsFalse(result.HasNils);

            Assert.AreEqual(XmlValueType.String, result.Values["mystring"].ValueType);
            Assert.AreEqual("my value", ((XmlString)result.Values["mystring"]).Value);

            Assert.AreEqual(XmlValueType.Number, result.Values["mynumber"].ValueType);
            Assert.AreEqual(10, ((XmlNumber)result.Values["mynumber"]).Value);

            Assert.AreEqual(XmlValueType.Bool, result.Values["mybool"].ValueType);
            Assert.AreEqual(true, ((XmlBool)result.Values["mybool"]).Value);

            Assert.AreEqual(XmlValueType.Nullable, result.Values["mynullable"].ValueType);
            Assert.AreEqual(100, ((XmlNullable)result.Values["mynullable"]).Value);
        }
Exemplo n.º 3
0
        public void TestCreateArray_WithObject()
        {
            var result = XmlValue.CreateArray("Items")
                         .Add(XmlValue.CreateObject("Obj").AddString("MyString", "my value"));

            Assert.AreEqual(XmlValueType.Array, result.ValueType);

            Assert.AreEqual(XmlValueType.Object, result.Values[0].ValueType);

            Assert.AreEqual(XmlValueType.String, ((XmlObject)result.Values[0]).Values["MyString"].ValueType);
            Assert.AreEqual("my value", ((XmlString)((XmlObject)result.Values[0]).Values["MyString"]).Value);
        }
Exemplo n.º 4
0
        public void TestCreateObject_WithArrayNull_SetHasNilsTrue()
        {
            var result = XmlValue.CreateObject("MyItem");

            result.AddArray("MyArray1", XmlValue.CreateArray("MyArray1"));

            Assert.IsFalse(result.HasNils);

            result.AddArray("MyArray2", XmlValue.CreateArray("MyArray2").SetNil());

            Assert.IsTrue(result.HasNils);
        }
Exemplo n.º 5
0
        public void TestCreateObject_WithNullableNull_SetHasNilsTrue()
        {
            var result = XmlValue.CreateObject("MyItem");

            result.AddNullable <int?>("MyNullable1", 10);

            Assert.IsFalse(result.HasNils);

            result.AddNullable <int?>("MyNullable2", null);

            Assert.IsTrue(result.HasNils);
        }
Exemplo n.º 6
0
        public void TestCreateObject_WithStringNull_SetHasNilsTrue()
        {
            var result = XmlValue.CreateObject("MyItem");

            result.AddString("MyString1", "My Value 1");

            Assert.IsFalse(result.HasNils);

            result.AddString("MyString2", null);

            Assert.IsTrue(result.HasNils);
        }
Exemplo n.º 7
0
        public void TestCompleteObject()
        {
            var service = this.GetService();

            var item = new MyItem
            {
                MyGuid      = new Guid("11ba7957-5afb-4b59-9d9b-c06a18cda5c2"),
                MyInt       = 1,
                MyDouble    = 1.5,
                MyString    = "my value",
                MyBool      = true,
                MyEnumValue = MyEnum.Other,
                MyDate      = new DateTime(1990, 12, 12),
                MyObj       = new MyInnerItem {
                    MyInnerString = "my inner value"
                },
                MyList = new List <string> {
                    "a", "b"
                },
                MyArray = new string[] { "y", "z" }
            };

            var xmlValue = new XmlObject("MyItem")
                           .AddString("MyGuid", item.MyGuid.ToString())
                           .AddNumber("MyInt", item.MyInt)
                           .AddNumber("MyDouble", item.MyDouble)
                           .AddBool("MyBool", item.MyBool)
                           .AddString("MyString", item.MyString)
                           .AddString("MyEnumValue", item.MyEnumValue.ToString())
                           .AddString("MyDate", item.MyDate.ToString())
                           .AddObject("MyObj", XmlValue.CreateObject("MyObj").AddString("MyInnerString", "my inner value"))
                           .AddArray("MyList", XmlValue.CreateArray("MyList").Add(new XmlString("String", "a")).Add(new XmlString("String", "b")))
                           .AddArray("MyArray", XmlValue.CreateArray("MyArray").Add(new XmlString("String", "y")).Add(new XmlString("String", "z")));

            var result = service.Resolve <MyItem>(xmlValue);

            Assert.IsNotNull(result);
            Assert.AreEqual(new Guid("11ba7957-5afb-4b59-9d9b-c06a18cda5c2"), result.MyGuid);
            Assert.AreEqual(1, result.MyInt);
            Assert.AreEqual(1.5, result.MyDouble);
            Assert.AreEqual(true, result.MyBool);
            Assert.AreEqual(MyEnum.Other, result.MyEnumValue);
            Assert.AreEqual(new DateTime(1990, 12, 12), result.MyDate);
            Assert.AreEqual("my inner value", result.MyObj.MyInnerString);
            Assert.AreEqual(2, result.MyList.Count);
            Assert.AreEqual("a", result.MyList[0]);
            Assert.AreEqual("b", result.MyList[1]);
            Assert.AreEqual(2, result.MyArray.Length);
            Assert.AreEqual("y", result.MyArray[0]);
            Assert.AreEqual("z", result.MyArray[1]);
        }
Exemplo n.º 8
0
        public void TestCreateObjectNil()
        {
            var result = XmlValue.CreateObject("myitem");

            Assert.AreEqual(XmlValueType.Object, result.ValueType);
            Assert.IsFalse(result.IsNil);

            var result2 = XmlValue.CreateObject("myitem");

            result2.SetNil();

            Assert.AreEqual(XmlValueType.Object, result2.ValueType);
            Assert.IsTrue(result2.IsNil);
        }
Exemplo n.º 9
0
        public void TestCreateObject_WithNullableNull()
        {
            var result = XmlValue.CreateObject("myitem")
                         .AddNullable <int?>("mynullable", null);

            Assert.AreEqual(XmlValueType.Object, result.ValueType);
            Assert.AreEqual(true, result.HasNils);

            Assert.IsTrue(result.HasNils);

            Assert.AreEqual(XmlValueType.Nullable, result.Values["mynullable"].ValueType);
            Assert.AreEqual(null, ((XmlNullable)result.Values["mynullable"]).Value);
            Assert.AreEqual(true, ((XmlNullable)result.Values["mynullable"]).IsNil);
        }
Exemplo n.º 10
0
        public void TestCreateObject_WithInnerObject()
        {
            var result = XmlValue.CreateObject("myitem")
                         .AddString("mystring", "my value")
                         .AddObject("myobj", XmlValue.CreateObject("obj").AddString("key", "string value"));

            Assert.AreEqual(XmlValueType.Object, result.ValueType);

            Assert.AreEqual("my value", ((XmlString)result.Values["mystring"]).Value);
            Assert.AreEqual(XmlValueType.String, result.Values["mystring"].ValueType);

            Assert.AreEqual(XmlValueType.Object, result.Values["myobj"].ValueType);
            Assert.AreEqual(XmlValueType.String, ((XmlObject)result.Values["myobj"]).Values["key"].ValueType);
            Assert.AreEqual("string value", ((XmlString)((XmlObject)result.Values["myobj"]).Values["key"]).Value);
        }
Exemplo n.º 11
0
        public void TestCreateObject_WithSameName_Fail()
        {
            bool failed = false;

            try
            {
                var result = XmlValue.CreateObject("item")
                             .AddString("myvalue", "my value")
                             .AddNumber("myvalue", 10);
            }
            catch (Exception)
            {
                failed = true;
            }
            Assert.IsTrue(failed);
        }
Exemplo n.º 12
0
        public void TestCreateObject_WithInnerArray()
        {
            var result = XmlValue.CreateObject("myitem")
                         .AddString("mystring", "my value")
                         .AddArray("myarray", XmlValue.CreateArray("items").Add(new XmlString("InnerString", "a")).Add(new XmlString("InnerString", "b")));

            Assert.AreEqual(XmlValueType.Object, result.ValueType);

            Assert.AreEqual("my value", ((XmlString)result.Values["mystring"]).Value);
            Assert.AreEqual(XmlValueType.String, result.Values["mystring"].ValueType);

            Assert.AreEqual(XmlValueType.Array, result.Values["myarray"].ValueType);

            Assert.AreEqual(XmlValueType.String, ((XmlArray)result.Values["myarray"]).Values[0].ValueType);
            Assert.AreEqual("a", ((XmlString)((XmlArray)result.Values["myarray"]).Values[0]).Value);

            Assert.AreEqual(XmlValueType.String, ((XmlArray)result.Values["myarray"]).Values[1].ValueType);
            Assert.AreEqual("b", ((XmlString)((XmlArray)result.Values["myarray"]).Values[1]).Value);
        }
Exemplo n.º 13
0
        public void TestObjectWithNullablesNull()
        {
            var service = this.GetService();

            var item = new MyItemNullables();

            var xmlValue = new XmlObject("MyItem")
                           .AddNullable <Guid?>("MyGuid", null)
                           .AddNullable <int?>("MyInt", null)
                           .AddNullable <double?>("MyDouble", null)
                           .AddString("MyString", null)
                           .AddNullable <MyEnum?>("MyEnumValue", null)
                           .AddNullable <DateTime?>("MyDate", null)
                           .AddObject("MyObj", XmlValue.CreateObject("MyObj").SetNil())
                           .AddArray("MyList", XmlValue.CreateArray("MyList").SetNil())
                           .AddArray("MyArray", XmlValue.CreateArray("MyArray").SetNil());

            var result = service.GetRoot(xmlValue);

            Assert.AreEqual("<MyItem xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><MyGuid xsi:nil=\"true\" /><MyInt xsi:nil=\"true\" /><MyDouble xsi:nil=\"true\" /><MyString xsi:nil=\"true\" /><MyEnumValue xsi:nil=\"true\" /><MyDate xsi:nil=\"true\" /><MyObj xsi:nil=\"true\" /><MyList xsi:nil=\"true\" /><MyArray xsi:nil=\"true\" /></MyItem>", result);
        }
Exemplo n.º 14
0
        public void TestObjectWithNullables()
        {
            var service = this.GetService();

            var item = new MyItemNullables
            {
                MyGuid      = new Guid("11ba7957-5afb-4b59-9d9b-c06a18cda5c2"),
                MyInt       = 1,
                MyDouble    = 1.5,
                MyString    = "my value",
                MyBool      = true,
                MyEnumValue = MyEnum.Other,
                MyDate      = new DateTime(1990, 12, 12),
                MyObj       = new MyInnerItem {
                    MyInnerString = "my inner value"
                },
                MyList = new List <string> {
                    "a", "b"
                },
                MyArray = new string[] { "y", "z" }
            };

            var xmlValue = new XmlObject("MyItem")
                           .AddNullable("MyGuid", item.MyGuid)
                           .AddNullable("MyInt", item.MyInt)
                           .AddNullable("MyDouble", item.MyDouble)
                           .AddString("MyString", item.MyString)
                           .AddNullable("MyEnumValue", item.MyEnumValue)
                           .AddNullable("MyDate", item.MyDate)
                           .AddObject("MyObj", XmlValue.CreateObject("MyObj").AddString("MyInnerString", "my inner value"))
                           .AddArray("MyList", XmlValue.CreateArray("MyList").Add(new XmlString("String", "a")).Add(new XmlString("String", "b")))
                           .AddArray("MyArray", XmlValue.CreateArray("MyArray").Add(new XmlString("String", "y")).Add(new XmlString("String", "z")));

            var result = service.GetRoot(xmlValue);

            Assert.AreEqual("<MyItem><MyGuid>11ba7957-5afb-4b59-9d9b-c06a18cda5c2</MyGuid><MyInt>1</MyInt><MyDouble>1.5</MyDouble><MyString>my value</MyString><MyEnumValue>Other</MyEnumValue><MyDate>12/12/1990 00:00:00</MyDate><MyObj><MyInnerString>my inner value</MyInnerString></MyObj><MyList><String>a</String><String>b</String></MyList><MyArray><String>y</String><String>z</String></MyArray></MyItem>", result);
        }
Exemplo n.º 15
0
        public void TestArrayOfObjectsNullables()
        {
            var service = this.GetService();

            var item = new MyItemNullables
            {
                MyGuid      = new Guid("11ba7957-5afb-4b59-9d9b-c06a18cda5c2"),
                MyInt       = 1,
                MyDouble    = 1.5,
                MyString    = "my value 1",
                MyBool      = true,
                MyEnumValue = MyEnum.Other,
                MyDate      = new DateTime(1990, 12, 12),
                MyObj       = new MyInnerItem {
                    MyInnerString = "my inner value 1"
                },
                MyList = new List <string> {
                    "a1", "b1"
                },
                MyArray = new string[] { "y1", "z1" }
            };

            var item2 = new MyItemNullables
            {
                MyGuid      = new Guid("11ba7957-5afb-4b59-9d9b-c06a18cda5c3"),
                MyInt       = 2,
                MyDouble    = 2.5,
                MyString    = "my value 2",
                MyBool      = false,
                MyEnumValue = MyEnum.Default,
                MyDate      = new DateTime(1990, 10, 12),
                MyObj       = new MyInnerItem {
                    MyInnerString = "my inner value 2"
                },
                MyList = new List <string> {
                    "a2", "b2"
                },
                MyArray = new string[] { "y2", "z2" }
            };

            var xmlArray = new XmlArray("MyItems")
                           .Add(new XmlObject("MyItem")
                                .AddNullable("MyGuid", item.MyGuid)
                                .AddNullable("MyInt", item.MyInt)
                                .AddNullable("MyDouble", item.MyDouble)
                                .AddString("MyString", item.MyString)
                                .AddNullable("MyEnumValue", item.MyEnumValue)
                                .AddNullable("MyDate", item.MyDate)
                                .AddObject("MyObj", XmlValue.CreateObject("MyObj").AddString("MyInnerString", "my inner value 1"))
                                .AddArray("MyList", XmlValue.CreateArray("MyList").Add(new XmlString("String", item.MyList[0])).Add(new XmlString("String", item.MyList[1])))
                                .AddArray("MyArray", XmlValue.CreateArray("MyArray").Add(new XmlString("String", item.MyArray[0])).Add(new XmlString("String", item.MyArray[1]))))
                           .Add(new XmlObject("MyItem")
                                .AddNullable("MyGuid", item2.MyGuid)
                                .AddNullable("MyInt", item2.MyInt)
                                .AddNullable("MyDouble", item2.MyDouble)
                                .AddString("MyString", item2.MyString)
                                .AddNullable("MyEnumValue", item2.MyEnumValue)
                                .AddNullable("MyDate", item2.MyDate)
                                .AddObject("MyObj", XmlValue.CreateObject("MyObj").AddString("MyInnerString", "my inner value 2"))
                                .AddArray("MyList", XmlValue.CreateArray("MyList").Add(new XmlString("String", item2.MyList[0])).Add(new XmlString("String", item2.MyList[0])))
                                .AddArray("MyArray", XmlValue.CreateArray("MyArray").Add(new XmlString("String", item2.MyArray[0])).Add(new XmlString("String", item2.MyArray[1]))));

            var result = service.GetRoot(xmlArray);

            Assert.AreEqual("<MyItems><MyItem><MyGuid>11ba7957-5afb-4b59-9d9b-c06a18cda5c2</MyGuid><MyInt>1</MyInt><MyDouble>1.5</MyDouble><MyString>my value 1</MyString><MyEnumValue>Other</MyEnumValue><MyDate>12/12/1990 00:00:00</MyDate><MyObj><MyInnerString>my inner value 1</MyInnerString></MyObj><MyList><String>a1</String><String>b1</String></MyList><MyArray><String>y1</String><String>z1</String></MyArray></MyItem><MyItem><MyGuid>11ba7957-5afb-4b59-9d9b-c06a18cda5c3</MyGuid><MyInt>2</MyInt><MyDouble>2.5</MyDouble><MyString>my value 2</MyString><MyEnumValue>Default</MyEnumValue><MyDate>12/10/1990 00:00:00</MyDate><MyObj><MyInnerString>my inner value 2</MyInnerString></MyObj><MyList><String>a2</String><String>a2</String></MyList><MyArray><String>y2</String><String>z2</String></MyArray></MyItem></MyItems>", result);
        }
Exemplo n.º 16
0
        public void TestArrayOfObjects()
        {
            var service = this.GetService();

            var item = new MyItem
            {
                MyGuid      = new Guid("11ba7957-5afb-4b59-9d9b-c06a18cda5c2"),
                MyInt       = 1,
                MyDouble    = 1.5,
                MyString    = "my value 1",
                MyBool      = true,
                MyEnumValue = MyEnum.Other,
                MyDate      = new DateTime(1990, 12, 12),
                MyObj       = new MyInnerItem {
                    MyInnerString = "my inner value 1"
                },
                MyList = new List <string> {
                    "a1", "b1"
                },
                MyArray = new string[] { "y1", "z1" }
            };

            var item2 = new MyItem
            {
                MyGuid      = new Guid("11ba7957-5afb-4b59-9d9b-c06a18cda5c3"),
                MyInt       = 2,
                MyDouble    = 2.5,
                MyString    = "my value 2",
                MyBool      = false,
                MyEnumValue = MyEnum.Default,
                MyDate      = new DateTime(1990, 10, 12),
                MyObj       = new MyInnerItem {
                    MyInnerString = "my inner value 2"
                },
                MyList = new List <string> {
                    "a2", "b2"
                },
                MyArray = new string[] { "y2", "z2" }
            };

            var xmlArray = new XmlArray("MyItems")
                           .Add(new XmlObject("MyItem")
                                .AddString("MyGuid", item.MyGuid.ToString())
                                .AddNumber("MyInt", item.MyInt)
                                .AddNumber("MyDouble", item.MyDouble)
                                .AddBool("MyBool", item.MyBool)
                                .AddString("MyString", item.MyString)
                                .AddString("MyEnumValue", item.MyEnumValue.ToString())
                                .AddString("MyDate", item.MyDate.ToString())
                                .AddObject("MyObj", XmlValue.CreateObject("MyObj").AddString("MyInnerString", "my inner value 1"))
                                .AddArray("MyList", XmlValue.CreateArray("MyList").Add(new XmlString("String", item.MyList[0])).Add(new XmlString("String", item.MyList[1])))
                                .AddArray("MyArray", XmlValue.CreateArray("MyArray").Add(new XmlString("String", item.MyArray[0])).Add(new XmlString("String", item.MyArray[1]))))
                           .Add(new XmlObject("MyItem")
                                .AddString("MyGuid", item2.MyGuid.ToString())
                                .AddNumber("MyInt", item2.MyInt)
                                .AddNumber("MyDouble", item2.MyDouble)
                                .AddString("MyString", item2.MyString)
                                .AddString("MyEnumValue", item2.MyEnumValue.ToString())
                                .AddString("MyDate", item2.MyDate.ToString())
                                .AddObject("MyObj", XmlValue.CreateObject("MyObj").AddString("MyInnerString", "my inner value 2"))
                                .AddArray("MyList", XmlValue.CreateArray("MyList").Add(new XmlString("String", item2.MyList[0])).Add(new XmlString("String", item2.MyList[1])))
                                .AddArray("MyArray", XmlValue.CreateArray("MyArray").Add(new XmlString("String", item2.MyArray[0])).Add(new XmlString("String", item2.MyArray[1]))));

            var results = service.Resolve <List <MyItem> >(xmlArray);

            var result = results[0];

            Assert.IsNotNull(result);
            Assert.AreEqual(new Guid("11ba7957-5afb-4b59-9d9b-c06a18cda5c2"), result.MyGuid);
            Assert.AreEqual(1, result.MyInt);
            Assert.AreEqual(1.5, result.MyDouble);
            Assert.AreEqual("my value 1", result.MyString);
            Assert.AreEqual(true, result.MyBool);
            Assert.AreEqual(MyEnum.Other, result.MyEnumValue);
            Assert.AreEqual(new DateTime(1990, 12, 12), result.MyDate);
            Assert.AreEqual("my inner value 1", result.MyObj.MyInnerString);
            Assert.AreEqual(2, result.MyList.Count);
            Assert.AreEqual("a1", result.MyList[0]);
            Assert.AreEqual("b1", result.MyList[1]);
            Assert.AreEqual(2, result.MyArray.Length);
            Assert.AreEqual("y1", result.MyArray[0]);
            Assert.AreEqual("z1", result.MyArray[1]);

            var result2 = results[1];

            Assert.IsNotNull(result2);
            Assert.AreEqual(new Guid("11ba7957-5afb-4b59-9d9b-c06a18cda5c3"), result2.MyGuid);
            Assert.AreEqual(2, result2.MyInt);
            Assert.AreEqual(2.5, result2.MyDouble);
            Assert.AreEqual("my value 2", result2.MyString);
            Assert.AreEqual(false, result2.MyBool);
            Assert.AreEqual(MyEnum.Default, result2.MyEnumValue);
            Assert.AreEqual(new DateTime(1990, 10, 12), result2.MyDate);
            Assert.AreEqual("my inner value 2", result2.MyObj.MyInnerString);
            Assert.AreEqual(2, result2.MyList.Count);
            Assert.AreEqual("a2", result2.MyList[0]);
            Assert.AreEqual("b2", result2.MyList[1]);
            Assert.AreEqual(2, result2.MyArray.Length);
            Assert.AreEqual("y2", result2.MyArray[0]);
            Assert.AreEqual("z2", result2.MyArray[1]);
        }