Phase 7: Tests erweitert + Mongo-Parser extrahiert (testbar)
Tests (jetzt 48 grün): - DbContextMappingTests: sichert core_/mod_-Tabellennamen, Position-Composite-Key, TrackedTrader-Key, ClosedTradeRow nicht gemappt, AccountState.OpenPositions ignoriert. - PositionRepositoryTests: Live/Demo-Trennung, Upsert setzt Account+Demo-Flag, Update ohne Duplikat, DeleteLive, DropDemo. - MarketRepositoryTests: GetActive filtert Closed, Upsert-Update, FindByTokenId. - TradeLogRepositoryTests: GetRecent (Sortierung+Limit), Find-Predikat, Guid-Id unique. - MongoExportParserTests: String-Dezimale, null->"", fehlende Felder->Default, AssignedAccountIds-Array, Category-Default, Nicht-Array->leer. Refactor: - Mongo-Export-Parsing aus ConfigMigrator in testbare Klasse PolyTrader.Modules.CopyTrading.ConfigImport.MongoExportParser ausgelagert (ParseAccounts -> Account+Settings, ParseTraders). ConfigMigrator nutzt sie; --migrate-json end-to-end verifiziert (3/3/32). - PolyTrader.App.csproj: tests/** vom Default-Glob ausgeschlossen (App zog sonst die Testdateien mit rein -> doppelte AssemblyInfo/Xunit-Fehler). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
ca16cd8a91
commit
1b51872f00
@@ -0,0 +1,79 @@
|
||||
using System.Linq;
|
||||
using PolyTrader.Core.Persistence.Ef;
|
||||
using PolyTrader.Tests.TestSupport;
|
||||
using PolyTraderSharp.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace PolyTrader.Tests
|
||||
{
|
||||
public class PositionRepositoryTests
|
||||
{
|
||||
private static EfPositionRepository NewRepo() =>
|
||||
new(new InMemoryContextFactory<CoreDbContext>(o => new CoreDbContext(o)));
|
||||
|
||||
[Fact]
|
||||
public void Live_and_demo_positions_are_kept_separate_per_account()
|
||||
{
|
||||
var repo = NewRepo();
|
||||
repo.UpsertLive(1, new Position { TokenId = "t1" });
|
||||
repo.UpsertDemo(1, new Position { TokenId = "t1" });
|
||||
repo.UpsertLive(2, new Position { TokenId = "t1" });
|
||||
|
||||
Assert.Single(repo.GetLive(1));
|
||||
Assert.Single(repo.GetDemo(1));
|
||||
Assert.Single(repo.GetLive(2));
|
||||
Assert.Empty(repo.GetDemo(2));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Upsert_sets_account_and_demo_flag_on_position()
|
||||
{
|
||||
var repo = NewRepo();
|
||||
repo.UpsertDemo(5, new Position { TokenId = "t1" });
|
||||
|
||||
var pos = repo.FindDemo(5, "t1");
|
||||
Assert.NotNull(pos);
|
||||
Assert.Equal(5, pos!.AccountId);
|
||||
Assert.True(pos.IsDemo);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Upsert_updates_existing_position_without_duplicating()
|
||||
{
|
||||
var repo = NewRepo();
|
||||
repo.UpsertLive(1, new Position { TokenId = "t1", Size = 10m });
|
||||
repo.UpsertLive(1, new Position { TokenId = "t1", Size = 20m });
|
||||
|
||||
var live = repo.GetLive(1);
|
||||
Assert.Single(live);
|
||||
Assert.Equal(20m, live[0].Size);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DeleteLive_removes_only_live()
|
||||
{
|
||||
var repo = NewRepo();
|
||||
repo.UpsertLive(1, new Position { TokenId = "t1" });
|
||||
repo.UpsertDemo(1, new Position { TokenId = "t1" });
|
||||
|
||||
repo.DeleteLive(1, "t1");
|
||||
|
||||
Assert.Empty(repo.GetLive(1));
|
||||
Assert.Single(repo.GetDemo(1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DropDemo_clears_only_demo_positions_of_account()
|
||||
{
|
||||
var repo = NewRepo();
|
||||
repo.UpsertDemo(1, new Position { TokenId = "t1" });
|
||||
repo.UpsertDemo(1, new Position { TokenId = "t2" });
|
||||
repo.UpsertLive(1, new Position { TokenId = "t3" });
|
||||
|
||||
repo.DropDemo(1);
|
||||
|
||||
Assert.Empty(repo.GetDemo(1));
|
||||
Assert.Single(repo.GetLive(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user