增加 oem 返利表的结算

This commit is contained in:
chfei committed 2026-11-19 11:19:12 +08:00
1 parent 4128fc8cc6
commit 9f8e656fcf
5 files changed
+251 -18

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
using KJD_Web.Services.Users;
using Store.Contracts.User.Entitys;
using Store.Contracts.User.Enums;
using System.Reflection;
namespace WebServiceTest;
[TestFixture]
public class UserFloorPriceTest
{
private static int Calculate(List<OEMMarkupRuleEntity> rules, string? oemId) =>
(int)typeof(UserService).GetMethod("CalculateUserFloorPrice", BindingFlags.NonPublic | BindingFlags.Static)!
.Invoke(null, new object[] { rules, new UserEntity { UserName = "user", OemId = oemId },
UserPaymentTypes.中转仓扣费支出, 220 })!;
[TestCase("B", false, 220)]
[TestCase("B", true, 232)]
[TestCase(null, true, 232)]
public void FloorIncludesOnlyMatchingUpstreamMarkup(string? oemId, bool hasRule, int expected)
{
var rules = new List<OEMMarkupRuleEntity>
{
new() { TargetType = OEMMarkupTargetType.User, TargetId = "user", SetterOemId = "B",
PaymentType = UserPaymentTypes.中转仓扣费支出, Markup = 50 },
new() { TargetType = OEMMarkupTargetType.OEM, TargetId = oemId ?? "00000000",
PaymentType = UserPaymentTypes.同步物流, Markup = 99 },
new() { TargetType = OEMMarkupTargetType.OEM, TargetId = "other",
PaymentType = UserPaymentTypes.中转仓扣费支出, Markup = 99 }
};
if (hasRule) rules.Add(new() { TargetType = OEMMarkupTargetType.OEM, TargetId = oemId ?? "00000000",
PaymentType = UserPaymentTypes.中转仓扣费支出, Markup = 12 });
Assert.That(Calculate(rules, oemId), Is.EqualTo(expected));
}
[TestCase(-1, 1, typeof(InvalidOperationException))]
[TestCase(12, 2, typeof(InvalidOperationException))]
[TestCase(int.MaxValue, 1, typeof(OverflowException))]
public void CorruptRulesAndOverflowAreRejected(int markup, int count, Type errorType)
{
var rule = new OEMMarkupRuleEntity { TargetType = OEMMarkupTargetType.OEM, TargetId = "B",
PaymentType = UserPaymentTypes.中转仓扣费支出, Markup = markup };
var error = Assert.Throws<TargetInvocationException>(() => Calculate(Enumerable.Repeat(rule, count).ToList(), "B"));
Assert.That(error!.InnerException, Is.TypeOf(errorType));
}
}