Files
zszq-trs/UnitTestProject/Modules/SwapModule/FundingLegs/FundingLegStrategyTest.cs
T
hjhan e9b54bdcf6 cleanup: 删除死代码枚举 mode 3/4/7/8 及相关引用
mode 3(持仓名义本金)/4(持仓市值): 零引用死代码
mode 7/8(多空存续名义本金): 界面已禁用, 无历史数据(用户确认)

删除:
- InterestModeEnum: 移除 持仓名义本金/持仓市值/多头存续名义本金/空头存续名义本金
  枚举值保持显式(1/2/5/6/9), DB契约不变
- CalcNotionalByMode: 移除 mode 7/8 的 case
- ConsTrade.InterestModels/InterestNotionalModels: 移除 mode 7/8
- 删除3个 mode 7/8 相关测试方法(场景已不存在)

CalcNotionalByMode 现在只剩 mode 5/6(保证金)的 case,
待 Margin 独立计息入口建成后整体删除。
验证: 编译0错误, 全量508测试7失败(基线一致)。
2026-08-11 13:00:52 +08:00

144 lines
5.3 KiB
C#

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using YLErp.DBModels.Enums;
using YLErp.Modules.SwapModule.FundingLegs;
namespace UnitTestProject.Modules.SwapModule.FundingLegs
{
/// <summary>
/// 融资腿策略单测。验证每个策略的 CalcNotional 与现有 CalcNotionalByMode switch 完全一致。
/// 这组测试是后续"迁移调用点"的安全网——迁移前后行为必须不变。
/// </summary>
[TestClass]
public class FundingLegStrategyTest
{
private const decimal Fix = 2_000_000m;
private const decimal Notional = 100_000_000m;
private const decimal LongNotional = 60_000_000m;
private const decimal ShortNotional = 40_000_000m;
#region 固定值(mode 1)
[TestMethod]
public void 固定值_部分平仓_计息基数恒等于Fix()
{
var leg = new FixedAmountLeg();
var r = leg.CalcNotional(Fix, Notional, LongNotional, ShortNotional, 0.5m);
Assert.AreEqual(Fix, r.ClosePrincipal, "平仓本金恒=Fix");
Assert.AreEqual(Fix, r.PosiPrincipal, "持仓本金恒=Fix");
Assert.AreEqual(1m, r.ClosePercent);
}
[TestMethod]
public void 固定值_全平_计息基数仍等于Fix()
{
var leg = new FixedAmountLeg();
var r = leg.CalcNotional(Fix, Notional, LongNotional, ShortNotional, 1m);
Assert.AreEqual(Fix, r.ClosePrincipal);
}
#endregion
#region 合约名义本金规模(mode 2)
[TestMethod]
public void 合约名义本金_部分平仓_本金按比例缩放()
{
var leg = new ContractNotionalLeg();
var r = leg.CalcNotional(Fix, Notional, LongNotional, ShortNotional, 0.5m);
Assert.AreEqual(50_000_000m, r.ClosePrincipal);
Assert.AreEqual(Notional, r.PosiPrincipal);
Assert.AreEqual(0.5m, r.ClosePercent);
}
[TestMethod]
public void 合约名义本金_全平_本金等于全额()
{
var leg = new ContractNotionalLeg();
var r = leg.CalcNotional(Fix, Notional, LongNotional, ShortNotional, 1m);
Assert.AreEqual(Notional, r.ClosePrincipal);
}
[TestMethod]
public void 合约名义本金_零平仓_本金为零()
{
var leg = new ContractNotionalLeg();
var r = leg.CalcNotional(Fix, Notional, LongNotional, ShortNotional, 0m);
Assert.AreEqual(0m, r.ClosePrincipal);
Assert.AreEqual(Notional, r.PosiPrincipal);
}
#endregion
#region 标的期初全价(mode 9)
[TestMethod]
public void 标的期初全价_部分平仓_主路径公式同mode2()
{
var leg = new UnderlyingEntryFullPriceLeg();
var r = leg.CalcNotional(Fix, Notional, LongNotional, ShortNotional, 0.5m);
Assert.AreEqual(50_000_000m, r.ClosePrincipal);
Assert.AreEqual(Notional, r.PosiPrincipal);
Assert.AreEqual(0.5m, r.ClosePercent);
}
[TestMethod]
public void 标的期初全价_全平_本金等于全额()
{
var leg = new UnderlyingEntryFullPriceLeg();
var r = leg.CalcNotional(Fix, Notional, LongNotional, ShortNotional, 1m);
Assert.AreEqual(Notional, r.ClosePrincipal);
}
#endregion
#region 守卫
[TestMethod]
public void 各策略对应正确枚举值()
{
Assert.AreEqual(InterestModeEnum.固定值, new FixedAmountLeg().Mode);
Assert.AreEqual(InterestModeEnum.合约名义本金规模, new ContractNotionalLeg().Mode);
Assert.AreEqual(InterestModeEnum.标的期初全价, new UnderlyingEntryFullPriceLeg().Mode);
}
#endregion
#region 工厂
[TestMethod]
public void 工厂_返回各活跃mode的策略()
{
Assert.IsInstanceOfType(FundingLegStrategyFactory.Get(InterestModeEnum.固定值), typeof(FixedAmountLeg));
Assert.IsInstanceOfType(FundingLegStrategyFactory.Get(InterestModeEnum.合约名义本金规模), typeof(ContractNotionalLeg));
Assert.IsInstanceOfType(FundingLegStrategyFactory.Get(InterestModeEnum.标的期初全价), typeof(UnderlyingEntryFullPriceLeg));
}
[TestMethod]
public void 工厂_未注册mode抛异常()
{
// mode 3/4/7/8 已从枚举删除,用 Unknown(0)验证未注册抛异常
Assert.ThrowsException<ArgumentException>(() =>
FundingLegStrategyFactory.Get(InterestModeEnum.Unknown));
Assert.ThrowsException<ArgumentException>(() =>
FundingLegStrategyFactory.Get(InterestModeEnum.初始预付金));
Assert.ThrowsException<ArgumentException>(() =>
FundingLegStrategyFactory.Get(InterestModeEnum.追加预付金));
}
[TestMethod]
public void 工厂_int重载和枚举重载等价()
{
var byEnum = FundingLegStrategyFactory.Get(InterestModeEnum.固定值);
var byInt = FundingLegStrategyFactory.Get((int)InterestModeEnum.固定值);
Assert.AreEqual(byEnum.Mode, byInt.Mode);
}
#endregion
}
}