test(eod): 为 FR007 入库 UnderlyingId 守卫补纯函数单测

- EodPriceService 抽出纯函数 ResolveUnderlyingIdForCode(行为不变),SyncUnderlyingIdFromCode 调用之,便于无库单测
- 新增 EodPriceUnderlyingIdGuardTest:7 用例全过,覆盖空代码/标的不存在维持原值、已一致不改动、FR007 错行(511160.SH=2173889、159111.SZ=2173890)校正为 2170838、非错配不互相覆盖
- 对应根因:GLMS-20260701 FR007 价格行 UnderlyingId 错挂导致网页查得到/结算查不到
This commit is contained in:
hjhan
2026-07-17 11:24:11 +08:00
parent e261137c1d
commit 42602055de
2 changed files with 123 additions and 9 deletions
@@ -0,0 +1,88 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using YLErp.DBModels;
namespace YLErp.Modules.EodModule
{
/// <summary>
/// FR007 错行根因的校正决策单测(GLMS-20260701)。
/// 对应最近提交的 bugfixeod_commodity_future_price 入库前以 UnderlyingCode(=FutureContractId) 为准
/// 重派生 UnderlyingId,防止 UnderlyingId 与 FutureContractId 失同步导致"网页能查到、EOD 结算查不到"。
/// 这里只测纯函数 ResolveUnderlyingIdForCode,不依赖数据库。
///
/// 生产事故还原:FR007 价格行的 FutureContractId='FR007',但 UnderlyingId 被错写成
/// 511160.SH 的 2173889 / 159111.SZ 的 2173890,正确应为 FR007 的 2170838。
/// 网页端按 UnderlyingId(int) JOIN underlying_manager 把 FR007 行误挂到 511160.SH
/// 而 EOD 结算按 UnderlyingCode(string) JOIN 查不到,报"结算价格缺失"。
/// </summary>
[TestClass]
public class EodPriceUnderlyingIdGuardTest
{
private const int Fr007CorrectId = 2170838;
private const int Id511160 = 2173889; // 511160.SH 的 id(被错写)
private const int Id159111 = 2173890; // 159111.SZ 的 id(被错写)
[TestMethod]
public void UnderlyingCode_维持原值()
{
Assert.AreEqual(123, EodPriceService.ResolveUnderlyingIdForCode("", 123, null));
Assert.AreEqual(123, EodPriceService.ResolveUnderlyingIdForCode(null, 123, 999));
Assert.AreEqual(123, EodPriceService.ResolveUnderlyingIdForCode(" ", 123, 999));
}
[TestMethod]
public void _维持原值()
{
// resolvedId=null 表示 underlying_manager 无此代码,无法校正
Assert.AreEqual(Id511160,
EodPriceService.ResolveUnderlyingIdForCode("FR007", Id511160, null));
}
[TestMethod]
public void _维持原值()
{
Assert.AreEqual(Fr007CorrectId,
EodPriceService.ResolveUnderlyingIdForCode("FR007", Fr007CorrectId, Fr007CorrectId));
}
[TestMethod]
public void _校正为正确id_FR007生产错行_511160()
{
// 生产事故:FR007 行 UnderlyingId=2173889(511160.SH) → 应校正为 2170838
Assert.AreEqual(Fr007CorrectId,
EodPriceService.ResolveUnderlyingIdForCode("FR007", Id511160, Fr007CorrectId));
}
[TestMethod]
public void _校正为正确id_FR007生产错行_159111()
{
// 生产事故:另两条错行 UnderlyingId=2173890(159111.SZ) → 应校正为 2170838
Assert.AreEqual(Fr007CorrectId,
EodPriceService.ResolveUnderlyingIdForCode("FR007", Id159111, Fr007CorrectId));
}
[TestMethod]
public void _端到端校正_FR007()
{
var row = new eod_commodity_future_price
{
UnderlyingCode = "FR007",
UnderlyingId = Id511160
};
// 模拟 db.underlying_manager 解析到的正确 id
int resolved = Fr007CorrectId;
int? before = row.UnderlyingId;
row.UnderlyingId = EodPriceService.ResolveUnderlyingIdForCode(row.UnderlyingCode, row.UnderlyingId ?? 0, resolved);
Assert.AreNotEqual(before, row.UnderlyingId);
Assert.AreEqual((int?)Fr007CorrectId, row.UnderlyingId);
}
[TestMethod]
public void _不同标的_各自正确不互相覆盖()
{
// 511160.SH 自己的行(FutureContractId='511160.SH'),UnderlyingId 已是 2173889 → 不动
Assert.AreEqual(Id511160,
EodPriceService.ResolveUnderlyingIdForCode("511160.SH", Id511160, Id511160));
}
}
}