Example #1
0
        public void DeserializeWrongNodeTest()
        {
            var data = XElement.Parse(
                "<data><model><Id>1</Id><Name>John Smith</Name><Date>2005-10-23T12:00:00.0000000</Date></model></data>");
            DataTestModel result = data.ToObject <DataTestModel>("wrongNode");

            Assert.IsNull(result);
        }
Example #2
0
        public void DeserializeWrongNamespaceTest()
        {
            var data = XElement.Parse(
                "<data xmlns=\"http://tempuri.org\"><model><Id>1</Id><Name>John Smith</Name><Date>2005-10-23T12:00:00.0000000</Date></model></data>");
            DataTestModel result =
                data.ToObject <DataTestModel>("model",
                                              "http://wrongnamespace.org");

            Assert.IsNull(result);
        }
Example #3
0
        public void SerializeWithNamespaceTest()
        {
            XElement expected =
                XElement.Parse(
                    "<DataTestModel xmlns=\"http://tempuri.org\"><Id>1</Id><Name>John Smith</Name><Date>2005-10-23T12:00:00.0000000</Date></DataTestModel>");
            var data = new DataTestModel()
            {
                Id   = 1,
                Name = "John Smith",
                Date = new DateTime(2005, 10, 23, 12, 0, 0)
            };
            XElement result = data.ToXml("http://tempuri.org");

            Assert.AreEqual(expected.ToString(), result.ToString());
        }
Example #4
0
        public void DeserializeXmlTest()
        {
            DataTestModel expected = new DataTestModel
            {
                Id   = 1,
                Name = "John Smith",
                Date = new DateTime(2005, 10, 23, 12, 0, 0)
            };
            var data = XElement.Parse(
                "<data><Id>1</Id><Name>John Smith</Name><Date>2005-10-23T12:00:00.0000000</Date></data>");
            DataTestModel result = data.ToObject <DataTestModel>();

            Assert.AreEqual(expected.Id, result.Id);
            Assert.AreEqual(expected.Name, result.Name);
            Assert.AreEqual(expected.Date, result.Date);
        }
Example #5
0
        public void DeserializeWithNamespaceTest()
        {
            DataTestModel expected = new DataTestModel
            {
                Id   = 1,
                Name = "John Smith",
                Date = new DateTime(2005, 10, 23, 12, 0, 0)
            };
            var data = XElement.Parse(
                "<data xmlns=\"http://tempuri.org\"><model><Id>1</Id><Name>John Smith</Name><Date>2005-10-23T12:00:00.0000000</Date></model></data>");
            DataTestModel result = data.ToObject <DataTestModel>("model", "http://tempuri.org");

            Assert.IsNotNull(result);
            Assert.AreEqual(expected.Id, result.Id);
            Assert.AreEqual(expected.Name, result.Name);
            Assert.AreEqual(expected.Date, result.Date);
        }