예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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));
        }
예제 #8
0
        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);
        }
예제 #9
0
        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);
        }
예제 #10
0
        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);
        }