L1a: Core und Module von WinForms entkoppeln - net10.0 statt net10.0-windows
Core, alle drei Module und das Testprojekt tragen keinen UI-Code mehr und bauen fuer linux-x64. Nur noch IBKRTrader.App ist Windows-gebunden. UI-Contract toolkit-neutral (Vorbild: PolytraderSharp): - ModuleView.CreateForm (Func<Form>) -> CreateView (Func<object>) - ModuleView.Icon (System.Drawing.Image) -> IconKey (string). System.Drawing.Common ist seit .NET 7 Windows-only und wirft auf Linux. - WindowMenu.cs war reine WinForms-Umsetzung -> in die Shell verschoben. LoggingService haelt keine RichTextBox mehr, sondern meldet Eintraege ueber event EntryWritten. Einfaerbung und UI-Thread-Wechsel liegen jetzt im LogPanelController der Shell. Nebenbei: ToUpper() -> ToUpperInvariant() (tr-TR haette aus "info" ein "İNFO" gemacht) und \r\n -> Environment.NewLine. Die drei Modul-Fenster liegen jetzt unter UI/Views/Modules/; RegisterUi der Module ist bewusst leer, die Shell registriert sie zentral ueber UI/ModuleViews.cs (nur fuer tatsaechlich geladene Module). ViewIcons loest IconKey gegen die PNG-Ressourcen auf - dieselben Schluessel bekommt spaeter die Avalonia-Shell. UiConstructionTests entfernt: die Konstruktionspruefung deckt --smoke-ui ab, das Testprojekt braucht dafuer keine UI-Referenz mehr. Der Test RegisterUi_RegistersMainView haelt jetzt das Gegenteil fest - das Modul darf nichts registrieren, sonst waere es wieder toolkit-gebunden. Verifiziert: Build 0 Fehler/0 Warnungen, 163 Tests gruen, --smoke-ui konstruiert alle 7 Fenster, und Core + 3 Module + Tests bauen fuer linux-x64. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- net10.0-windows + WinForms, weil das Testprojekt die WinForms-Hauptassembly referenziert -->
|
||||
<TargetFramework>net10.0-windows</TargetFramework>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<!-- Plattformneutral: die Tests decken Core und Module ab, die beide keinen UI-Code mehr
|
||||
tragen. Die UI-Konstruktionsprüfung liegt jetzt beim Smoke-UI-Lauf der Shell. -->
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
|
||||
@@ -55,17 +55,17 @@ public class CongressTradingModuleTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegisterUi_RegistersMainView()
|
||||
public void RegisterUi_RegistriertNichts_DamitDasModulPlattformneutralBleibt()
|
||||
{
|
||||
// Absicht, kein Versehen: würde das Modul sein Fenster selbst erzeugen, müsste es das
|
||||
// UI-Toolkit referenzieren – und wäre damit nicht mehr kopflos auf Linux lauffähig.
|
||||
// Das Fenster registriert die Shell zentral (App: UI/ModuleViews.cs).
|
||||
var host = new CapturingUiHost();
|
||||
// CreateForm wird hier NICHT aufgerufen – daher genügt ein leerer Provider.
|
||||
var provider = new ServiceCollection().BuildServiceProvider();
|
||||
|
||||
new CongressTradingModule().RegisterUi(host, provider);
|
||||
|
||||
host.Views.Should().ContainSingle();
|
||||
host.Views[0].Id.Should().Be("congresstrading.main");
|
||||
host.Views[0].Title.Should().Be("Congress Trading");
|
||||
host.Views.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
using FluentAssertions;
|
||||
using IBKRTrader.Core.Logging;
|
||||
using IBKRTrader.Core.Persistence;
|
||||
using IBKRTrader.Core.Persistence.Ef;
|
||||
using IBKRTrader.Modules.Accounting.Persistence;
|
||||
using IBKRTrader.Modules.Accounting.Services;
|
||||
using IBKRTrader.Modules.Accounting.Ui;
|
||||
using IBKRTrader.Modules.Supervisor.Agent;
|
||||
using IBKRTrader.Modules.Supervisor.Persistence;
|
||||
using IBKRTrader.Modules.Supervisor.Services;
|
||||
using IBKRTrader.Modules.Supervisor.Ui;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace IBKRTrader.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Konstruiert die neuen Modul-Fenster mit In-Memory-/Stub-Abhängigkeiten – gleichwertig zum
|
||||
/// Headless-Smoke-UI-Check (`--smoke-ui`), aber ohne die laufende App/DB. Forms bauen im Konstruktor
|
||||
/// nur Controls (DB-Zugriff erst auf Interaktion), daher genügt Instanziierbarkeit der Services.
|
||||
/// </summary>
|
||||
[Trait("cat", "unit")]
|
||||
public class UiConstructionTests
|
||||
{
|
||||
private sealed class Factory<T>(DbContextOptions<T> options) : IDbContextFactory<T> where T : DbContext
|
||||
{
|
||||
public T CreateDbContext() => (T)Activator.CreateInstance(typeof(T), options)!;
|
||||
}
|
||||
|
||||
private static Factory<T> InMemory<T>() where T : DbContext =>
|
||||
new(new DbContextOptionsBuilder<T>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options);
|
||||
|
||||
private sealed class NoChat : IChatCompletionClient
|
||||
{
|
||||
public Task<ChatResponse> CompleteAsync(string m, IReadOnlyList<ChatMessage> msgs,
|
||||
IReadOnlyList<SupervisorTool> tools, CancellationToken ct) => Task.FromResult(new ChatResponse());
|
||||
}
|
||||
|
||||
private static Exception? ConstructOnSta(Action action)
|
||||
{
|
||||
Exception? captured = null;
|
||||
var t = new Thread(() => { try { action(); } catch (Exception ex) { captured = ex; } });
|
||||
t.SetApartmentState(ApartmentState.STA);
|
||||
t.Start();
|
||||
t.Join();
|
||||
return captured;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AccountingMainForm_Constructs()
|
||||
{
|
||||
var ex = ConstructOnSta(() =>
|
||||
{
|
||||
var logger = new LoggingService();
|
||||
var accDbf = InMemory<AccountingDbContext>();
|
||||
var ledger = new EfLedgerRepository(accDbf);
|
||||
var runs = new EfIngestRunRepository(accDbf);
|
||||
var report = new AccountingReportService(ledger, new EfFxRateRepository(accDbf));
|
||||
var ingest = new AccountingIngestService(
|
||||
new NullAccountSource(), ledger, runs, new EfRawSnapshotRepository(accDbf),
|
||||
new NullStatementSource(), new NullBalanceAnchorSource(), logger);
|
||||
|
||||
using var form = new AccountingMainForm(ledger, runs, report, ingest, logger);
|
||||
form.Text.Should().Be("Accounting");
|
||||
});
|
||||
ex.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SupervisorMainForm_Constructs()
|
||||
{
|
||||
var ex = ConstructOnSta(() =>
|
||||
{
|
||||
var logger = new LoggingService();
|
||||
var coreDbf = InMemory<CoreDbContext>();
|
||||
var supDbf = InMemory<SupervisorDbContext>();
|
||||
IDecisionJournal journal = new EfDecisionJournal(coreDbf, logger);
|
||||
IOrderEventLog orderLog = new EfOrderEventLog(coreDbf, logger);
|
||||
var dossiers = new DossierService(journal, orderLog, new TradeLogReader(coreDbf));
|
||||
var agent = new SupervisorAgent(new NoChat(), new SupervisorToolRegistry());
|
||||
var reports = new EfSupervisorReportRepository(supDbf, logger);
|
||||
|
||||
using var form = new SupervisorMainForm(agent, dossiers, reports, logger);
|
||||
form.Text.Should().Be("Supervisor");
|
||||
});
|
||||
ex.Should().BeNull();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user