test: run process-wide tests serially and report constructor failures as themselves
Four App tests switched the process-wide UI language inside parallel classes, so another class's English assertion, or its constructor's reset to English, could land in the middle of them; they now live in the serial ArchiveLanguageTests and ImportLanguageTests. The App and Core test programs fail a test that leaves English outside a serial class at the switch, through the new TestContext.Current and TestContext.IsSerial. The FrameWindow cancellation test counted unobserved task exceptions while other classes ran beside it; it moves to the serial FrameWindowIsolationTests, and both unobserved-exception tests drain the finalizer queue before they start counting. The runner unwrapped TargetInvocationException only around the test method: a skip or an assertion thrown by a test class constructor or field initializer was reported as a failure reading "Exception has been thrown by the target of an invocation". Constructors are unwrapped the same way now. TestRunner.Discover(Type) and ExecuteAsync are public, so Tools.Tests checks the runner with nested fixtures. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
13 files changed
+381
-167
No files matched your search
@@ -0,0 +1,61 @@
|
||||
using System.Globalization;
|
||||
using Titano.App.Archiving;
|
||||
using Titano.Core.Archiving;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Testing;
|
||||
using static Titano.App.Tests.Archiving.ArchiveLogicTests;
|
||||
|
||||
namespace Titano.App.Tests.Archiving;
|
||||
|
||||
/// <summary>
|
||||
/// Archive texts in other languages. They switch the process-wide UI language, so the class is serial: in parallel it
|
||||
/// would race with the English assertions of the classes running beside it.
|
||||
/// </summary>
|
||||
[Serial]
|
||||
public sealed class ArchiveLanguageTests
|
||||
{
|
||||
public ArchiveLanguageTests() => Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
|
||||
[Test]
|
||||
public void MonthColumnsAreInitialsOnlyWhereTheyAreLetters()
|
||||
{
|
||||
var numbers = Enumerable.Range(1, 12).Select(m => m.ToString(CultureInfo.InvariantCulture)).ToArray();
|
||||
try
|
||||
{
|
||||
Assert.Equal("J F M A M J J A S O N D", string.Join(' ', ArchiveFigures.MonthLabels()));
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("it"));
|
||||
Assert.Equal("G F M A M G L A S O N D", string.Join(' ', ArchiveFigures.MonthLabels()));
|
||||
// Numbered abbreviations ("10月", "Tháng 10") would read "1" for October to December, or "T" for every month.
|
||||
foreach (var culture in new[] { "ja", "ko", "zh-Hans", "zh-Hant", "vi", "th", "ar", "he" })
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo(culture));
|
||||
Assert.SequenceEqual(numbers, ArchiveFigures.MonthLabels(), culture);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TreeRowsShowTheirWholeTitleAndTheKeysOfTheReadingDirection()
|
||||
{
|
||||
var harbour = Seq("Construction cam · weekly", new DateTime(2026, 9, 28), 3_600, 72_000_000_000);
|
||||
var tree = ArchiveTree.Build(Main, ArchiveAvailability.Online, [harbour]);
|
||||
var year = new ArchiveTreeRowViewModel(tree.Root.Children[0], ArchiveAvailability.Online, _ => { });
|
||||
var sequence = new ArchiveTreeRowViewModel(tree.Root.Children[0].Children[0], ArchiveAvailability.Online, _ => { });
|
||||
Assert.Equal("Construction cam · weekly · 3,600 photos · 72 GB", sequence.RowToolTip);
|
||||
Assert.Equal("2026 · 1 sequence · 72 GB · Right arrow opens the year, Left arrow closes it", year.RowToolTip);
|
||||
try
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("he"));
|
||||
Assert.Equal(Loc.L("Tooltips.Archive.YearRowRtl", "2026" + Loc.Separator + year.Detail), year.RowToolTip, "the arrow keys of a mirrored tree");
|
||||
Assert.Contains("", year.RowToolTip, "right-to-left marks keep the year and its figures apart");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,11 +17,11 @@ namespace Titano.App.Tests.Archiving;
|
||||
|
||||
public sealed class ArchiveLogicTests
|
||||
{
|
||||
private static readonly Core.Model.Archive Main = new() { Id = Guid.CreateVersion7(), Name = "TitanoArchive", RootPath = "/archive" };
|
||||
internal static readonly Core.Model.Archive Main = new() { Id = Guid.CreateVersion7(), Name = "TitanoArchive", RootPath = "/archive" };
|
||||
|
||||
public ArchiveLogicTests() => Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
|
||||
private static Sequence Seq(string title, DateTime? first, int frames = 100, long bytes = 1_000_000, params string[] tags) => new()
|
||||
internal static Sequence Seq(string title, DateTime? first, int frames = 100, long bytes = 1_000_000, params string[] tags) => new()
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
ArchiveId = Main.Id,
|
||||
@@ -170,28 +170,6 @@ public sealed class ArchiveLogicTests
|
||||
Assert.Empty(ArchiveFigures.PhotosPerMonth(Stats() with { ByMonth = [] }, DateTime.Today));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MonthColumnsAreInitialsOnlyWhereTheyAreLetters()
|
||||
{
|
||||
var numbers = Enumerable.Range(1, 12).Select(m => m.ToString(CultureInfo.InvariantCulture)).ToArray();
|
||||
try
|
||||
{
|
||||
Assert.Equal("J F M A M J J A S O N D", string.Join(' ', ArchiveFigures.MonthLabels()));
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("it"));
|
||||
Assert.Equal("G F M A M G L A S O N D", string.Join(' ', ArchiveFigures.MonthLabels()));
|
||||
// Numbered abbreviations ("10月", "Tháng 10") would read "1" for October to December, or "T" for every month.
|
||||
foreach (var culture in new[] { "ja", "ko", "zh-Hans", "zh-Hant", "vi", "th", "ar", "he" })
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo(culture));
|
||||
Assert.SequenceEqual(numbers, ArchiveFigures.MonthLabels(), culture);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TilesAndHealthSummariseTheIndex()
|
||||
{
|
||||
@@ -246,27 +224,6 @@ public sealed class ArchiveLogicTests
|
||||
Assert.Equal(Loc.L("Archive.Error.StalePlan"), ArchiveFailures.Cause(new StaleRenamePlanException(Guid.NewGuid())));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TreeRowsShowTheirWholeTitleAndTheKeysOfTheReadingDirection()
|
||||
{
|
||||
var harbour = Seq("Construction cam · weekly", new DateTime(2026, 9, 28), 3_600, 72_000_000_000);
|
||||
var tree = ArchiveTree.Build(Main, ArchiveAvailability.Online, [harbour]);
|
||||
var year = new ArchiveTreeRowViewModel(tree.Root.Children[0], ArchiveAvailability.Online, _ => { });
|
||||
var sequence = new ArchiveTreeRowViewModel(tree.Root.Children[0].Children[0], ArchiveAvailability.Online, _ => { });
|
||||
Assert.Equal("Construction cam · weekly · 3,600 photos · 72 GB", sequence.RowToolTip);
|
||||
Assert.Equal("2026 · 1 sequence · 72 GB · Right arrow opens the year, Left arrow closes it", year.RowToolTip);
|
||||
try
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("he"));
|
||||
Assert.Equal(Loc.L("Tooltips.Archive.YearRowRtl", "2026" + Loc.Separator + year.Detail), year.RowToolTip, "the arrow keys of a mirrored tree");
|
||||
Assert.Contains("\u200F", year.RowToolTip, "right-to-left marks keep the year and its figures apart");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenameTemplatesAreCheckedAndThePlanListedByMode()
|
||||
{
|
||||
|
||||
@@ -8,9 +8,9 @@ namespace Titano.App.Tests.Import;
|
||||
|
||||
public sealed class CardPoolTests
|
||||
{
|
||||
private static readonly CardDevice CardA = new(@"F:\", "EOS_DIGITAL", 0x3F2A9C11, 128_000_000_000, 31_800_000_000, true, true);
|
||||
internal static readonly CardDevice CardA = new(@"F:\", "EOS_DIGITAL", 0x3F2A9C11, 128_000_000_000, 31_800_000_000, true, true);
|
||||
private static readonly CardDevice GoPro = new(@"E:\", "GOPRO", 0x11112222, 64_000_000_000, 52_600_000_000, true, true);
|
||||
private static readonly CardDevice Usb = new(@"G:\", "BACKUP", 0x99990000, 2_000_000_000_000, 1_800_000_000_000, true, false);
|
||||
internal static readonly CardDevice Usb = new(@"G:\", "BACKUP", 0x99990000, 2_000_000_000_000, 1_800_000_000_000, true, false);
|
||||
|
||||
public CardPoolTests() => Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
|
||||
@@ -77,25 +77,6 @@ public sealed class CardPoolTests
|
||||
Assert.Equal(@"Folder · D:\Shoots\2026", pool[2].ToolTip);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PathsAndSerialsStayLeftToRightInARightToLeftLanguage()
|
||||
{
|
||||
try
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("he"));
|
||||
var pool = CardPool.Build([Usb with { Label = string.Empty }, CardA], [], @"D:\Shoots\");
|
||||
Assert.Equal("\u202AG:\\\u202C", pool[1].Title, "a drive root keeps its separator at its end");
|
||||
Assert.Equal("\u202AD:\\Shoots\\\u202C", pool[2].Title);
|
||||
Assert.Equal("\u202AD:\\Shoots\\\u202C", pool[2].Subtitle);
|
||||
Assert.Contains("\u202A3F2A-9C11\u202C", pool[0].IdentityText);
|
||||
Assert.Equal("EOS_DIGITAL", pool[0].Title, "a label is left to bidi");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AKnownCardWithoutDcimIsStillACard()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
using System.Globalization;
|
||||
using Titano.App.Import;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Testing;
|
||||
using static Titano.App.Tests.Import.CardPoolTests;
|
||||
using static Titano.App.Tests.Import.ImportPlansTests;
|
||||
|
||||
namespace Titano.App.Tests.Import;
|
||||
|
||||
/// <summary>
|
||||
/// Import texts in a right-to-left language. They switch the process-wide UI language, so the class is serial: in
|
||||
/// parallel it would race with the English assertions of the classes running beside it.
|
||||
/// </summary>
|
||||
[Serial]
|
||||
public sealed class ImportLanguageTests
|
||||
{
|
||||
public ImportLanguageTests() => Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
|
||||
[Test]
|
||||
public void PathsAndSerialsStayLeftToRightInARightToLeftLanguage()
|
||||
{
|
||||
try
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("he"));
|
||||
var pool = CardPool.Build([Usb with { Label = string.Empty }, CardA], [], @"D:\Shoots\");
|
||||
Assert.Equal("\u202AG:\\\u202C", pool[1].Title, "a drive root keeps its separator at its end");
|
||||
Assert.Equal("\u202AD:\\Shoots\\\u202C", pool[2].Title);
|
||||
Assert.Equal("\u202AD:\\Shoots\\\u202C", pool[2].Subtitle);
|
||||
Assert.Contains("\u202A3F2A-9C11\u202C", pool[0].IdentityText);
|
||||
Assert.Equal("EOS_DIGITAL", pool[0].Title, "a label is left to bidi");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ARightToLeftLanguageReadsTheSessionTimesWithItsOwnArrow()
|
||||
{
|
||||
var plan = ThreeSessions();
|
||||
Assert.Contains("→", ImportPlans.Sessions(plan, ImportDestinationKind.Archive, new HashSet<string>())[0].TimeText);
|
||||
try
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("he"));
|
||||
var time = ImportPlans.Sessions(plan, ImportDestinationKind.Archive, new HashSet<string>())[0].TimeText;
|
||||
Assert.Contains("←", time);
|
||||
Assert.False(time.Contains('→'), "a right-to-left reader would see the arrow point back to the start");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ public sealed class ImportPlansTests
|
||||
{
|
||||
public ImportPlansTests() => Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
|
||||
private static ImportPlan ThreeSessions(long? available = 200_000_000)
|
||||
internal static ImportPlan ThreeSessions(long? available = 200_000_000)
|
||||
{
|
||||
var duplicate = Guid.CreateVersion7();
|
||||
return Plan(available, [new ImportProblem("DCIM/100CANON/IMG_0099.CR2", "Access denied")],
|
||||
@@ -140,24 +140,6 @@ public sealed class ImportPlansTests
|
||||
Assert.Equal("Split at IMG_0002.CR2", file.SplitName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ARightToLeftLanguageReadsTheSessionTimesWithItsOwnArrow()
|
||||
{
|
||||
var plan = ThreeSessions();
|
||||
Assert.Contains("→", ImportPlans.Sessions(plan, ImportDestinationKind.Archive, new HashSet<string>())[0].TimeText);
|
||||
try
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("he"));
|
||||
var time = ImportPlans.Sessions(plan, ImportDestinationKind.Archive, new HashSet<string>())[0].TimeText;
|
||||
Assert.Contains("←", time);
|
||||
Assert.False(time.Contains('→'), "a right-to-left reader would see the arrow point back to the start");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheNamePreviewShowsTheFirstThreeCopiedFiles()
|
||||
{
|
||||
|
||||
@@ -1,8 +1,19 @@
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.App.Tests;
|
||||
|
||||
internal static class TestMain
|
||||
{
|
||||
public static Task<int> Main(string[] args) => TestRunner.RunAsync(args, typeof(TestMain).Assembly);
|
||||
public static Task<int> 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.
|
||||
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");
|
||||
};
|
||||
return TestRunner.RunAsync(args, typeof(TestMain).Assembly);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user