R7: Dashboard-View + DashboardService (Abschluss Feinschliff) - Core/Trading/DashboardService: aggregiert Positionen/Exposure/Trades via EF (DashboardSnapshot) - UI/Views/DashboardView: Trading-Modus, aggregierte Kennzahlen, geladene Module (+ Aktivierungs-Status) - core.dashboard-View registriert (Order 5) mit dashboard-Icon - Tests: DashboardService (leer + Aggregation, InMemory) -> 58/58 gruen; smoke-ui deckt alle 5 Views ab Kurskorrektur R1-R7 abgeschlossen: IBKRTrader folgt dem PolytraderSharp-Konzept. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> @
54 lines
1.8 KiB
C#
54 lines
1.8 KiB
C#
using FluentAssertions;
|
|
using IBKRTrader.Core.Persistence.Ef;
|
|
using IBKRTrader.Core.Persistence.Entities;
|
|
using IBKRTrader.Core.Trading;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace IBKRTrader.Tests.Trading;
|
|
|
|
[Trait("cat", "unit")]
|
|
public class DashboardServiceTests
|
|
{
|
|
private sealed class Factory(DbContextOptions<CoreDbContext> o) : IDbContextFactory<CoreDbContext>
|
|
{
|
|
public CoreDbContext CreateDbContext() => new(o);
|
|
}
|
|
|
|
private static (DashboardService sut, IDbContextFactory<CoreDbContext> factory) Create()
|
|
{
|
|
var opts = new DbContextOptionsBuilder<CoreDbContext>()
|
|
.UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;
|
|
var factory = new Factory(opts);
|
|
return (new DashboardService(factory), factory);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task EmptyDatabase_ReturnsZeros()
|
|
{
|
|
var (sut, _) = Create();
|
|
|
|
var snap = await sut.GetSnapshotAsync();
|
|
|
|
snap.Should().Be(new DashboardSnapshot(0, 0m, 0));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task AggregatesPositionsAndTrades()
|
|
{
|
|
var (sut, factory) = Create();
|
|
await using (var db = await factory.CreateDbContextAsync())
|
|
{
|
|
db.Positions.Add(new CorePosition { Module = "CT", Symbol = "AAPL", Quantity = 5, AvgPrice = 100m });
|
|
db.Positions.Add(new CorePosition { Module = "CT", Symbol = "MSFT", Quantity = 2, AvgPrice = 200m });
|
|
db.TradeHistory.Add(new CoreTrade { Module = "CT", Symbol = "AAPL", Action = "BUY", Quantity = 5, Price = 100m });
|
|
await db.SaveChangesAsync();
|
|
}
|
|
|
|
var snap = await sut.GetSnapshotAsync();
|
|
|
|
snap.OpenPositions.Should().Be(2);
|
|
snap.TotalExposure.Should().Be(900m); // 5*100 + 2*200
|
|
snap.TotalTrades.Should().Be(1);
|
|
}
|
|
}
|