Phase 7: Testprojekt (xUnit) + Repository-Tests
- Neues Projekt tests/PolyTrader.Tests (xUnit, EF Core InMemory-Provider),
zur Solution hinzugefügt.
- InMemoryContextFactory<TContext>: Test-IDbContextFactory (isolierte In-Memory-DB
je Test, geteilt über alle Kontexte einer Factory – wie im echten Betrieb).
- 18 Tests über die EF-Repos:
- TrackedTrader: Upsert insert/update ohne Duplikat, Delete,
AssignedAccountIds-JSON-Round-Trip (Value-Converter) + Set-Ersetzung.
- CopyTradingAccountSettings: Upsert/Get (Dezimalwerte), Get-null, Delete.
- CopyTradeLog: Insert/Find, Exists-Dedup (Account+Token), Predikat-Filter.
- MasterTraderHistory: Exists-Zeitfenster, GetByTraderSince-Cutoff.
- Core Accounts: Upsert insert/update, Delete.
- Alle 18 grün.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
e27a659529
commit
ca16cd8a91
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace PolyTrader.Tests.TestSupport
|
||||
{
|
||||
/// <summary>
|
||||
/// Test-Implementierung von <see cref="IDbContextFactory{TContext}"/> auf Basis des
|
||||
/// EF-Core-InMemory-Providers. Jede Factory-Instanz nutzt eine eigene (per GUID benannte)
|
||||
/// In-Memory-DB, sodass Tests voneinander isoliert sind; alle vom selben Factory erzeugten
|
||||
/// Kontexte teilen sich die gleiche Datenbank (wie im echten Betrieb der DbContextFactory).
|
||||
/// </summary>
|
||||
public sealed class InMemoryContextFactory<TContext> : IDbContextFactory<TContext>
|
||||
where TContext : DbContext
|
||||
{
|
||||
private readonly Func<DbContextOptions<TContext>, TContext> _ctor;
|
||||
private readonly DbContextOptions<TContext> _options;
|
||||
|
||||
public InMemoryContextFactory(Func<DbContextOptions<TContext>, TContext> ctor)
|
||||
{
|
||||
_ctor = ctor;
|
||||
_options = new DbContextOptionsBuilder<TContext>()
|
||||
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
||||
.EnableSensitiveDataLogging()
|
||||
.Options;
|
||||
}
|
||||
|
||||
public TContext CreateDbContext() => _ctor(_options);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user