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,61 @@
|
||||
using PolyTrader.Modules.CopyTrading.Persistence.Ef;
|
||||
using PolyTrader.Tests.TestSupport;
|
||||
using PolyTraderSharp.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace PolyTrader.Tests
|
||||
{
|
||||
public class AccountSettingsRepositoryTests
|
||||
{
|
||||
private static EfCopyTradingAccountSettingsRepository NewRepo() =>
|
||||
new(new InMemoryContextFactory<CopyTradingDbContext>(o => new CopyTradingDbContext(o)));
|
||||
|
||||
[Fact]
|
||||
public void Upsert_and_Get_persists_decimal_values()
|
||||
{
|
||||
var repo = NewRepo();
|
||||
repo.Upsert(new CopyTradingAccountSettings
|
||||
{
|
||||
AccountId = 1,
|
||||
PerMarketLimit = 0.5m,
|
||||
PerMasterLimit = 15m,
|
||||
MaxBuyPrice = 98m,
|
||||
PreRedeemLimit = 99.5m
|
||||
});
|
||||
|
||||
var s = repo.Get(1);
|
||||
Assert.NotNull(s);
|
||||
Assert.Equal(0.5m, s!.PerMarketLimit);
|
||||
Assert.Equal(15m, s.PerMasterLimit);
|
||||
Assert.Equal(98m, s.MaxBuyPrice);
|
||||
Assert.Equal(99.5m, s.PreRedeemLimit);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Get_returns_null_when_missing()
|
||||
{
|
||||
var repo = NewRepo();
|
||||
Assert.Null(repo.Get(42));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Upsert_updates_existing_without_duplicating()
|
||||
{
|
||||
var repo = NewRepo();
|
||||
repo.Upsert(new CopyTradingAccountSettings { AccountId = 1, PerMarketLimit = 1m });
|
||||
repo.Upsert(new CopyTradingAccountSettings { AccountId = 1, PerMarketLimit = 2m });
|
||||
|
||||
Assert.Single(repo.GetAll());
|
||||
Assert.Equal(2m, repo.Get(1)!.PerMarketLimit);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Delete_removes_settings()
|
||||
{
|
||||
var repo = NewRepo();
|
||||
repo.Upsert(new CopyTradingAccountSettings { AccountId = 1 });
|
||||
repo.Delete(1);
|
||||
Assert.Empty(repo.GetAll());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user