public void Deserialize_DateTime_To_DateTime() { // arrange var type = new DateType(); var time = new DateTime(2018, 6, 11, 8, 46, 14, DateTimeKind.Utc); // act bool success = type.TryDeserialize(time, out object deserialized); // assert Assert.True(success); Assert.Equal(time, deserialized); }
public void Deserialize_NullableDateTime_To_DateTime_2() { // arrange var type = new DateType(); DateTime?time = null; // act bool success = type.TryDeserialize(time, out object deserialized); // assert Assert.True(success); Assert.Null(deserialized); }
public void ParseLiteral_StringValueNode() { // arrange var dateType = new DateType(); var literal = new StringValueNode("2018-06-29"); var expectedDateTime = new DateTime(2018, 6, 29); // act var dateTime = (DateTime)dateType.ParseLiteral(literal) !; // assert Assert.Equal(expectedDateTime, dateTime); }
public void Serialize_Date() { // arrange DateType dateType = new DateType(); DateTime dateTime = new DateTime( 2018, 6, 11, 8, 46, 14, DateTimeKind.Utc); string expectedValue = "2018-06-11"; // act string serializedValue = (string)dateType.Serialize(dateTime); // assert Assert.Equal(expectedValue, serializedValue); }
public void ParseLiteral_StringValueNode() { // arrange DateType dateType = new DateType(); StringValueNode literal = new StringValueNode("2018-06-11"); DateTime expectedDateTime = new DateTime(2018, 6, 11); // act DateTime dateTime = (DateTime)dateType .ParseLiteral(literal); // assert Assert.Equal(expectedDateTime, dateTime); }
public void ParseValue_Null() { // arrange var dateType = new DateType(); var dateTime = new DateTime(2018, 6, 11, 8, 46, 14, DateTimeKind.Utc); var expectedLiteralValue = "2018-06-11"; // act var stringLiteral = (StringValueNode)dateType.ParseValue(dateTime); // assert Assert.Equal(expectedLiteralValue, stringLiteral.Value); }
public void Deserialize_NullableDateTime_To_DateTime() { // arrange var type = new DateType(); DateTime?time = new DateTime(2018, 6, 11, 8, 46, 14, DateTimeKind.Utc); // act var success = type.TryDeserialize(time, out var deserialized); // assert Assert.True(success); Assert.Equal(time, Assert.IsType <DateTime>(deserialized)); }
public void Serialize_DateTimeOffset() { // arrange DateType dateType = new DateType(); DateTimeOffset dateTime = new DateTimeOffset( new DateTime(2018, 6, 11, 8, 46, 14), new TimeSpan(4, 0, 0)); string expectedValue = "2018-06-11"; // act string serializedValue = (string)dateType.Serialize(dateTime); // assert Assert.Equal(expectedValue, serializedValue); }
public void ParseValue_DateTimeOffset() { // arrange DateType dateType = new DateType(); DateTimeOffset dateTime = new DateTimeOffset( new DateTime(2018, 6, 11, 8, 46, 14), new TimeSpan(4, 0, 0)); string expectedLiteralValue = "2018-06-11"; // act StringValueNode stringLiteral = (StringValueNode)dateType.ParseValue(dateTime); // assert Assert.Equal(expectedLiteralValue, stringLiteral.Value); }
public void ParseLiteral_StringValueNode_DifferentCulture( string cultureName) { // arrange Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(cultureName); var dateType = new DateType(); var literal = new StringValueNode("2018-06-29"); var expectedDateTime = new DateTime(2018, 6, 29); // act var dateTime = (DateTime)dateType.ParseLiteral(literal) !; // assert Assert.Equal(expectedDateTime, dateTime); }