public void Can_Deserialize_Attributes_On_Default_Root() { string doc = CreateAttributesXml(); RestResponse response = new RestResponse { Content = doc }; XmlDeserializer d = new XmlDeserializer(); PersonForXml p = d.Deserialize <PersonForXml>(response); Assert.Equal("John Sheehan", p.Name); Assert.Equal(new DateTime(2009, 9, 25, 0, 6, 1), p.StartDate); Assert.Equal(28, p.Age); Assert.Equal(long.MaxValue, p.BigNumber); Assert.Equal(99.9999m, p.Percent); Assert.Equal(false, p.IsCool); Assert.Equal(new Guid(GUID_STRING), p.UniqueId); Assert.Equal(new Uri("http://example.com", UriKind.RelativeOrAbsolute), p.Url); Assert.Equal(new Uri("/foo/bar", UriKind.RelativeOrAbsolute), p.UrlPath); Assert.NotNull(p.BestFriend); Assert.Equal("The Fonz", p.BestFriend.Name); Assert.Equal(1952, p.BestFriend.Since); }
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); }