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>
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
using AvParser.UI.ViewModels;
|
||||
|
||||
namespace AvParser.UI.Tests.Fakes;
|
||||
|
||||
/// <summary>A navigation destination with no behaviour, for exercising the shell and the stack.</summary>
|
||||
internal sealed class FakePage(string title, string iconKey = "IconHome") : PageViewModel
|
||||
{
|
||||
public override string Title { get; } = title;
|
||||
|
||||
public override string IconKey { get; } = iconKey;
|
||||
}
|
||||
|
||||
/// <summary>A second page type, so <c>NavigateTo<TPage>()</c> has something to discriminate on.</summary>
|
||||
internal sealed class OtherFakePage : PageViewModel
|
||||
{
|
||||
public override string Title => "Other";
|
||||
|
||||
public override string IconKey => "IconInfo";
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using AvParser.Core.Settings;
|
||||
using ReactiveUI.Primitives.Signals;
|
||||
|
||||
namespace AvParser.UI.Tests.Fakes;
|
||||
|
||||
/// <summary>In-memory settings, so tests never touch the developer's real profile.</summary>
|
||||
internal sealed class FakeSettingsService(AppSettings? initial = null) : ISettingsService, IDisposable
|
||||
{
|
||||
private readonly BehaviorSignal<AppSettings> _current = new(initial ?? new AppSettings());
|
||||
|
||||
public AppSettings Current => _current.Value;
|
||||
|
||||
public IObservable<AppSettings> Changes => _current;
|
||||
|
||||
/// <summary>How many times <see cref="FlushAsync"/> was called.</summary>
|
||||
public int FlushCount { get; private set; }
|
||||
|
||||
/// <summary>Every value the settings have taken, oldest first.</summary>
|
||||
public List<AppSettings> History { get; } = [];
|
||||
|
||||
public void Update(Func<AppSettings, AppSettings> mutate)
|
||||
{
|
||||
var next = mutate(_current.Value);
|
||||
History.Add(next);
|
||||
_current.OnNext(next);
|
||||
}
|
||||
|
||||
public Task FlushAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
FlushCount++;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public void Dispose() => _current.Dispose();
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using AvParser.Core.Settings;
|
||||
using AvParser.UI.Services;
|
||||
using ReactiveUI.Primitives.Signals;
|
||||
|
||||
namespace AvParser.UI.Tests.Fakes;
|
||||
|
||||
/// <summary>Theme service with no Avalonia <c>Application</c> behind it.</summary>
|
||||
internal sealed class FakeThemeService(AppTheme initial = AppTheme.System) : IThemeService, IDisposable
|
||||
{
|
||||
private readonly BehaviorSignal<AppTheme> _current = new(initial);
|
||||
|
||||
public AppTheme Current => _current.Value;
|
||||
|
||||
public IObservable<AppTheme> Changes => _current;
|
||||
|
||||
public void Apply(AppTheme theme)
|
||||
{
|
||||
if (theme == _current.Value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_current.OnNext(theme);
|
||||
}
|
||||
|
||||
public void Dispose() => _current.Dispose();
|
||||
}
|
||||
Reference in New Issue
Block a user