diff --git a/UnitTestProject/Modules/SwapModule/Margin/MarginModesTest.cs b/UnitTestProject/Modules/SwapModule/Margin/MarginModesTest.cs new file mode 100644 index 00000000..edf94c89 --- /dev/null +++ b/UnitTestProject/Modules/SwapModule/Margin/MarginModesTest.cs @@ -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 +{ + /// + /// MarginModes 统一判断口径测试。 + /// 验证它和现有散落的 marginTypes/InterestMarginModels/premiumModes 内容一致。 + /// + [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.标的期初全价)); + } + + /// 守护:和 ConsTrade.InterestMarginModels 内容必须一致(迁移期对齐)。 + [TestMethod] + public void 与ConsTradeInterestMarginModels内容一致() + { + var consTrade = new List { (int)InterestModeEnum.初始预付金, (int)InterestModeEnum.追加预付金 }; + CollectionAssert.AreEquivalent(consTrade, MarginModes.All.ToList()); + } + } +} diff --git a/YLErpDAL/Modules/SwapModule/Margin/MarginModes.cs b/YLErpDAL/Modules/SwapModule/Margin/MarginModes.cs new file mode 100644 index 00000000..d653e114 --- /dev/null +++ b/YLErpDAL/Modules/SwapModule/Margin/MarginModes.cs @@ -0,0 +1,34 @@ +using System.Collections.Generic; +using System.Linq; +using YLErp.DBModels; + +namespace YLErp.Modules.SwapModule.Margin; + +/// +/// 保证金计息模式(mode 5 初始预付金 / mode 6 追加预付金)的统一判断口径。 +/// +/// 现状(待收敛):同一集合 {初始预付金, 追加预付金} 在代码里复制了至少 6 次—— +/// ConsTrade.InterestMarginModels(框架级) +/// SwapEodPositionService.marginTypes(实例字段) +/// SwapEodPositionService.premiumModes(局部变量) +/// SwapEventEmailService.marginTypes +/// EodClientBalanceCalc.marginTypes +/// ClientBalanceUtility.marginTypes +/// 任何一处漏改(如新增保证金形态)都会导致口径分裂。本类收敛到单一来源。 +/// +/// 注意:这里的"保证金 mode"是现有系统把保证金错误建模为计息腿的历史遗留。 +/// 按 Margin 限界上下文的设计方向,未来保证金不应用 InterestMode 标识, +/// 但在历史代码完全迁出前,需要一个统一判断点。 +/// +public static class MarginModes +{ + /// 所有属于保证金的 InterestMode(初始预付金 / 追加预付金)。 + public static readonly IReadOnlyCollection All = new HashSet + { + (int)InterestModeEnum.初始预付金, + (int)InterestModeEnum.追加预付金, + }; + + /// 判断 mode 是否属于保证金。 + public static bool Contains(int interestMode) => All.Contains(interestMode); +}