Files
zszq-trs/UnitTestProject/Modules/EodModule/BondPaymentServiceCalculationTest.cs
T
张名锐 392e36a820 feat(bond): 添加公司行为现金分红标识并优化付息计算逻辑
- 在 BondPayment 模型中添加 IsCorporateActionCashDividend 属性用于区分不同数据来源
- 修改 BondPaymentService 中的 CalcPayment 方法,按每条记录来源分别处理金额单位转换
- 更新单元测试以验证混合债券付息和公司行为分红的正确计算
- 移除不再需要的 useBondPriceScale 参数简化方法接口
- 修正注释说明以反映新的按记录类型分别计算的逻辑
2026-08-21 16:51:55 +08:00

71 lines
2.3 KiB
C#
Raw 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 YLErp.DBModels;
namespace YLErp.Modules.EodModule
{
[TestClass]
public class BondPaymentServiceCalculationTest
{
private static BondPaymentService CreateService()
{
return new BondPaymentService(
new OptUserInfo(0, nameof(BondPaymentServiceCalculationTest), OptUserFrom.UnitTest));
}
[TestMethod]
public void CalcPayment_BondCoupon_KeepsPerHundredScale()
{
var payments = new List<BondPayment>
{
new BondPayment { payment_interest = 1m }
};
// 债券票息 1 表示每 100 元面值付 1 元:1 * 1000 / 100 = 10。
var actual = CreateService().CalcPayment(
payments,
qty: 1000m,
longRatio: 1m,
payDirection: 1m);
Assert.AreEqual(10m, actual);
}
[TestMethod]
public void CalcPayment_CorporateActionDividend_UsesPerTenScale()
{
var payments = new List<BondPayment>
{
new BondPayment { payment_interest = 10m, IsCorporateActionCashDividend = true }
};
// GiveCashAmount=10(每 10 份派 10)时,payment_interest 直接存 10
// 持仓 1000 份的现金分红 = 10 * 1000 / 10 = 1000,不能再套债券报价的 /100 换算。
var actual = CreateService().CalcPayment(
payments,
qty: 1000m,
longRatio: 1m,
payDirection: 1m);
Assert.AreEqual(1000m, actual);
}
[TestMethod]
public void CalcPayment_FundMixedBondPaymentAndCorporateAction_UsesEachRecordScale()
{
var payments = new List<BondPayment>
{
// bond_payment_info:每 100 份付 2200000 份应为 4000。
new BondPayment { payment_interest = 2m },
// ex_dividend_info:每 10 份派 10200000 份应为 200000。
new BondPayment { payment_interest = 10m, IsCorporateActionCashDividend = true }
};
var actual = CreateService().CalcPayment(
payments,
qty: 200000m,
longRatio: 1m,
payDirection: 1m);
Assert.AreEqual(204000m, actual);
}
}
}