SonarCloud's gate asks for 80% coverage on new code, and the first push had 22.5%: most of the new code only runs inside WPF. New tests run it on an STA thread against WPF-UI's own styles and templates, with no window shown: the names given to template parts, the glyphs kept out of the automation tree, the decorative peers, the Ctrl+Q scope, the screen-reader notification, and the font and contrast resources. A WPF-UI update that renames one of those parts now fails a test instead of silently undoing the fix. The seams for that: WpfUiAccessibility.Apply (what the class handlers run), ScreenReader.Raise and RaiseOnActiveWindow, FontScaleService taking its text-size reader and the resources it writes, ThemeService.ApplyDimming taking the resources. The tests also showed that WPF-UI 4.3 has a single button for Maximize and Restore down, drawn as Restore down while the window is maximized; its name now follows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
37 lines
964 B
C#
37 lines
964 B
C#
using System.Runtime.ExceptionServices;
|
|
using System.Windows.Threading;
|
|
|
|
namespace CommandForge.Tests;
|
|
|
|
/// <summary>
|
|
/// Runs a test's body on a thread of its own in a single-threaded apartment, where WPF elements can
|
|
/// be created, and rethrows what it threw. No window is shown.
|
|
/// </summary>
|
|
internal static class Sta
|
|
{
|
|
public static void Run(Action body)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(body);
|
|
ExceptionDispatchInfo? failure = null;
|
|
var thread = new Thread(() =>
|
|
{
|
|
try
|
|
{
|
|
body();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
failure = ExceptionDispatchInfo.Capture(ex);
|
|
}
|
|
finally
|
|
{
|
|
Dispatcher.CurrentDispatcher.InvokeShutdown();
|
|
}
|
|
});
|
|
thread.SetApartmentState(ApartmentState.STA);
|
|
thread.Start();
|
|
thread.Join();
|
|
failure?.Throw();
|
|
}
|
|
}
|