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,52 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using PolyTrader.Core.Persistence.Ef;
|
||||
using PolyTrader.Tests.TestSupport;
|
||||
using PolyTraderSharp.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace PolyTrader.Tests
|
||||
{
|
||||
public class TradeLogRepositoryTests
|
||||
{
|
||||
private static EfTradeLogRepository NewRepo() =>
|
||||
new(new InMemoryContextFactory<CoreDbContext>(o => new CoreDbContext(o)));
|
||||
|
||||
[Fact]
|
||||
public void GetRecent_orders_by_closed_at_descending_and_limits()
|
||||
{
|
||||
var repo = NewRepo();
|
||||
var t = new DateTime(2026, 7, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
repo.Insert(new TradeRecord { Id = "a", ClosedAt = t.AddHours(1) });
|
||||
repo.Insert(new TradeRecord { Id = "b", ClosedAt = t.AddHours(3) });
|
||||
repo.Insert(new TradeRecord { Id = "c", ClosedAt = t.AddHours(2) });
|
||||
|
||||
var recent = repo.GetRecent(2);
|
||||
|
||||
Assert.Equal(2, recent.Count);
|
||||
Assert.Equal("b", recent[0].Id);
|
||||
Assert.Equal("c", recent[1].Id);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Find_filters_by_module_name()
|
||||
{
|
||||
var repo = NewRepo();
|
||||
repo.Insert(new TradeRecord { Id = "a", ModuleName = "CopyTrading" });
|
||||
repo.Insert(new TradeRecord { Id = "b", ModuleName = "Other" });
|
||||
|
||||
var ct = repo.Find(x => x.ModuleName == "CopyTrading");
|
||||
Assert.Single(ct);
|
||||
Assert.Equal("a", ct[0].Id);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Generated_id_is_unique_per_record()
|
||||
{
|
||||
var a = new TradeRecord();
|
||||
var b = new TradeRecord();
|
||||
Assert.False(string.IsNullOrEmpty(a.Id));
|
||||
Assert.NotEqual(a.Id, b.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user