S0TenantEntityContractTests.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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(AdoS0PriorityCode)];
  40. yield return [typeof(AdoS0ProdLineDetail)];
  41. yield return [typeof(AdoS0ProductStructureMaster)];
  42. yield return [typeof(AdoS0ProductStructureOp)];
  43. yield return [typeof(AdoS0QualitySegmentImage)];
  44. yield return [typeof(AdoS0MfgRoutingOpDetail)];
  45. yield return [typeof(AdoS0StdOpMaster)];
  46. yield return [typeof(AdoS0SuppMaster)];
  47. yield return [typeof(AdoS0WorkCtrMaster)];
  48. yield return [typeof(AdoS0WorkOrdControl)];
  49. yield return [typeof(IcSubstitute)];
  50. yield return [typeof(AdoS0SrmPurchase)];
  51. }
  52. [Theory]
  53. [MemberData(nameof(TenantScopedEntityTypes))]
  54. public void TenantScopedS0Entities_ImplementTenantFilterAndMapTenantId(Type entityType)
  55. {
  56. Assert.True(typeof(ITenantIdFilter).IsAssignableFrom(entityType), $"{entityType.Name} must implement ITenantIdFilter");
  57. var property = entityType.GetProperty(nameof(ITenantIdFilter.TenantId));
  58. Assert.NotNull(property);
  59. Assert.Equal(typeof(long?), property!.PropertyType);
  60. var sugarColumn = property.GetCustomAttributes(typeof(SugarColumn), inherit: true)
  61. .OfType<SugarColumn>()
  62. .SingleOrDefault();
  63. Assert.NotNull(sugarColumn);
  64. Assert.Equal("tenant_id", sugarColumn!.ColumnName);
  65. }
  66. }