S0TenantEntityContractTests.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. }
  51. [Theory]
  52. [MemberData(nameof(TenantScopedEntityTypes))]
  53. public void TenantScopedS0Entities_ImplementTenantFilterAndMapTenantId(Type entityType)
  54. {
  55. Assert.True(typeof(ITenantIdFilter).IsAssignableFrom(entityType), $"{entityType.Name} must implement ITenantIdFilter");
  56. var property = entityType.GetProperty(nameof(ITenantIdFilter.TenantId));
  57. Assert.NotNull(property);
  58. Assert.Equal(typeof(long?), property!.PropertyType);
  59. var sugarColumn = property.GetCustomAttributes(typeof(SugarColumn), inherit: true)
  60. .OfType<SugarColumn>()
  61. .SingleOrDefault();
  62. Assert.NotNull(sugarColumn);
  63. Assert.Equal("tenant_id", sugarColumn!.ColumnName);
  64. }
  65. }