Exemple #1
0
        public void LocalDate_ExpectDeserializeInvalidStringToDateTime()
        {
            // arrange
            ScalarType scalar = new LocalDateType();

            // act
            var success = scalar.TryDeserialize("abc", out object?_);

            // assert
            Assert.False(success);
        }
Exemple #2
0
        protected void LocalDate_ExpectParseResultToMatchNull()
        {
            // arrange
            ScalarType scalar = new LocalDateType();

            // act
            IValueNode result = scalar.ParseResult(null);

            // assert
            Assert.Equal(typeof(NullValueNode), result.GetType());
        }
Exemple #3
0
        public void LocalDate_EnsureDateTimeTypeKindIsCorret()
        {
            // arrange
            var type = new LocalDateType();

            // act
            TypeKind kind = type.Kind;

            // assert
            Assert.Equal(TypeKind.Scalar, type.Kind);
        }
Exemple #4
0
        protected void LocalDate_ExpectParseResultToThrowSerializationException()
        {
            // arrange
            ScalarType scalar       = new LocalDateType();
            IValueNode runtimeValue = new IntValueNode(1);

            // act
            Exception?result = Record.Exception(() => scalar.ParseResult(runtimeValue));

            // assert
            Assert.IsType <SerializationException>(result);
        }
Exemple #5
0
        protected void LocalDate_ExpectParseResultToMatchStringValue()
        {
            // arrange
            ScalarType   scalar      = new LocalDateType();
            const string valueSyntax = "2018-06-29T08:46:14+04:00";

            // act
            IValueNode result = scalar.ParseResult(valueSyntax);

            // assert
            Assert.Equal(typeof(StringValueNode), result.GetType());
        }
Exemple #6
0
        public void LocalDate_ExpectDeserializeNullToNull()
        {
            // arrange
            ScalarType scalar = new LocalDateType();

            // act
            var success = scalar.TryDeserialize(null, out object?deserialized);

            // assert
            Assert.True(success);
            Assert.Null(deserialized);
        }
Exemple #7
0
        public void LocalDate_ExpectDeserializeNullableDateTimeToDateTime()
        {
            // arrange
            ScalarType scalar = new LocalDateType();
            DateTime?  time   = null;

            // act
            var success = scalar.TryDeserialize(time, out object?deserialized);

            // assert
            Assert.True(success);
            Assert.Null(deserialized);
        }
Exemple #8
0
        protected void LocalDate_ExpectSerializeDateTimeOffsetToMatch()
        {
            // arrange
            ScalarType scalar   = new LocalDateType();
            var        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)scalar.Serialize(dateTime) !;

            // assert
            Assert.Equal(expectedValue, serializedValue);
        }
Exemple #9
0
        protected void LocalDate_ExpectSerializeUtcToMatch()
        {
            // arrange
            ScalarType     scalar   = new LocalDateType();
            DateTimeOffset dateTime = new DateTime(
                2018, 6, 11, 8, 46, 14, DateTimeKind.Utc);

            string expectedValue = "2018-06-11";

            // act
            string serializedValue = (string)scalar.Serialize(dateTime) !;

            // assert
            Assert.Equal(expectedValue, serializedValue);
        }
Exemple #10
0
        public void LocalDate_ParseLiteralStringValueDifferentCulture(
            string cultureName)
        {
            // arrange
            Thread.CurrentThread.CurrentCulture =
                CultureInfo.GetCultureInfo(cultureName);

            ScalarType scalar           = new LocalDateType();
            var        valueSyntax      = 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 = (DateTime)scalar.ParseLiteral(valueSyntax) !;

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