You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The unit test BindingParameterResolverTests.DateTimeResolver_ReturnsExpectedValue is locale-dependent and shouldn't be.
Repro steps
Switch to a locale such as en-GB.
Set the date to a date on the 13th or later of the month.
Run the unit tests.
Expected behavior
The unit tests should pass.
Actual behavior
DateTimeResolver_ReturnsExpectedValue fails with a FormatException.
Microsoft.Azure.WebJobs.Host.UnitTests.Bindings.Path.BindingParameterResolverTests.DateTimeResolver_ReturnsExpectedValue
Source: BindingParameterResolverTests.cs line 68
Duration: 1 ms
Message:
System.FormatException : String '02/16/2023 08:35:41' was not recognized as a valid DateTime.
Stack Trace:
DateTimeParse.Parse(ReadOnlySpan`1 s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
DateTime.Parse(String s)
BindingParameterResolverTests.DateTimeResolver_ReturnsExpectedValue() line 77
The problem is that resolvedValue = resolver.Resolve("datetime:G") uses CultureInfo.InvariantCulture, but the basic DateTime.Parse(resolvedValue) of the following assert uses whatever the current culture of the test computer is. For historical reasons CultureInfo.InvariantCulture is, if not an alias of en-US, very close to it, but the majority of cultures don't use middle-endian dates.
Known workarounds
Setting the computer's locale to en-US is a workaround, but somewhat antithetical to the desire to welcome outside contributions.
I see this as a bug in the test rather than the code tested, so I think the correct fix is to change DateTime.Parse(resolvedValue) to DateTime.Parse(resolvedValue, CultureInfo.InvariantCulture).
The unit test
BindingParameterResolverTests.DateTimeResolver_ReturnsExpectedValue
is locale-dependent and shouldn't be.Repro steps
Expected behavior
The unit tests should pass.
Actual behavior
DateTimeResolver_ReturnsExpectedValue
fails with aFormatException
.The problem is that
resolvedValue = resolver.Resolve("datetime:G")
usesCultureInfo.InvariantCulture
, but the basicDateTime.Parse(resolvedValue)
of the following assert uses whatever the current culture of the test computer is. For historical reasonsCultureInfo.InvariantCulture
is, if not an alias of en-US, very close to it, but the majority of cultures don't use middle-endian dates.Known workarounds
Setting the computer's locale to en-US is a workaround, but somewhat antithetical to the desire to welcome outside contributions.
I see this as a bug in the test rather than the code tested, so I think the correct fix is to change
DateTime.Parse(resolvedValue)
toDateTime.Parse(resolvedValue, CultureInfo.InvariantCulture)
.Related information
Present in e210142 , which is the current dev.
The text was updated successfully, but these errors were encountered: