test: the language guard switches back to English before failing the test

Loc.SetCulture stores the new culture before it raises CultureChanged, so the
guard's exception left the process in the other language until the offending
test's own cleanup ran, or for good, and the parallel classes asserting English
failed beside it. Both test programs now restore English first (the switch back
passes the guard) and then fail the test, naming it and the language it chose.
LanguageGuardTests runs a non-serial fixture through the runner and checks the
failure message, that English is back and that later listeners only hear of
English.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-12 10:34:33 +00:00
1 parent 9ad57b5e0b
commit bef602a9c4
3 files changed
+76 -4

No files matched your search

+7 -2
View File
@@ -1,3 +1,4 @@
using System.Globalization;
using Titano.Core.Localization;
using Titano.Testing;
@@ -9,10 +10,14 @@ internal static class TestMain
{
// The UI language is process-wide: a test that leaves English outside a serial class races with the English
// assertions of the classes running beside it, so it fails at the switch instead of making another one flaky.
// English comes back before the failure, so the classes beside it never see the other language (switching back
// passes this guard).
Loc.CultureChanged += (_, _) =>
{
if (TestContext.Current is { IsSerial: false } test && Loc.Culture.TwoLetterISOLanguageName != "en")
throw new AssertionException($"{test.TestName} switched the UI language to '{Loc.Culture.Name}' outside a [Serial] class");
if (TestContext.Current is not { IsSerial: false } test || Loc.Culture.TwoLetterISOLanguageName == "en") return;
var culture = Loc.Culture.Name;
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
throw new AssertionException($"{test.TestName} switched the UI language to '{culture}' outside a [Serial] class");
};
return TestRunner.RunAsync(args, typeof(TestMain).Assembly);
}