public void Can_Deserialize_Custom_Formatted_Date()
        {
            CultureInfo culture = CultureInfo.InvariantCulture;
            string      format  = "dd yyyy MMM, hh:mm ss tt zzz";
            DateTime    date    = new DateTime(2010, 2, 8, 11, 11, 11);
            XDocument   doc     = new XDocument();
            XElement    root    = new XElement("Person");

            root.Add(new XElement("StartDate", date.ToString(format, culture)));
            doc.Add(root);

            XmlDeserializer xml = new XmlDeserializer
            {
                DateFormat = format,
                Culture    = culture
            };
            RestResponse response = new RestResponse {
                Content = doc.ToString()
            };
            PersonForXml output = xml.Deserialize <PersonForXml>(response);

            Assert.AreEqual(date, output.StartDate);
        }
示例#2
0
        public void Can_Deserialize_Attributes_With_Namespace()
        {
            string       doc      = CreateAttributesXml();
            RestResponse response = new RestResponse {
                Content = doc
            };
            XmlDeserializer d = new XmlDeserializer {
                Namespace = "http://restsharp.org"
            };
            PersonForXml p = d.Deserialize <PersonForXml>(response);

            Assert.AreEqual("John Sheehan", p.Name);
            Assert.AreEqual(new DateTime(2009, 9, 25, 0, 6, 1), p.StartDate);
            Assert.AreEqual(28, p.Age);
            Assert.AreEqual(long.MaxValue, p.BigNumber);
            Assert.AreEqual(99.9999m, p.Percent);
            Assert.AreEqual(false, p.IsCool);
            Assert.AreEqual(new Guid(GUID_STRING), p.UniqueId);
            Assert.AreEqual(new Uri("http://example.com", UriKind.RelativeOrAbsolute), p.Url);
            Assert.AreEqual(new Uri("/foo/bar", UriKind.RelativeOrAbsolute), p.UrlPath);
            Assert.NotNull(p.BestFriend);
            Assert.AreEqual("The Fonz", p.BestFriend.Name);
            Assert.AreEqual(1952, p.BestFriend.Since);
        }