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,47 @@
|
||||
using System.Linq;
|
||||
using PolyTrader.Modules.CopyTrading.Persistence.Ef;
|
||||
using PolyTrader.Tests.TestSupport;
|
||||
using PolyTraderSharp.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace PolyTrader.Tests
|
||||
{
|
||||
public class CopyTradeLogRepositoryTests
|
||||
{
|
||||
private static EfCopyTradeLogRepository NewRepo() =>
|
||||
new(new InMemoryContextFactory<CopyTradingDbContext>(o => new CopyTradingDbContext(o)));
|
||||
|
||||
[Fact]
|
||||
public void Insert_and_Find_returns_all()
|
||||
{
|
||||
var repo = NewRepo();
|
||||
repo.Insert(new ClosedTrade { TradeId = 1, AccountId = 1, TokenId = "a" });
|
||||
repo.Insert(new ClosedTrade { TradeId = 2, AccountId = 1, TokenId = "b" });
|
||||
|
||||
Assert.Equal(2, repo.Find(_ => true).Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Exists_is_true_for_matching_account_and_token()
|
||||
{
|
||||
var repo = NewRepo();
|
||||
repo.Insert(new ClosedTrade { TradeId = 1, AccountId = 5, TokenId = "tok" });
|
||||
|
||||
Assert.True(repo.Exists(5, "tok"));
|
||||
Assert.False(repo.Exists(5, "other"));
|
||||
Assert.False(repo.Exists(9, "tok"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Find_applies_predicate()
|
||||
{
|
||||
var repo = NewRepo();
|
||||
repo.Insert(new ClosedTrade { TradeId = 1, AccountId = 1, RealizedPnl = 10m });
|
||||
repo.Insert(new ClosedTrade { TradeId = 2, AccountId = 1, RealizedPnl = -3m });
|
||||
|
||||
var winners = repo.Find(t => t.RealizedPnl > 0);
|
||||
Assert.Single(winners);
|
||||
Assert.Equal(1, winners[0].TradeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user