Files
Leonid PershinandClaude Opus 5 3db9d4dfc6 Scaffold AvParser: Avalonia 12 shell with adaptive layout
Greenfield skeleton for a parser desktop app. The domain is deliberately a
placeholder — IParser<TIn,TOut> plus two sample parsers — so the shell is
runnable and verifiable end to end before real logic lands.

Layers run one way: Core (no Avalonia, no IO) <- Infrastructure <- UI <- Desktop.
UI is a class library rather than the exe so headless tests build real views
without dragging in Program.cs, Serilog or the container.

Adaptive layout is built from what Avalonia actually offers, since it has no
AdaptiveTrigger or media queries: ResponsiveLayout observes Visual.Bounds and
projects a breakpoint onto both an attached property and :compact/:medium/
:expanded pseudoclasses, with 24px hysteresis so dragging a window edge cannot
make the layout flap. Pane state lives in the view model because a style setter
loses to a local value permanently; styles own only the visual variance.

Stack notes worth remembering: Avalonia.ReactiveUI is deprecated in favour of
ReactiveUI.Avalonia, and ReactiveUI 24 runs on the Primitives engine (RxVoid,
ISequencer, Signal<T>) and no longer self-initialises. Avalonia.Headless.XUnit
12.x requires xUnit v3. InvariantGlobalization must stay false or Semi.Avalonia
throws in its static constructor.

102 tests across three projects, including headless guards for the two failures
that are otherwise completely silent: a stylesheet whose selectors match nothing,
and a light palette too low-contrast for cards to read.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-13 16:07:08 +03:00

45 lines
1.6 KiB
C#

using Avalonia;
using Avalonia.Headless;
using Avalonia.Markup.Xaml.Styling;
using AvParser.UI.HeadlessTests;
using ReactiveUI.Avalonia;
using Semi.Avalonia;
[assembly: AvaloniaTestApplication(typeof(TestAppBuilder))]
// The headless platform is one dispatcher per assembly; running collections in parallel produces
// intermittent "call from invalid thread" failures rather than useful signal.
[assembly: CollectionBehavior(DisableTestParallelization = true)]
namespace AvParser.UI.HeadlessTests;
/// <summary>Boots a headless Avalonia application for <c>[AvaloniaFact]</c> tests.</summary>
public static class TestAppBuilder
{
/// <summary>Called by Avalonia.Headless.XUnit once per test assembly.</summary>
public static AppBuilder BuildAvaloniaApp() =>
AppBuilder
.Configure<HeadlessTestApp>()
.UseHeadless(new AvaloniaHeadlessPlatformOptions())
.UseReactiveUI(_ => { });
}
/// <summary>
/// A minimal application that loads the real styles but never touches the DI container.
/// </summary>
/// <remarks>
/// Deliberately not <c>AvParser.Desktop.App</c>: these tests should exercise the views and the
/// stylesheet, not Serilog, the settings file or the composition root. Styles are added in code
/// rather than XAML so the test project needs no Avalonia XAML compilation of its own.
/// </remarks>
public sealed class HeadlessTestApp : Application
{
/// <inheritdoc />
public override void Initialize()
{
Styles.Add(new SemiTheme());
var index = new Uri("avares://AvParser.UI/Styles/Index.axaml");
Styles.Add(new StyleInclude(index) { Source = index });
}
}