Exemple #1
0
        public void UseDate_Deserialize()
        {
            string objectXml = "<DateTime>1997/07/31 10:00:00</DateTime>";

            DateTime date = _tester.Deserialize <DateTime>(objectXml);

            Assert.AreEqual(new DateTime(1997, 7, 31, 10, 0, 0), date);
        }
Exemple #2
0
        public void Attributes_SetProperties()
        {
            string objectXml = "<StringPropertiesTestObject Name=\"MyName\" Value=\"MyValue\"/>";

            var obj = _tester.Deserialize <StringPropertiesTestObject>(objectXml);

            Assert.AreEqual("MyName", obj.Name);
            Assert.AreEqual("MyValue", obj.Value);
        }
Exemple #3
0
        public void ArrayAsValue_Deserialize()
        {
            string objectXml = "<ArrayOfInt32>[1,2]</ArrayOfInt32>";

            var obj = _tester.Deserialize <int[]>(objectXml);

            Assert.IsNotNull(obj);
            Assert.AreEqual(2, obj.Length);
            Assert.AreEqual(1, obj[0]);
            Assert.AreEqual(2, obj[1]);
        }
Exemple #4
0
        public void GenericInterface_GetCorrectImplementation()
        {
            string objectXml =
                "<EnumerableOfString Type=\"ListOfString\">" +
                "<String>Hi</String>" +
                "</EnumerableOfString>";

            IEnumerable <string> str = _tester.Deserialize <IEnumerable <string> >(objectXml);

            Assert.IsNotNull(str);
            Assert.AreEqual("Hi", str.First());
        }
Exemple #5
0
        public void HasOnlyConstructor_CallConstructor()
        {
            string objectXml =
                "<ConstructorObject ParamA=\"ParamA\">" +
                "<ParamB>ParamB</ParamB>" +
                "</ConstructorObject>";

            ConstructorObject obj = _tester.Deserialize <ConstructorObject>(objectXml);

            Assert.AreEqual("ParamA", obj.ParamA);
            Assert.AreEqual("ParamB", obj.ParamB);
        }
Exemple #6
0
        public void ReferenceValue_GetReference()
        {
            string objectXml =
                "<ObjectWithReferenceContainer>" +
                "<NamedElements>" +
                "<NamedElement Name=\"NameA\" Value=\"ValueA\"/>" +
                "<NamedElement Name=\"NameB\" Value=\"ValueB\"/>" +
                "</NamedElements>" +
                "<Holder A=\"$NameA\" B=\"$NameB\"/>" +
                "</ObjectWithReferenceContainer>";

            var deserialized = _tester.Deserialize <ObjectWithReferenceContainer>(objectXml);

            Assert.IsNotNull(deserialized);
            Assert.IsNotNull(deserialized.NamedElements);
            Assert.IsTrue(deserialized.NamedElements.Count == 2);
            Assert.IsTrue(deserialized.NamedElements[0] == deserialized.Holder.A);
            Assert.IsTrue(deserialized.NamedElements[1] == deserialized.Holder.B);
        }
Exemple #7
0
        public void ListOfSubProperties_SetItems()
        {
            string objectXml =
                "<ListOfSubProperties>" +
                "<SubProperties SubPropertyA=\"1AValue\" SubPropertyB=\"1BValue\"/>" +
                "<SubProperties SubPropertyA=\"2AValue\" SubPropertyB=\"2BValue\"/>" +
                "</ListOfSubProperties>";

            var list = new List <SubProperties>()
            {
                new SubProperties {
                    SubPropertyA = "1AValue", SubPropertyB = "1BValue"
                },
                new SubProperties {
                    SubPropertyA = "2AValue", SubPropertyB = "2BValue"
                },
            };

            var deserialized = _tester.Deserialize <List <SubProperties> >(objectXml);

            Assert.IsTrue(EnumerableExtentions.IsItemsEqual(deserialized, list), "Items Are Not Equal!");
        }
Exemple #8
0
        public void EnumMember_Flags_Parse()
        {
            string objXml =
                "<EnumMemberObject>" +
                "<EnumMember>One, Two</EnumMember>" +
                "</EnumMemberObject>";

            SuppleDeserializerTester tester = new SuppleDeserializerTester();
            var obj = tester.Deserialize <EnumMemberObject>(objXml);

            Assert.IsNotNull(obj);
            Assert.AreEqual(SomeEnum.Two | SomeEnum.One, obj.EnumMember);
        }
Exemple #9
0
        public void EnumMember_InvalidMember_ThrowsException()
        {
            string objXml =
                "<EnumMemberObject>" +
                "<EnumMember>BLAH_BLAH</EnumMember>" +
                "</EnumMemberObject>";

            SuppleDeserializerTester tester = new SuppleDeserializerTester();

            try
            {
                tester.Deserialize <EnumMemberObject>(objXml);
            }
            catch (EnumConvertException e)
            {
                Assert.AreEqual(typeof(SomeEnum), e.EnumType);
                Assert.AreEqual("EnumMember", e.Node.Name);
                Assert.AreEqual("BLAH_BLAH", e.Node.Value);
                return;
            }

            Assert.Fail("Exception was not thrown!");
        }