Files
IBKRTrader/tests/IBKRTrader.Tests/Modules/CongressTradingModuleTests.cs
T
Richard 8f44c0fd82 @
R2: Generic Host + Modul-Vertrag + Shell-UI (PolytraderSharp-Konzept)

- Core/Modularity: neuer IModule (Name, DbPrefix, RegisterServices(services,config),
  RegisterUi(host,sp), StartAsync/StopAsync, GetActivationBlocker) + ModuleView
  + IModuleUiHost + WindowMenu. Alte IModule/ModuleRegistry/WindowManager/ModuleFormBase entfernt.
- Program.cs: Host.CreateDefaultBuilder + IConfiguration (appsettings.json/.Local.json);
  Core-Services registriert, Module via RegisterServices, Views via RegisterUi.
- UI: ShellUiHost (Einzelinstanz-Fenster + Fenster-Menue), LauncherForm als Shell
  (Buttons je View), Core-Views Logs/Settings/Workers als eigene Fenster.
- CongressTrading auf neuen Vertrag; Worker als IWorker registriert.
- --smoke-ui Headless-Test (konstruiert jede View + Launcher).
- appsettings.Local.json gitignored.
- Tests angepasst -> 30/30 gruen; Build + Smoke-UI + App-Start verifiziert.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@
2026-07-28 00:24:00 +02:00

80 lines
2.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using FluentAssertions;
using IBKRTrader.Core.Modularity;
using IBKRTrader.Core.Workers;
using IBKRTrader.Modules.CongressTrading;
using IBKRTrader.Modules.CongressTrading.Database;
using IBKRTrader.Modules.CongressTrading.Scraper;
using IBKRTrader.Modules.CongressTrading.Workers;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using NSubstitute;
namespace IBKRTrader.Tests.Modules;
[Trait("cat", "unit")]
public class CongressTradingModuleTests
{
private sealed class CapturingUiHost : IModuleUiHost
{
private readonly List<ModuleView> _views = new();
public IReadOnlyList<ModuleView> Views => _views;
public void RegisterView(ModuleView view) => _views.Add(view);
public bool IsOpen(string viewId) => false;
public void OpenView(string viewId) { }
public void ActivateMain() { }
public void RequestShutdown() { }
public event Action? OpenStateChanged { add { } remove { } }
}
[Fact]
public void Metadata_IsAsExpected()
{
var module = new CongressTradingModule();
module.Name.Should().Be("CongressTrading");
module.DbPrefix.Should().Be("ct_");
}
[Fact]
public void RegisterServices_RegistersServicesAndWorkers()
{
var services = new ServiceCollection();
new CongressTradingModule().RegisterServices(services, Substitute.For<IConfiguration>());
var types = services.Select(d => d.ServiceType).ToList();
types.Should().Contain(new[]
{
typeof(CongressMigrations),
typeof(CongressRepository),
typeof(CapitolTradesScraper),
typeof(CongressHistoryImportWorker),
typeof(CongressScrapeWorker),
});
// Worker werden zusätzlich als IWorker registriert (für die WorkerEngine).
services.Count(d => d.ServiceType == typeof(IWorker)).Should().Be(2);
}
[Fact]
public void RegisterUi_RegistersMainView()
{
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");
}
[Fact]
public void GetActivationBlocker_DefaultsToNull()
{
// Default-Interface-Methode → über die Interface-Referenz aufrufen.
IModule module = new CongressTradingModule();
module.GetActivationBlocker(Substitute.For<IConfiguration>()).Should().BeNull();
}
}