Add DI container and view-model tests

Add a composition-root test that builds the provider with ValidateOnBuild to catch missing registrations (without touching the real hardware monitor), plus per-service registration assertions. Add a MainWindowViewModel test that constructs the view model entirely from faked IHardwareMonitorService/ILogger/IRemoteWebServer, proving the testability win. To make that possible, inject the UI DispatcherQueue (captured on the UI thread by the composition factory) instead of calling the static DispatcherQueue.GetForCurrentThread() in the view-model constructor, which threw in the headless test host; the tree-rebuild marshalling now treats a null dispatcher as direct invocation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-06-02 15:20:40 -05:00
co-authored by Copilot
parent 3e71e09a25
commit dcb6a5b803
4 changed files with 98 additions and 5 deletions
@@ -83,7 +83,7 @@ public sealed class MainWindowViewModel : ViewModelBase, IDisposable
];
private readonly IHardwareMonitorService _hardwareMonitor;
private readonly DispatcherQueue _dispatcherQueue;
private readonly DispatcherQueue? _dispatcherQueue;
private readonly ILogger _logger;
private readonly PlotTrackingService _plotTracking;
private readonly SensorSelectionService _sensorSelection;
@@ -125,12 +125,13 @@ public sealed class MainWindowViewModel : ViewModelBase, IDisposable
IRemoteWebServer remoteWebServer,
PlotTrackingService plotTracking,
StartupService startupService,
IStartupTracer startupTrace)
IStartupTracer startupTrace,
DispatcherQueue? dispatcherQueue = null)
{
Settings = settings;
_startupTrace = startupTrace;
_startupTrace.Mark("MainWindowViewModel.Constructor.Begin");
_dispatcherQueue = DispatcherQueue.GetForCurrentThread();
_dispatcherQueue = dispatcherQueue;
_hardwareMonitor = hardwareMonitor;
_logger = logger;
_sensorSelection = sensorSelection;
@@ -941,7 +942,7 @@ public sealed class MainWindowViewModel : ViewModelBase, IDisposable
private void HardwareMonitor_TreeRebuilt(object? sender, EventArgs e)
{
if (_dispatcherQueue.HasThreadAccess)
if (_dispatcherQueue is null || _dispatcherQueue.HasThreadAccess)
{
UpdateRoot();
UpdateStatus();