S0TenantEntityContractTests.cs 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. // (AdoS0ProcessFlowCard 的租户化随其组织解析改造单独落地,届时再补入本清单。)
  52. yield return [typeof(AdoS0OrderScheduleCycle)];
  53. yield return [typeof(AdoS0MfgWorkOrderControl)];
  54. yield return [typeof(AdoS0MfgPersonSkill)];
  55. yield return [typeof(AdoS0ContractReviewCycle)];
  56. yield return [typeof(AdoS0ContractReviewCycleBreakdown)];
  57. yield return [typeof(AdoS0ContractReviewCycleSyncFlag)];
  58. yield return [typeof(AdoS0OrderReviewCycle)];
  59. yield return [typeof(AdoS0PriorityCode)];
  60. yield return [typeof(AdoS0PriorityRule)];
  61. yield return [typeof(AdoS0ProductDesignCycle)];
  62. yield return [typeof(AdoS0CategoryLeadTime)];
  63. yield return [typeof(AdoS0MaterialPlanCycle)];
  64. }
  65. [Theory]
  66. [MemberData(nameof(TenantScopedEntityTypes))]
  67. public void TenantScopedS0Entities_ImplementTenantFilterAndMapTenantId(Type entityType)
  68. {
  69. Assert.True(typeof(ITenantIdFilter).IsAssignableFrom(entityType), $"{entityType.Name} must implement ITenantIdFilter");
  70. var property = entityType.GetProperty(nameof(ITenantIdFilter.TenantId));
  71. Assert.NotNull(property);
  72. Assert.Equal(typeof(long?), property!.PropertyType);
  73. var sugarColumn = property.GetCustomAttributes(typeof(SugarColumn), inherit: true)
  74. .OfType<SugarColumn>()
  75. .SingleOrDefault();
  76. Assert.NotNull(sugarColumn);
  77. Assert.Equal("tenant_id", sugarColumn!.ColumnName);
  78. }
  79. }