Exemplo n.º 1
0
        public void ParseValue_Utc_DateTime()
        {
            // arrange
            DateTimeType dateTimeType = new DateTimeType();
            DateTime     dateTime     =
                new DateTime(2018, 6, 11, 8, 46, 14, DateTimeKind.Utc);
            string expectedLiteralValue = "2018-06-11T08:46:14.000Z";

            // act
            StringValueNode stringLiteral =
                (StringValueNode)dateTimeType.ParseValue(dateTime);

            // assert
            Assert.Equal(expectedLiteralValue, stringLiteral.Value);
        }
Exemplo n.º 2
0
        public void Deserialize_IsoString_DateTime()
        {
            // arrange
            DateTimeType dateTimeType = new DateTimeType();
            DateTime     dateTime     = new DateTime(
                2018, 6, 11, 8, 46, 14, DateTimeKind.Unspecified);

            // act
            DateTime deserializedValue = ((DateTimeOffset)dateTimeType
                                          .Deserialize("2018-06-11T08:46:14+04:00")).DateTime;

            // assert
            Assert.Equal(dateTime, deserializedValue);
            Assert.Equal(DateTimeKind.Unspecified, deserializedValue.Kind);
        }
Exemplo n.º 3
0
        public void Deserialize_IsoString_DateTimeOffset()
        {
            // arrange
            var dateTimeType = new DateTimeType();
            var dateTime     = new DateTimeOffset(
                new DateTime(2018, 6, 11, 8, 46, 14),
                new TimeSpan(4, 0, 0));

            // act
            var deserializedValue = (DateTimeOffset)dateTimeType
                                    .Deserialize("2018-06-11T08:46:14+04:00");

            // assert
            Assert.Equal(dateTime, deserializedValue);
        }
Exemplo n.º 4
0
        public void Deserialize_ZuluString_DateTimeOffset()
        {
            // arrange
            DateTimeType   dateTimeType = new DateTimeType();
            DateTimeOffset dateTime     = new DateTimeOffset(
                new DateTime(2018, 6, 11, 8, 46, 14),
                new TimeSpan(0, 0, 0));

            // act
            DateTimeOffset deserializedValue = (DateTimeOffset)dateTimeType
                                               .Deserialize("2018-06-11T08:46:14.000Z");

            // assert
            Assert.Equal(dateTime, deserializedValue);
        }
Exemplo n.º 5
0
        public void Serialize_DateTimeOffset()
        {
            // arrange
            DateTimeType   dateTimeType = new DateTimeType();
            DateTimeOffset dateTime     = new DateTimeOffset(
                new DateTime(2018, 6, 11, 8, 46, 14),
                new TimeSpan(4, 0, 0));
            string expectedValue = "2018-06-11T08:46:14+04:00";

            // act
            string serializedValue = (string)dateTimeType.Serialize(dateTime);

            // assert
            Assert.Equal(expectedValue, serializedValue);
        }
Exemplo n.º 6
0
        public void Deserialize_NullableDateTime_To_DateTimeOffset()
        {
            // arrange
            var      type = new DateTimeType();
            DateTime?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,
                         Assert.IsType <DateTimeOffset>(deserialized).UtcDateTime);
        }
Exemplo n.º 7
0
        public void Serialize_Utc_DateTimeOffset()
        {
            // arrange
            var            dateTimeType = new DateTimeType();
            DateTimeOffset dateTime     = new DateTime(
                2018, 6, 11, 8, 46, 14, DateTimeKind.Utc);

            string expectedValue = "2018-06-11T08:46:14.000Z";

            // act
            string serializedValue = (string)dateTimeType.Serialize(dateTime);

            // assert
            Assert.Equal(expectedValue, serializedValue);
        }
Exemplo n.º 8
0
        public void ParseValue_DateTimeOffset()
        {
            // arrange
            var dateTimeType = new DateTimeType();
            var dateTime     = new DateTimeOffset(
                new DateTime(2018, 6, 11, 8, 46, 14),
                new TimeSpan(4, 0, 0));
            string expectedLiteralValue = "2018-06-11T08:46:14.000+04:00";

            // act
            var stringLiteral =
                (StringValueNode)dateTimeType.ParseValue(dateTime);

            // assert
            Assert.Equal(expectedLiteralValue, stringLiteral.Value);
        }
Exemplo n.º 9
0
        public void ParseLiteral_StringValueNode()
        {
            // arrange
            DateTimeType    dateTimeType     = new DateTimeType();
            StringValueNode literal          = new StringValueNode("2018-06-11T08:46:14+04:00");
            DateTimeOffset  expectedDateTime = new DateTimeOffset(
                new DateTime(2018, 6, 11, 8, 46, 14),
                new TimeSpan(4, 0, 0));

            // act
            DateTimeOffset dateTime = (DateTimeOffset)dateTimeType
                                      .ParseLiteral(literal);

            // assert
            Assert.Equal(expectedDateTime, dateTime);
        }
Exemplo n.º 10
0
        public void ParseValue_Local_DateTime()
        {
            // arrange
            DateTimeType dateTimeType = new DateTimeType();
            DateTime     dateTime     =
                new DateTime(2018, 6, 11, 8, 46, 14, DateTimeKind.Local);
            DateTimeOffset offset         = dateTime;
            DateTime       offsetDateTime = offset.DateTime;

            // act
            StringValueNode stringLiteral =
                (StringValueNode)dateTimeType.ParseValue(dateTime);
            StringValueNode stringLiteralOffset =
                (StringValueNode)dateTimeType.ParseValue(offsetDateTime);

            // assert
            Assert.Equal(stringLiteral, stringLiteralOffset);
        }
Exemplo n.º 11
0
        public void ParseValue_Unspecified_DateTime()
        {
            // arrange
            var dateTimeType = new DateTimeType();
            var dateTime     =
                new DateTime(2018, 6, 11, 8, 46, 14, DateTimeKind.Unspecified);
            DateTimeOffset offset         = dateTime;
            DateTime       offsetDateTime = offset.DateTime;

            // act
            var stringLiteral =
                (StringValueNode)dateTimeType.ParseValue(dateTime);
            var stringLiteralOffset =
                (StringValueNode)dateTimeType.ParseValue(offsetDateTime);

            // assert
            Assert.Equal(stringLiteralOffset, stringLiteral);
        }
Exemplo n.º 12
0
        public void Deserialize_ZuluString_DateTime()
        {
            // arrange
            var            dateTimeType = new DateTimeType();
            DateTimeOffset dateTime     = new DateTime(
                2018,
                6,
                11,
                8,
                46,
                14,
                DateTimeKind.Utc);

            // act
            DateTimeOffset deserializedValue = ((DateTimeOffset)dateTimeType
                                                .Deserialize("2018-06-11T08:46:14.000Z"));

            // assert
            Assert.Equal(dateTime, deserializedValue.UtcDateTime);
        }
Exemplo n.º 13
0
        public void ParseLiteral_StringValueNode_DifferentCulture(string cultureName)
        {
            // arrange
            Thread.CurrentThread.CurrentCulture =
                CultureInfo.GetCultureInfo(cultureName);

            var dateTimeType = new DateTimeType();
            var literal      = new StringValueNode(
                "2018-06-29T08:46:14+04:00");
            var expectedDateTime = new DateTimeOffset(
                new DateTime(2018, 6, 29, 8, 46, 14),
                new TimeSpan(4, 0, 0));

            // act
            var dateTime = (DateTimeOffset)dateTimeType
                           .ParseLiteral(literal);

            // assert
            Assert.Equal(expectedDateTime, dateTime);
        }