96 lines
4.7 KiB
C#
96 lines
4.7 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using YLErp.DBModels;
|
||
using YLErp.Modules.MarginModule;
|
||
|
||
namespace YLErp.Modules.CalcModules
|
||
{
|
||
/// <summary>
|
||
/// 模板同层多候选取舍纯函数测试(MarginTemplateV2RateHelper.PickByBookScopePreference,2026-08-28 裁定):
|
||
/// 簿记条件满足者优先,其次生效日最新。不连库。
|
||
/// </summary>
|
||
[TestClass]
|
||
public class MarginTemplateV2BookScopePreferenceTest
|
||
{
|
||
private static readonly DateTime Newer = new DateTime(2026, 8, 1);
|
||
private static readonly DateTime Older = new DateTime(2026, 1, 1);
|
||
|
||
private static margin_template_v2 Tpl(int id, DateTime valueDate, string bookIds = null)
|
||
{
|
||
return new margin_template_v2 { id = id, ValueDate = valueDate, BookIds = bookIds, IsValid = true };
|
||
}
|
||
|
||
[TestMethod]
|
||
public void BP_01_双默认同日_限定簿记匹配_压过id更新的通配()
|
||
{
|
||
//复刻 dev 274/275 场景:同生效日按 id 降序,通配模板排前、限定簿记(45)排后;交易簿记=45
|
||
var candidates = new List<margin_template_v2> { Tpl(275, Older), Tpl(274, Older, "45") };
|
||
var picked = MarginTemplateV2RateHelper.PickByBookScopePreference(candidates, 45, out var byBook);
|
||
Assert.AreEqual(274, picked.id, "簿记条件满足的限定模板应压过同日 id 更新的通配模板");
|
||
Assert.IsTrue(byBook, "命中由簿记匹配优先产生时应置 preferredByBookScope");
|
||
}
|
||
|
||
[TestMethod]
|
||
public void BP_02_簿记不匹配_通配胜出()
|
||
{
|
||
//交易簿记=45 不在限定范围(38)内:限定模板不适用,按序取通配(2573 客需债券簿记场景)
|
||
var candidates = new List<margin_template_v2> { Tpl(275, Older), Tpl(274, Older, "38") };
|
||
var picked = MarginTemplateV2RateHelper.PickByBookScopePreference(candidates, 45, out var byBook);
|
||
Assert.AreEqual(275, picked.id);
|
||
Assert.IsFalse(byBook);
|
||
}
|
||
|
||
[TestMethod]
|
||
public void BP_03_无限定候选_取生效日最新()
|
||
{
|
||
var candidates = new List<margin_template_v2> { Tpl(2, Newer), Tpl(1, Older) };
|
||
var picked = MarginTemplateV2RateHelper.PickByBookScopePreference(candidates, 45, out var byBook);
|
||
Assert.AreEqual(2, picked.id, "无簿记限定候选时维持原口径:生效日最新胜出");
|
||
Assert.IsFalse(byBook);
|
||
}
|
||
|
||
[TestMethod]
|
||
public void BP_04_多限定都匹配_取生效日最新()
|
||
{
|
||
var candidates = new List<margin_template_v2> { Tpl(2, Newer, "45,46"), Tpl(1, Older, "45") };
|
||
var picked = MarginTemplateV2RateHelper.PickByBookScopePreference(candidates, 45, out var byBook);
|
||
Assert.AreEqual(2, picked.id, "多个簿记条件满足的候选之间仍按生效日最新取第一个");
|
||
Assert.IsFalse(byBook, "第一个适用候选即簿记匹配时不算'优先压过'");
|
||
}
|
||
|
||
[TestMethod]
|
||
public void BP_05_限定匹配_压过生效日更新的通配()
|
||
{
|
||
var candidates = new List<margin_template_v2> { Tpl(2, Newer), Tpl(1, Older, "45") };
|
||
var picked = MarginTemplateV2RateHelper.PickByBookScopePreference(candidates, 45, out var byBook);
|
||
Assert.AreEqual(1, picked.id, "簿记条件满足优先于生效日新旧");
|
||
Assert.IsTrue(byBook);
|
||
}
|
||
|
||
[TestMethod]
|
||
public void BP_06_全部不适用_返回null()
|
||
{
|
||
var candidates = new List<margin_template_v2> { Tpl(1, Newer, "38") };
|
||
var picked = MarginTemplateV2RateHelper.PickByBookScopePreference(candidates, 45, out _);
|
||
Assert.IsNull(picked, "候选均不适用当前簿记账户时应返回 null(穿透/未命中由调用方处理)");
|
||
}
|
||
|
||
[TestMethod]
|
||
public void BP_07_交易无簿记账户_限定视为不适用()
|
||
{
|
||
//tradeId 查不到 AssetId 时入参为 null:显式限定模板视为不适用,通配仍可用
|
||
var candidates = new List<margin_template_v2> { Tpl(2, Newer), Tpl(1, Older, "45") };
|
||
var picked = MarginTemplateV2RateHelper.PickByBookScopePreference(candidates, null, out var byBook);
|
||
Assert.AreEqual(2, picked.id);
|
||
Assert.IsFalse(byBook);
|
||
}
|
||
|
||
[TestMethod]
|
||
public void BP_08_空候选或null_返回null()
|
||
{
|
||
Assert.IsNull(MarginTemplateV2RateHelper.PickByBookScopePreference(new List<margin_template_v2>(), 45, out _));
|
||
Assert.IsNull(MarginTemplateV2RateHelper.PickByBookScopePreference(null, 45, out _));
|
||
}
|
||
}
|
||
}
|