public void NullableRoundTrips(DateTime? dt) { var parser = new NullableFieldParser(new DateTimeFieldParser()); var serializer = new NullableFieldSerializer(new DateTimeFieldSerializer()); var s = serializer.Serialize(dt).First().FieldValue; Console.WriteLine(s); var value = (DateTime?) parser.Parse(XmlUtils.CreateNode("date", s), typeof(DateTime?)); Console.WriteLine(value.Value.ToString("r")); Assert.AreEqual(dt, value); }
public void NullableRoundTrips(DateTimeOffset dt) { var parser = new NullableFieldParser(new DateTimeOffsetFieldParser()); var serializer = new NullableFieldSerializer(new DateTimeOffsetFieldSerializer()); var s = serializer.Serialize(dt).First().FieldValue; var xml = new XDocument(); xml.Add(new XElement("date", s)); var value = (DateTimeOffset?)parser.Parse(xml.Root, typeof(DateTimeOffset?)); Assert.AreEqual(dt, value); }
public static IEnumerable<Test> NullableRoundTrips() { var parser = new NullableFieldParser(new DateTimeFieldParser()); var serializer = new NullableFieldSerializer(new DateTimeFieldSerializer()); return dateTimes.Select(dt => new TestCase("NullableRoundTrips " + dt, () => { var s = serializer.Serialize(dt).First().FieldValue; var xml = new XDocument(); xml.Add(new XElement("date", s)); var value = (DateTime?)parser.Parse(xml.Root, typeof(DateTime?)); Assert.AreEqual(dt, value); })); }
public void NullableRoundTrips(DateTime? dt) { var parser = new NullableFieldParser(new DateTimeFieldParser()); var serializer = new NullableFieldSerializer(new DateTimeFieldSerializer()); var s = serializer.Serialize(dt).First().FieldValue; Console.WriteLine(s); var xml = new XDocument(); xml.Add(new XElement("date", s)); var value = (DateTime?) parser.Parse(xml.Root, typeof(DateTime?)); Console.WriteLine(value.Value.ToString("r")); Assert.AreEqual(dt, value); }