refactor(margin): 新增 MarginModes 统一保证金mode判断口径
现状: 同一集合{初始预付金,追加预付金}在代码里复制了至少6次
(ConsTrade.InterestMarginModels + 5处局部marginTypes/premiumModes)。
任何一处漏改(如新增保证金形态)都会导致口径分裂。
本次: Margin 模块新增 MarginModes 静态类, 作为单一判断来源。
- IReadOnlyCollection<int> All: 保证金mode集合
- bool Contains(int): 判断mode是否属于保证金
后续逐个替换散落的marginTypes/premiumModes/InterestMarginModels。
纯新增, 零生产代码改动。
验证: 5个单测全过, 全量485测试7失败(基线一致)。
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using YLErp.DBModels;
|
||||
using YLErp.Modules.SwapModule.Margin;
|
||||
|
||||
namespace UnitTestProject.Modules.SwapModule.Margin
|
||||
{
|
||||
/// <summary>
|
||||
/// MarginModes 统一判断口径测试。
|
||||
/// 验证它和现有散落的 marginTypes/InterestMarginModels/premiumModes 内容一致。
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class MarginModesTest
|
||||
{
|
||||
[TestMethod]
|
||||
public void All_只含初始预付金和追加预付金()
|
||||
{
|
||||
CollectionAssert.AreEquivalent(
|
||||
new[] { (int)InterestModeEnum.初始预付金, (int)InterestModeEnum.追加预付金 },
|
||||
MarginModes.All.ToList());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Contains_初始预付金_返回true()
|
||||
=> Assert.IsTrue(MarginModes.Contains((int)InterestModeEnum.初始预付金));
|
||||
|
||||
[TestMethod]
|
||||
public void Contains_追加预付金_返回true()
|
||||
=> Assert.IsTrue(MarginModes.Contains((int)InterestModeEnum.追加预付金));
|
||||
|
||||
[TestMethod]
|
||||
public void Contains_融资腿mode_返回false()
|
||||
{
|
||||
Assert.IsFalse(MarginModes.Contains((int)InterestModeEnum.固定值));
|
||||
Assert.IsFalse(MarginModes.Contains((int)InterestModeEnum.合约名义本金规模));
|
||||
Assert.IsFalse(MarginModes.Contains((int)InterestModeEnum.标的期初全价));
|
||||
}
|
||||
|
||||
/// <summary>守护:和 ConsTrade.InterestMarginModels 内容必须一致(迁移期对齐)。</summary>
|
||||
[TestMethod]
|
||||
public void 与ConsTradeInterestMarginModels内容一致()
|
||||
{
|
||||
var consTrade = new List<int> { (int)InterestModeEnum.初始预付金, (int)InterestModeEnum.追加预付金 };
|
||||
CollectionAssert.AreEquivalent(consTrade, MarginModes.All.ToList());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using YLErp.DBModels;
|
||||
|
||||
namespace YLErp.Modules.SwapModule.Margin;
|
||||
|
||||
/// <summary>
|
||||
/// 保证金计息模式(mode 5 初始预付金 / mode 6 追加预付金)的统一判断口径。
|
||||
///
|
||||
/// 现状(待收敛):同一集合 {初始预付金, 追加预付金} 在代码里复制了至少 6 次——
|
||||
/// ConsTrade.InterestMarginModels(框架级)
|
||||
/// SwapEodPositionService.marginTypes(实例字段)
|
||||
/// SwapEodPositionService.premiumModes(局部变量)
|
||||
/// SwapEventEmailService.marginTypes
|
||||
/// EodClientBalanceCalc.marginTypes
|
||||
/// ClientBalanceUtility.marginTypes
|
||||
/// 任何一处漏改(如新增保证金形态)都会导致口径分裂。本类收敛到单一来源。
|
||||
///
|
||||
/// 注意:这里的"保证金 mode"是现有系统把保证金错误建模为计息腿的历史遗留。
|
||||
/// 按 Margin 限界上下文的设计方向,未来保证金不应用 InterestMode 标识,
|
||||
/// 但在历史代码完全迁出前,需要一个统一判断点。
|
||||
/// </summary>
|
||||
public static class MarginModes
|
||||
{
|
||||
/// <summary>所有属于保证金的 InterestMode(初始预付金 / 追加预付金)。</summary>
|
||||
public static readonly IReadOnlyCollection<int> All = new HashSet<int>
|
||||
{
|
||||
(int)InterestModeEnum.初始预付金,
|
||||
(int)InterestModeEnum.追加预付金,
|
||||
};
|
||||
|
||||
/// <summary>判断 mode 是否属于保证金。</summary>
|
||||
public static bool Contains(int interestMode) => All.Contains(interestMode);
|
||||
}
|
||||
Reference in New Issue
Block a user