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 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 { 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(() => Calculate(Enumerable.Repeat(rule, count).ToList(), "B")); Assert.That(error!.InnerException, Is.TypeOf(errorType)); } }