refactor(swap-test): 抽取 TestableSwapEodPositionService 公共基类收敛重复 Stub

- 新建 TestableSwapEodPositionService 收敛 8/8 Stub 重复的高频 override
  (PersistEodSwapPosition/SaveAllChanges/GetCurrencyRate/AddClientCash)
  + 统一 OptUserInfo 构造 + PersistedPositions/SaveChangesCount 输出捕获
- SwapEodPositionService.DealInterests 改 protected virtual(行为零变化)
- 8 个 ScenarioTest 改为继承基类,删除重复 override
- 消灭 DealInterestsScenarioTest/DealInterestsGoldenReplayTest 的反射调用
  (typeof().GetMethod().Invoke → 直接调用 DealInterests)

验证:dotnet build 0 错误;dotnet test SwapModule 284通过/6跳过/0失败
This commit is contained in:
hjhan
2026-07-23 11:16:11 +08:00
parent 63d9decd17
commit 7b007bddfa
10 changed files with 109 additions and 109 deletions
@@ -22,13 +22,13 @@ namespace YLErp.Modules.SwapModule
#region Stub
private sealed class StubEodService : SwapEodPositionService
private sealed class StubEodService : TestableSwapEodPositionService
{
public List<eod_swap_position> CreatedEodPositions { get; } = new();
public int ClientCashCallCount { get; private set; }
private int _nextId = 1;
// 输出别名(转发到基类捕获属性,保持测试断言不变)
public List<eod_swap_position> CreatedEodPositions => PersistedPositions;
public int ClientCashCallCount => ClientCashCalls.Count;
public StubEodService() : base(new OptUserInfo(0, nameof(ComposePageScenarioTest), OptUserFrom.UnitTest))
public StubEodService() : base(nameof(ComposePageScenarioTest))
{
}
@@ -56,13 +56,7 @@ namespace YLErp.Modules.SwapModule
protected override swap_event AddSwapEvent(DateTime tradeDate, int swapTradeId, int eventType, string data, int clientCashId, bool save, string reason)
{
return new swap_event { id = _nextId++, SwapTradeId = swapTradeId, EventType = eventType, ValueDate = tradeDate, EventData = data };
}
protected override int AddClientCash(trade td, double amount, string action, DateTime valueDate)
{
ClientCashCallCount++;
return _nextId++;
return new swap_event { id = 1, SwapTradeId = swapTradeId, EventType = eventType, ValueDate = tradeDate, EventData = data };
}
protected override void SaveEodSwapRecord(trade td, DateTime settleDate, DateTime preSettleDate)
@@ -75,17 +69,6 @@ namespace YLErp.Modules.SwapModule
// 不做任何事(测试无历史事件需清理)
}
protected override void PersistEodSwapPosition(eod_swap_position position)
{
if (position.id == 0) position.id = _nextId++;
CreatedEodPositions.Add(position);
}
protected override void SaveAllChanges() { }
protected override double GetCurrencyRate(string quoteCurrency, string settlementCurrency, DateTime valueDate, bool seekPreday, CurrencyRateType currencyRateType)
=> 1.0;
// override SaveEodPosition:捕获生成的 eod,绕过 UpdateSwapPosition 连库
protected override decimal SaveEodPosition(eod_swap_position newEodPayPosition,
trade td, swap_flow_event eventFlow,