Skip to content

DateTimeFormatInCSharp: retarget net10.0, MSTest 4.3.3, deterministic assertions - #2153

Open
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/62666-datetime-format
Open

DateTimeFormatInCSharp: retarget net10.0, MSTest 4.3.3, deterministic assertions#2153
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/62666-datetime-format

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Retargets dotnet-datetime/DateTimeFormatInCSharp from net6.0 to net10.0 and lifts the test packages with it (Microsoft.NET.Test.Sdk 18.9.0, MSTest 4.3.3, coverlet.collector 10.0.1).

MSTest 4 removed [ExpectedException], so that one test now uses Assert.ThrowsExactly<FormatException>.

Three assertions only passed where the machine clock is UTC and now hold anywhere:

  • %K on a DateTimeKind.Local value prints the machine's offset; the expectation is computed from TimeZoneInfo.Local instead of a hard-coded +00:00.
  • The RFC 1123 and universal-sortable tests called ToUniversalTime() on an Unspecified value, which converts from the local zone. Both values are now created as Utc.

The character between the time and its AM/PM designator comes from the host's ICU data, not from the .NET version (dotnet/runtime#96022, closed "working as designed"), so en-US emits U+0020 on some hosts and U+202F on others. Console output is compared through a small helper that folds Unicode space separators to a plain space, instead of pasting an invisible character into a string literal.

Build and all 39 tests green on SDK 10.0.302.

… assertions

Retarget both projects from net6.0 to net10.0 and lift the 2021-era test
packages with it: Microsoft.NET.Test.Sdk 18.9.0, MSTest.TestAdapter and
MSTest.TestFramework 4.3.3, coverlet.collector 10.0.1.

MSTest 4 removed [ExpectedException], so the ja-JP ParseExact test now uses
Assert.ThrowsExactly<FormatException>.

Three assertions only passed on a machine whose clock is UTC and now hold
anywhere:

- %K on a DateTimeKind.Local value prints the machine's offset, so the
  expectation is computed from TimeZoneInfo.Local instead of hard-coded +00:00.
- The RFC 1123 and universal-sortable tests called ToUniversalTime() on an
  Unspecified value, which converts from the local zone. Both values are now
  created as Utc, which is what the tests are about anyway.

The character between the time and its AM/PM designator comes from the host's
ICU data, not from the .NET version (dotnet/runtime#96022, "working as
designed"), so en-US emits U+0020 on some hosts and U+202F on others. Console
output is compared through TextExpectation.NormalizeSpaces, which folds Unicode
space separators to a plain space, rather than pasting an invisible character
into a string literal.

Program.cs is left as it is.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant