S0TenantEntityContractTests.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using Admin.NET.Core;
  2. using Admin.NET.Plugin.AiDOP.Entity.S0.Manufacturing;
  3. using Admin.NET.Plugin.AiDOP.Entity.S0.Sales;
  4. using Admin.NET.Plugin.AiDOP.Entity.S0.Supply;
  5. using Admin.NET.Plugin.AiDOP.Entity.S0.Warehouse;
  6. using SqlSugar;
  7. using Xunit;
  8. namespace Admin.NET.Plugin.AiDOP.Tests.S0.Tenant;
  9. /// <summary>
  10. /// S0 tenant isolation contract for entities whose DB tables already contain tenant_id.
  11. /// </summary>
  12. public class S0TenantEntityContractTests
  13. {
  14. public static IEnumerable<object[]> TenantScopedEntityTypes()
  15. {
  16. yield return [typeof(AdoS0BarCodeType)];
  17. yield return [typeof(AdoS0CostCtrMaster)];
  18. yield return [typeof(AdoS0CustMaster)];
  19. yield return [typeof(AdoS0DepartmentMaster)];
  20. yield return [typeof(AdoS0DevMonitor)];
  21. yield return [typeof(AdoS0EmpSkills)];
  22. yield return [typeof(AdoS0EmpWorkDutyMaster)];
  23. yield return [typeof(AdoS0EmployeeMaster)];
  24. yield return [typeof(AdoS0ImageType)];
  25. yield return [typeof(AdoS0ItemMaster)];
  26. yield return [typeof(AdoS0ItemOpCondition)];
  27. yield return [typeof(AdoS0ItemPackMaster)];
  28. yield return [typeof(AdoS0ItemSubstituteDetail)];
  29. yield return [typeof(AdoS0LineMaster)];
  30. yield return [typeof(AdoS0LineSkillDetail)];
  31. yield return [typeof(AdoS0LineSkillMaster)];
  32. yield return [typeof(AdoS0LocationMaster)];
  33. yield return [typeof(AdoS0LocationShelfMaster)];
  34. yield return [typeof(AdoS0NbrControl)];
  35. yield return [typeof(AdoS0NbrTypeMaster)];
  36. yield return [typeof(AdoS0MfgPersonSkillAssignment)];
  37. yield return [typeof(AdoS0MfgPreprocessElement)];
  38. yield return [typeof(AdoS0MfgPreprocessElementParam)];
  39. yield return [typeof(AdoS0ProdLineDetail)];
  40. yield return [typeof(AdoS0ProductStructureMaster)];
  41. yield return [typeof(AdoS0ProductStructureOp)];
  42. yield return [typeof(AdoS0QualitySegmentImage)];
  43. yield return [typeof(AdoS0MfgRoutingOpDetail)];
  44. yield return [typeof(AdoS0StdOpMaster)];
  45. yield return [typeof(AdoS0SuppMaster)];
  46. yield return [typeof(AdoS0WorkCtrMaster)];
  47. yield return [typeof(AdoS0WorkOrdControl)];
  48. yield return [typeof(IcSubstitute)];
  49. yield return [typeof(AdoS0SrmPurchase)];
  50. // 2026-08-25 批次:原本无 tenant_id 的 12 张 S0 列表主表,随 ITenantIdFilter 一并纳入契约。
  51. yield return [typeof(AdoS0OrderScheduleCycle)];
  52. yield return [typeof(AdoS0MfgWorkOrderControl)];
  53. yield return [typeof(AdoS0MfgPersonSkill)];
  54. yield return [typeof(AdoS0ContractReviewCycle)];
  55. yield return [typeof(AdoS0ContractReviewCycleBreakdown)];
  56. yield return [typeof(AdoS0ContractReviewCycleSyncFlag)];
  57. yield return [typeof(AdoS0OrderReviewCycle)];
  58. yield return [typeof(AdoS0PriorityCode)];
  59. yield return [typeof(AdoS0PriorityRule)];
  60. yield return [typeof(AdoS0ProductDesignCycle)];
  61. yield return [typeof(AdoS0CategoryLeadTime)];
  62. yield return [typeof(AdoS0MaterialPlanCycle)];
  63. // 2026-08-25 同批:工序流转卡随其组织解析改造(去 ClearFilter)一并租户化,migration 1.0.390。
  64. yield return [typeof(AdoS0ProcessFlowCard)];
  65. }
  66. [Theory]
  67. [MemberData(nameof(TenantScopedEntityTypes))]
  68. public void TenantScopedS0Entities_ImplementTenantFilterAndMapTenantId(Type entityType)
  69. {
  70. Assert.True(typeof(ITenantIdFilter).IsAssignableFrom(entityType), $"{entityType.Name} must implement ITenantIdFilter");
  71. var property = entityType.GetProperty(nameof(ITenantIdFilter.TenantId));
  72. Assert.NotNull(property);
  73. Assert.Equal(typeof(long?), property!.PropertyType);
  74. var sugarColumn = property.GetCustomAttributes(typeof(SugarColumn), inherit: true)
  75. .OfType<SugarColumn>()
  76. .SingleOrDefault();
  77. Assert.NotNull(sugarColumn);
  78. Assert.Equal("tenant_id", sugarColumn!.ColumnName);
  79. }
  80. }