修正上次尝试的失败: 静态 Fr007IndexFixer.Instance 绕过了 TryGetFloatRate(virtual)接缝, 导致测试 stub 失效(CI_007/CI_008失败)。 本次方案: 新增 SwapDealIndexFixer(实例级, 委托 TryGetFloatRate): - SwapDealService.IndexFixer 属性 lazy 初始化, 包 SwapDealIndexFixer - 6处 GetNonHolidayDefore+TryGetFloatRate 全部替换为 IndexFixerBase+IndexFixer - TryGetFloatRate(protected virtual)保留不动, 测试 stub 机制完全不受影响 验证: CI_007/CI_008 从失败转为通过, 全量480测试7失败(与基线一致,零回归)。 SwapDealService 内 GetNonHolidayDefore 出现次数: 6 → 0(全部收敛到 IndexFixerBase)。
26 lines
1.0 KiB
C#
26 lines
1.0 KiB
C#
using System;
|
||
using YLErp.Derivatives.Interest;
|
||
|
||
namespace YLErp.Modules.SwapModule;
|
||
|
||
/// <summary>
|
||
/// SwapDealService 专用取价器:通过实例方法委托给 TryGetFloatRate(virtual),
|
||
/// 而非 Fr007IndexFixer.Instance 那样直接调 EodPriceQueryService。
|
||
///
|
||
/// 为什么不用静态 Instance:SwapDealService.TryGetFloatRate 是 protected virtual,
|
||
/// 测试通过 override 它注入 stub 利率。静态 Instance 绕过这个接缝会让 45 个测试失败。
|
||
/// 本类把 TryGetFloatRate 包成 IIndexFixer,既保留 virtual 接缝,又用上 IndexFixerBase。
|
||
/// </summary>
|
||
internal sealed class SwapDealIndexFixer : IndexFixerBase, IIndexFixer
|
||
{
|
||
private readonly SwapDealService _owner;
|
||
internal SwapDealIndexFixer(SwapDealService owner) => _owner = owner;
|
||
|
||
public bool TryGetFixing(DateTime fixingDate, string underlyingCode, out decimal rate)
|
||
{
|
||
bool ok = _owner.TryGetFloatRate(fixingDate, underlyingCode, out double r);
|
||
rate = Convert.ToDecimal(r);
|
||
return ok;
|
||
}
|
||
}
|