Beispiel #1
0
        public void ParseDateWithInvalidParameterShouldThrowFormatException()
        {
            var invalidDates = new[]
            {
                "0000-01-01",
                "0001-13-12",
                "0001-12-98",
                "0001-12-98",
                "-0000-01-01",
                "-0001-13-12",
                "-0001-12-98",
                "-0001-12-98",
                "99999-01-01",
                "-99999-01-01",
                "-0000-01-01",
                "2001-02-29",
                "2001-04-31",
                "-0001-01-01",
                "-9999-12-12",
                "001-01-01",
                "01-01-01",
                "1-01-01",
            };

            foreach (var invalidDate in invalidDates)
            {
                Date?result;
                Assert.False(EdmValueParser.TryParseDate(invalidDate, out result));
            }
        }
Beispiel #2
0
        public void TryParseDateWithValidParameterShouldParseCorrectly()
        {
            Date?result;

            Assert.True(EdmValueParser.TryParseDate("2012-07-28", out result));
            Assert.Equal(new Date(2012, 07, 28), result);
        }
Beispiel #3
0
        public void TryParseDateWithValidParameterShouldParseCorrectly()
        {
            Date?result;

            EdmValueParser.TryParseDate("2012-07-28", out result).Should().BeTrue();
            result.Should().Be(new Date(2012, 07, 28));
        }
Beispiel #4
0
            /// <summary>
            /// Tries to convert the given text into this parser's expected type. Conversion only, formatting should already have been removed.
            /// </summary>
            /// <param name="text">The text to convert.</param>
            /// <param name="targetValue">The target value.</param>
            /// <returns>
            /// Whether or not conversion was successful.
            /// </returns>
            internal override bool TryConvert(string text, out object targetValue)
            {
                Date?date;
                bool isSucceed = EdmValueParser.TryParseDate(text, out date);

                targetValue = date;
                return(isSucceed);
            }
Beispiel #5
0
        public void DateAsXmlWithValidShouldRoundtripWhenParsed()
        {
            foreach (var date in this.validDate)
            {
                Date?parsedDate;
                var  result = EdmValueWriter.DateAsXml(date);
                EdmValueParser.TryParseDate(result, out parsedDate).Should().BeTrue();

                parsedDate.Should().Be(date);
            }
        }
Beispiel #6
0
        public void DateAsXmlWithValidShouldRoundtripWhenParsed()
        {
            foreach (var date in this.validDate)
            {
                Date?parsedDate;
                var  result = EdmValueWriter.DateAsXml(date);
                Assert.True(EdmValueParser.TryParseDate(result, out parsedDate));

                Assert.Equal(date, parsedDate);
            }
        }
Beispiel #7
0
        private IEnumerable <EdmError> ComputeErrors()
        {
            Date?value;

            if (!EdmValueParser.TryParseDate(this.expression.Value, out value))
            {
                return(new EdmError[] { new EdmError(this.Location, EdmErrorCode.InvalidDate, Edm.Strings.ValueParser_InvalidDate(this.expression.Value)) });
            }
            else
            {
                return(Enumerable.Empty <EdmError>());
            }
        }
Beispiel #8
0
        private Date ComputeValue()
        {
            Date?value;

            return(EdmValueParser.TryParseDate(this.expression.Value, out value) ? value.Value : Date.MinValue);
        }
Beispiel #9
0
        public void ParseDateWithSpaceShouldThrowFormatException()
        {
            Date?result;

            Assert.False(EdmValueParser.TryParseDate(" ", out result));
        }
Beispiel #10
0
        public void ParseDateWithEmptyStringShouldThrowFormatException()
        {
            Date?result;

            Assert.False(EdmValueParser.TryParseDate(string.Empty, out result));
        }
Beispiel #11
0
        public void ParseDateNullShouldThrowFormatException()
        {
            Date?result;

            Assert.False(EdmValueParser.TryParseDate(null, out result));
        }
Beispiel #12
0
        public void ParseDateWithSpaceShouldThrowFormatException()
        {
            Date?result;

            EdmValueParser.TryParseDate(" ", out result).Should().BeFalse();
        }
Beispiel #13
0
        public void ParseDateNullShouldThrowFormatException()
        {
            Date?result;

            EdmValueParser.TryParseDate(null, out result).Should().BeFalse();
        }