Files
zszq-trs/UnitTestProject/Modules/EodModule/EodPriceUnderlyingIdGuardTest.cs
hjhan 42602055de test(eod): 为 FR007 入库 UnderlyingId 守卫补纯函数单测
- EodPriceService 抽出纯函数 ResolveUnderlyingIdForCode(行为不变),SyncUnderlyingIdFromCode 调用之,便于无库单测
- 新增 EodPriceUnderlyingIdGuardTest:7 用例全过,覆盖空代码/标的不存在维持原值、已一致不改动、FR007 错行(511160.SH=2173889、159111.SZ=2173890)校正为 2170838、非错配不互相覆盖
- 对应根因:GLMS-20260701 FR007 价格行 UnderlyingId 错挂导致网页查得到/结算查不到
2026-07-17 11:24:11 +08:00

89 lines
3.8 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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));
}
}
}