- 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>
54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
using System.Linq;
|
|
using PolyTrader.Core.Persistence.Ef;
|
|
using PolyTrader.Tests.TestSupport;
|
|
using PolyTraderSharp.Models;
|
|
using Xunit;
|
|
|
|
namespace PolyTrader.Tests
|
|
{
|
|
public class AccountRepositoryTests
|
|
{
|
|
private static EfAccountRepository NewRepo() =>
|
|
new(new InMemoryContextFactory<CoreDbContext>(o => new CoreDbContext(o)));
|
|
|
|
[Fact]
|
|
public void Upsert_inserts_and_reads_back_account()
|
|
{
|
|
var repo = NewRepo();
|
|
repo.Upsert(new AccountState
|
|
{
|
|
AccountId = 1,
|
|
Name = "Richard Test",
|
|
WalletAddress = "0xabc",
|
|
IsDemo = false,
|
|
TotalBalance = 64.763626m
|
|
});
|
|
|
|
var acc = repo.GetAll().Single();
|
|
Assert.Equal("Richard Test", acc.Name);
|
|
Assert.Equal(64.763626m, acc.TotalBalance);
|
|
}
|
|
|
|
[Fact]
|
|
public void Upsert_updates_existing_without_duplicating()
|
|
{
|
|
var repo = NewRepo();
|
|
repo.Upsert(new AccountState { AccountId = 1, Name = "A" });
|
|
repo.Upsert(new AccountState { AccountId = 1, Name = "B" });
|
|
|
|
var all = repo.GetAll();
|
|
Assert.Single(all);
|
|
Assert.Equal("B", all[0].Name);
|
|
}
|
|
|
|
[Fact]
|
|
public void Delete_removes_account()
|
|
{
|
|
var repo = NewRepo();
|
|
repo.Upsert(new AccountState { AccountId = 1 });
|
|
repo.Delete(1);
|
|
Assert.Empty(repo.GetAll());
|
|
}
|
|
}
|
|
}
|