using Admin.NET.Plugin.AiDOP.Infrastructure; using Xunit; namespace Admin.NET.Plugin.AiDOP.Tests.S0.Sales; /// /// S0 Batch2 产销:客户/物料 ForbidStatus 与订单优先规则编码规则(单元测试)。 /// public class AdoS0SalesRulesTests { [Theory] [InlineData(true, "normal")] [InlineData(false, "forbidden")] public void ForbidStatusFromIsEnabled_MatchesBatch2Contract(bool isEnabled, string expected) { Assert.Equal(expected, AdoS0SalesRules.ForbidStatusFromIsEnabled(isEnabled)); } [Fact] public void ResolveOrderPriorityRuleCodeForCreate_WhenCodeProvided_ReturnsAsIs() { const string code = "MY-RULE-01"; var now = new DateTime(2026, 4, 8, 12, 30, 45); Assert.Equal(code, AdoS0SalesRules.ResolveOrderPriorityRuleCodeForCreate(code, now, 1234)); } [Fact] public void ResolveOrderPriorityRuleCodeForCreate_WhenEmpty_GeneratesRulePrefixWithTimestampAndSuffix() { var now = new DateTime(2026, 4, 8, 12, 30, 45); var result = AdoS0SalesRules.ResolveOrderPriorityRuleCodeForCreate(null, now, 5678); Assert.Equal("RULE-20260408123045-5678", result); } [Theory] [InlineData(null)] [InlineData("")] [InlineData(" ")] public void ResolveOrderPriorityRuleCodeForUpdate_WhenBlank_KeepsExisting(string dtoCode) { Assert.Equal("OLD", AdoS0SalesRules.ResolveOrderPriorityRuleCodeForUpdate(dtoCode, "OLD")); } [Fact] public void ResolveOrderPriorityRuleCodeForUpdate_WhenProvided_Replaces() { Assert.Equal("NEW", AdoS0SalesRules.ResolveOrderPriorityRuleCodeForUpdate("NEW", "OLD")); } }