Adds new date string in HttpRuleParser
This commit is contained in:
parent
68ba94218a
commit
b41d8656d5
|
|
@ -24,8 +24,9 @@ namespace Microsoft.Net.Http.Headers
|
||||||
"d MMM yy H:m:s 'GMT'", // RFC 1123, no day-of-week, short year
|
"d MMM yy H:m:s 'GMT'", // RFC 1123, no day-of-week, short year
|
||||||
"d MMM yy H:m:s", // RFC 1123, no day-of-week, short year, no zone
|
"d MMM yy H:m:s", // RFC 1123, no day-of-week, short year, no zone
|
||||||
|
|
||||||
"dddd, d'-'MMM'-'yy H:m:s 'GMT'", // RFC 850
|
"dddd, d'-'MMM'-'yy H:m:s 'GMT'", // RFC 850, short year
|
||||||
"dddd, d'-'MMM'-'yy H:m:s", // RFC 850 no zone
|
"dddd, d'-'MMM'-'yy H:m:s", // RFC 850 no zone
|
||||||
|
"ddd, d'-'MMM'-'yyyy H:m:s 'GMT'", // RFC 850, long year
|
||||||
"ddd MMM d H:m:s yyyy", // ANSI C's asctime() format
|
"ddd MMM d H:m:s yyyy", // ANSI C's asctime() format
|
||||||
|
|
||||||
"ddd, d MMM yyyy H:m:s zzz", // RFC 5322
|
"ddd, d MMM yyyy H:m:s zzz", // RFC 5322
|
||||||
|
|
|
||||||
|
|
@ -2,29 +2,47 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.Net.Http.Headers
|
namespace Microsoft.Net.Http.Headers
|
||||||
{
|
{
|
||||||
public class DateParserTest
|
public class DateParserTest
|
||||||
{
|
{
|
||||||
[Fact]
|
[Theory]
|
||||||
public void TryParse_SetOfValidValueStrings_ParsedCorrectly()
|
[MemberData(nameof(ValidStringData))]
|
||||||
|
public void TryParse_SetOfValidValueStrings_ParsedCorrectly(string input, DateTimeOffset expected)
|
||||||
{
|
{
|
||||||
// We don't need to validate all possible date values, since they're already tested in HttpRuleParserTest.
|
// We don't need to validate all possible date values, since they're already tested in HttpRuleParserTest.
|
||||||
// Just make sure the parser calls HttpRuleParser methods correctly.
|
// Just make sure the parser calls HttpRuleParser methods correctly.
|
||||||
CheckValidParsedValue("Tue, 15 Nov 1994 08:12:31 GMT", new DateTimeOffset(1994, 11, 15, 8, 12, 31, TimeSpan.Zero));
|
DateTimeOffset result;
|
||||||
CheckValidParsedValue(" Sunday, 06-Nov-94 08:49:37 GMT ", new DateTimeOffset(1994, 11, 6, 8, 49, 37, TimeSpan.Zero));
|
Assert.True(HeaderUtilities.TryParseDate(input, out result));
|
||||||
CheckValidParsedValue(" Tue,\r\n 15 Nov\r\n 1994 08:12:31 GMT ", new DateTimeOffset(1994, 11, 15, 8, 12, 31, TimeSpan.Zero));
|
Assert.Equal(expected, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
private static IEnumerable<object[]> ValidStringData()
|
||||||
public void TryParse_SetOfInvalidValueStrings_ReturnsFalse()
|
|
||||||
{
|
{
|
||||||
CheckInvalidParsedValue(null);
|
yield return new object[] { "Tue, 15 Nov 1994 08:12:31 GMT", new DateTimeOffset(1994, 11, 15, 8, 12, 31, TimeSpan.Zero) };
|
||||||
CheckInvalidParsedValue(string.Empty);
|
yield return new object[] { " Sunday, 06-Nov-94 08:49:37 GMT ", new DateTimeOffset(1994, 11, 6, 8, 49, 37, TimeSpan.Zero) };
|
||||||
CheckInvalidParsedValue(" ");
|
yield return new object[] { " Tue,\r\n 15 Nov\r\n 1994 08:12:31 GMT ", new DateTimeOffset(1994, 11, 15, 8, 12, 31, TimeSpan.Zero) };
|
||||||
CheckInvalidParsedValue("!!Sunday, 06-Nov-94 08:49:37 GMT");
|
yield return new object[] { "Sat, 09-Dec-2017 07:07:03 GMT ", new DateTimeOffset(2017, 12, 09, 7, 7, 3, TimeSpan.Zero) };
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[MemberData(nameof(InvalidStringData))]
|
||||||
|
public void TryParse_SetOfInvalidValueStrings_ReturnsFalse(string input)
|
||||||
|
{
|
||||||
|
DateTimeOffset result;
|
||||||
|
Assert.False(HeaderUtilities.TryParseDate(input, out result));
|
||||||
|
Assert.Equal(new DateTimeOffset(), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<object[]> InvalidStringData()
|
||||||
|
{
|
||||||
|
yield return new object[] { null };
|
||||||
|
yield return new object[] { string.Empty };
|
||||||
|
yield return new object[] { " " };
|
||||||
|
yield return new object[] { "!!Sunday, 06-Nov-94 08:49:37 GMT" };
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -36,23 +54,5 @@ namespace Microsoft.Net.Http.Headers
|
||||||
Assert.Equal("Fri, 01 Jan 2010 01:01:01 GMT",
|
Assert.Equal("Fri, 01 Jan 2010 01:01:01 GMT",
|
||||||
HeaderUtilities.FormatDate(new DateTimeOffset(2010, 1, 1, 1, 1, 1, TimeSpan.Zero)));
|
HeaderUtilities.FormatDate(new DateTimeOffset(2010, 1, 1, 1, 1, 1, TimeSpan.Zero)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Helper methods
|
|
||||||
|
|
||||||
private void CheckValidParsedValue(string input, DateTimeOffset expectedResult)
|
|
||||||
{
|
|
||||||
DateTimeOffset result;
|
|
||||||
Assert.True(HeaderUtilities.TryParseDate(input, out result));
|
|
||||||
Assert.Equal(expectedResult, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CheckInvalidParsedValue(string input)
|
|
||||||
{
|
|
||||||
DateTimeOffset result;
|
|
||||||
Assert.False(HeaderUtilities.TryParseDate(input, out result));
|
|
||||||
Assert.Equal(new DateTimeOffset(), result);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue