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
@@ -26,29 +26,29 @@ namespace YLErp.Modules.SwapModule
#region Stub DealInterestsScenarioTest
private sealed class StubEodService : SwapEodPositionService
private sealed class StubEodService : TestableSwapEodPositionService
{
public List<eod_swap_position> PersistedPositions { get; } = new();
private int _nextId = 1;
public StubEodService() : base(new OptUserInfo(0, nameof(DealInterestsGoldenReplayTest), OptUserFrom.UnitTest))
public StubEodService() : base(nameof(DealInterestsGoldenReplayTest))
{
}
protected override void PersistEodSwapPosition(eod_swap_position position)
{
if (position.id == 0) position.id = _nextId++;
PersistedPositions.Add(position);
}
protected override void SaveAllChanges() { }
protected override double GetCurrencyRate(string q, string s, DateTime d, bool p, CurrencyRateType t) => 1.0;
public void ExecuteSaveEodInterestPosition(
eod_swap_position eodPayPosition, swap_position position, trade td,
DateTime valueDate, List<swap_flow_event> flowEvents)
{
SaveEodInterestPosition(eodPayPosition, null, position, td, valueDate, flowEvents);
}
// public 包装:直接调用 protected virtual DealInterests(录制场景2用)
public void ExecuteDealInterestsForRecord(
List<swap_position> interestList, List<eod_swap_position> eodPositions,
DateTime settleDate, trade td,
decimal posiLongNational, decimal grossPrice, decimal orginPv)
{
DealInterests(interestList, eodPositions, new List<eod_swap_position>(),
settleDate, td, new List<swap_flow_event>(), new List<swap_flow_event>(), null,
posiLongNational, 0m, 0m, grossPrice, orginPv);
}
}
#endregion
@@ -189,17 +189,11 @@ namespace YLErp.Modules.SwapModule
};
var service = new StubEodService();
// 通过反射调 DealInterestscopy 分支需要 CalcSwapInterests
var method = typeof(SwapEodPositionService).GetMethod("DealInterests",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
method.Invoke(service, new object[]
{
// 直接调用 protected virtual DealInterestscopy 分支需要 CalcSwapInterests
service.ExecuteDealInterestsForRecord(
new List<swap_position> { position },
new List<eod_swap_position> { preEod },
new List<eod_swap_position>(),
settleDate, td, new List<swap_flow_event>(), new List<swap_flow_event>(), null,
Principal, 0m, 0m, 1m, Principal
});
settleDate, td, Principal, 1m, Principal);
if (service.PersistedPositions.Count == 0)
{