Esempio n. 1
0
        public void TestObject_WithNullablesNull()
        {
            var service = this.GetService();

            var model = new ItemNullable();

            var result = service.ToXmlValue(model);

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

            Assert.AreEqual(XmlValueType.Nullable, ((XmlObject)result).Values["MyGuid"].ValueType);
            Assert.AreEqual(null, ((XmlNullable)((XmlObject)result).Values["MyGuid"]).Value);
            Assert.AreEqual("MyGuid", ((XmlNullable)((XmlObject)result).Values["MyGuid"]).NodeName);

            Assert.AreEqual(XmlValueType.Nullable, ((XmlObject)result).Values["MyInt"].ValueType);
            Assert.AreEqual(null, ((XmlNullable)((XmlObject)result).Values["MyInt"]).Value);
            Assert.AreEqual("MyInt", ((XmlNullable)((XmlObject)result).Values["MyInt"]).NodeName);

            Assert.AreEqual(XmlValueType.Nullable, ((XmlObject)result).Values["MyDouble"].ValueType);
            Assert.AreEqual(null, ((XmlNullable)((XmlObject)result).Values["MyDouble"]).Value);
            Assert.AreEqual("MyDouble", ((XmlNullable)((XmlObject)result).Values["MyDouble"]).NodeName);

            Assert.AreEqual(XmlValueType.Nullable, ((XmlObject)result).Values["MyBool"].ValueType);
            Assert.AreEqual(null, ((XmlNullable)((XmlObject)result).Values["MyBool"]).Value);
            Assert.AreEqual("MyBool", ((XmlNullable)((XmlObject)result).Values["MyBool"]).NodeName);

            Assert.AreEqual(XmlValueType.Nullable, ((XmlObject)result).Values["MyEnum"].ValueType);
            Assert.AreEqual(null, ((XmlNullable)((XmlObject)result).Values["MyEnum"]).Value);
            Assert.AreEqual("MyEnum", ((XmlNullable)((XmlObject)result).Values["MyEnum"]).NodeName);

            Assert.AreEqual(XmlValueType.Nullable, ((XmlObject)result).Values["MyDate"].ValueType);
            Assert.AreEqual(null, ((XmlNullable)((XmlObject)result).Values["MyDate"]).Value);
            Assert.AreEqual("MyDate", ((XmlNullable)((XmlObject)result).Values["MyDate"]).NodeName);
        }
        public void TestObject_WithNullablesNull()
        {
            var service = this.GetService();

            var model = new ItemNullable();

            var result = service.ToJson(model);

            Assert.AreEqual("{\"MyGuid\":null,\"MyInt\":null,\"MyDouble\":null,\"MyBool\":null,\"MyEnum\":null,\"MyDate\":null}", result);
        }
Esempio n. 3
0
        public void TestObject_WithNullablesNotNull()
        {
            // Json nullable => value object

            var service = this.GetService();

            var model = new ItemNullable
            {
                MyGuid   = Guid.NewGuid(),
                MyInt    = 1,
                MyDouble = 1.5,
                MyBool   = true,
                MyEnum   = AssemblyEnum.Other,
                MyDate   = new DateTime(1990, 12, 12)
            };

            var result = service.ToXmlValue(model);

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

            Assert.AreEqual(XmlValueType.Nullable, ((XmlObject)result).Values["MyGuid"].ValueType);
            Assert.AreEqual(model.MyGuid, ((XmlNullable)((XmlObject)result).Values["MyGuid"]).Value);
            Assert.AreEqual("MyGuid", ((XmlNullable)((XmlObject)result).Values["MyGuid"]).NodeName);

            Assert.AreEqual(XmlValueType.Nullable, ((XmlObject)result).Values["MyInt"].ValueType);
            Assert.AreEqual(model.MyInt, ((XmlNullable)((XmlObject)result).Values["MyInt"]).Value);
            Assert.AreEqual("MyInt", ((XmlNullable)((XmlObject)result).Values["MyInt"]).NodeName);

            Assert.AreEqual(XmlValueType.Nullable, ((XmlObject)result).Values["MyDouble"].ValueType);
            Assert.AreEqual(model.MyDouble, ((XmlNullable)((XmlObject)result).Values["MyDouble"]).Value);
            Assert.AreEqual("MyDouble", ((XmlNullable)((XmlObject)result).Values["MyDouble"]).NodeName);

            Assert.AreEqual(XmlValueType.Nullable, ((XmlObject)result).Values["MyBool"].ValueType);
            Assert.AreEqual(model.MyBool, ((XmlNullable)((XmlObject)result).Values["MyBool"]).Value);
            Assert.AreEqual("MyBool", ((XmlNullable)((XmlObject)result).Values["MyBool"]).NodeName);

            Assert.AreEqual(XmlValueType.Nullable, ((XmlObject)result).Values["MyEnum"].ValueType);
            Assert.AreEqual(AssemblyEnum.Other, ((XmlNullable)((XmlObject)result).Values["MyEnum"]).Value);
            Assert.AreEqual("MyEnum", ((XmlNullable)((XmlObject)result).Values["MyEnum"]).NodeName);

            Assert.AreEqual(XmlValueType.Nullable, ((XmlObject)result).Values["MyDate"].ValueType);
            Assert.AreEqual(model.MyDate, ((XmlNullable)((XmlObject)result).Values["MyDate"]).Value);
            Assert.AreEqual("MyDate", ((XmlNullable)((XmlObject)result).Values["MyDate"]).NodeName);
        }
        public void TestObject_WithNullablesNotNull()
        {
            // Json nullable => value object

            var service = this.GetService();

            var g = new Guid("344ac1a2-9613-44d7-b64c-8d45b4585176");

            var model = new ItemNullable
            {
                MyGuid   = g,
                MyInt    = 1,
                MyDouble = 1.5,
                MyBool   = true,
                MyEnum   = AssemblyEnum.Other,
                MyDate   = new DateTime(1990, 12, 12)
            };

            var result = service.ToJson(model);

            Assert.AreEqual("{\"MyGuid\":\"344ac1a2-9613-44d7-b64c-8d45b4585176\",\"MyInt\":1,\"MyDouble\":1.5,\"MyBool\":true,\"MyEnum\":1,\"MyDate\":\"12/12/1990 00:00:00\"}", result);
        }