using System.Globalization; using Chronos.Core.Localization; using Chronos.Testing; namespace Chronos.App.Tests; internal static class TestMain { public static async Task Main(string[] args) { // 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 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"); }; var result = await TestRunner.RunAsync(args, typeof(TestMain).Assembly); // WPF's binding engine cleans up on its dispatcher; stopped with the process instead, that cleanup can run against a // half-torn-down engine and crash the exit after every test passed. Windows.WpfApplication.Shutdown(); return result; } }