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:
@@ -23,7 +23,7 @@ namespace YLErp.Modules.SwapModule
|
||||
/// 继承 SwapEodPositionService,override SwapPositionCompose 路径上的 seam。
|
||||
/// 适配当前分支 seam 签名(GetUnderlyingPrice 带 out、GetCurrencyRate 返回 double 等)。
|
||||
/// </summary>
|
||||
private sealed class TestableSwapEodService : SwapEodPositionService
|
||||
private sealed class TestableSwapEodService : TestableSwapEodPositionService
|
||||
{
|
||||
private readonly List<trade> _trades;
|
||||
private readonly List<swap_position> _positions;
|
||||
@@ -34,15 +34,15 @@ namespace YLErp.Modules.SwapModule
|
||||
private readonly decimal _price;
|
||||
private readonly decimal _vobp;
|
||||
|
||||
public List<eod_swap_position> CreatedEodPositions { get; } = new();
|
||||
public List<(double amount, string action)> ClientCashCalls { get; } = new();
|
||||
// 输出别名(转发到基类捕获属性)
|
||||
public List<eod_swap_position> CreatedEodPositions => PersistedPositions;
|
||||
|
||||
public TestableSwapEodService(
|
||||
List<trade> trades, List<swap_position> positions,
|
||||
List<eod_swap_position> eodPositions, List<eod_swap> eodSwaps,
|
||||
List<trade_extend> extends, List<swap_flow_event> flowEvents,
|
||||
decimal price = 100m, decimal vobp = 0m)
|
||||
: base(new OptUserInfo(0, nameof(SwapPositionComposeScenarioTest), OptUserFrom.UnitTest))
|
||||
: base(nameof(SwapPositionComposeScenarioTest))
|
||||
{
|
||||
_trades = trades; _positions = positions; _eodPositions = eodPositions;
|
||||
_eodSwaps = eodSwaps; _extends = extends; _flowEvents = flowEvents;
|
||||
@@ -67,13 +67,9 @@ namespace YLErp.Modules.SwapModule
|
||||
{ vobp = _vobp; return _price; }
|
||||
protected override decimal CalcBondPayment(string underlyingCode, DateTime fromDate, DateTime toDate, decimal qty, int shortRatio, int directionRatio) => 0m;
|
||||
|
||||
// 持久化/事务 seam override
|
||||
protected override void PersistEodSwapPosition(eod_swap_position position) { CreatedEodPositions.Add(position); }
|
||||
// 持久化/事务 seam override(PersistEodSwapPosition/SaveAllChanges/GetCurrencyRate/AddClientCash 由基类提供)
|
||||
protected override void SaveEodSwapRecord(trade td, DateTime settleDate, DateTime preSettleDate) { }
|
||||
protected override void SaveAllChanges() { }
|
||||
protected override void ExecuteInTransaction(Action action) => action();
|
||||
protected override int AddClientCash(trade td, double amount, string action, DateTime valueDate)
|
||||
{ ClientCashCalls.Add((amount, action)); return ClientCashCalls.Count; }
|
||||
protected override void ClearSwapPositionsForCompose(trade td, DateTime tradeDate, List<int> eventTypes) { }
|
||||
public override void ClearSwapPositions(trade td, DateTime valueDate, List<int> eventTypes, bool delAfter) { }
|
||||
protected override swap_event AddSwapEvent(DateTime tradeDate, int swapTradeId, int eventType, string data, int clientCashId, bool save, string reason)
|
||||
@@ -85,7 +81,6 @@ namespace YLErp.Modules.SwapModule
|
||||
decimal closePosiNotionalValue, decimal closePrecent, int eventType, bool tdClose, bool needPrice,
|
||||
decimal grossPrice, decimal orginPv, bool add = false, bool settment = true, bool newCalcLast = false,
|
||||
List<swap_flow_event> closeList = null) => new List<swap_flow_event>();
|
||||
protected override double GetCurrencyRate(string quoteCurrency, string settlementCurrency, DateTime valueDate, bool seekPreday, CurrencyRateType currencyRateType) => 1.0;
|
||||
|
||||
public void ExecuteSwapPositionCompose(DateTime settleDate, DateTime preSettleDate)
|
||||
=> SwapPositionCompose(settleDate, preSettleDate, null);
|
||||
|
||||
Reference in New Issue
Block a user