ProductionSchedulePrimaryKeyContractTests.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Xunit;
  2. namespace Admin.NET.Plugin.AiDOP.Tests.Production;
  3. public class ProductionSchedulePrimaryKeyContractTests
  4. {
  5. [Fact]
  6. public void LegacySchedulePrimaryKeys_UseGlobalSequenceAndSerializedGeneration()
  7. {
  8. var generation = File.ReadAllText(FindFile(
  9. "server", "Plugins", "Admin.NET.Plugin.AiDOP", "Production",
  10. "ProductionScheduleGenerationService.cs"));
  11. var action = File.ReadAllText(FindFile(
  12. "server", "Plugins", "Admin.NET.Plugin.AiDOP", "Production",
  13. "ProductionSchedulingActionService.cs"));
  14. Assert.Contains("MAX(RecID), 0) FROM PeriodSequenceDet\"", generation);
  15. Assert.Contains("MAX(RecID), 0) FROM ScheduleExceptionMaster\"", generation);
  16. Assert.Contains("MAX(RecID), 0) FROM ScheduleResultOpMaster\"", generation);
  17. Assert.DoesNotContain("MAX(RecID), 0) FROM PeriodSequenceDet WHERE tenant_id", generation);
  18. Assert.DoesNotContain("MAX(RecID), 0) FROM ScheduleExceptionMaster WHERE tenant_id", generation);
  19. Assert.DoesNotContain("MAX(RecID), 0) FROM ScheduleResultOpMaster WHERE tenant_id", generation);
  20. Assert.Contains("GlobalScheduleGate.WaitAsync()", generation);
  21. Assert.Contains("GlobalScheduleGate.Release()", generation);
  22. Assert.Contains("var key = $\"S2_SCHEDULE:{tenantId}\"", action);
  23. }
  24. [Fact]
  25. public void FullSchedule_EnsuresMissingWorkOrderRoutingsBeforeGeneration()
  26. {
  27. var action = File.ReadAllText(FindFile(
  28. "server", "Plugins", "Admin.NET.Plugin.AiDOP", "Production",
  29. "ProductionSchedulingActionService.cs"));
  30. var routing = File.ReadAllText(FindFile(
  31. "server", "Plugins", "Admin.NET.Plugin.AiDOP", "WorkOrder",
  32. "WorkOrderRoutingSyncService.cs"));
  33. Assert.Contains("await routingSync.EnsureAllPendingAsync(tenantId, account)", action);
  34. Assert.Contains("NOT EXISTS", routing);
  35. Assert.Contains("wr.tenant_id = w.tenant_id", routing);
  36. Assert.Contains("LOWER(IFNULL(w.Status, '')) IN ('p', 'r')", routing);
  37. }
  38. private static string FindFile(params string[] parts)
  39. {
  40. var dir = new DirectoryInfo(AppContext.BaseDirectory);
  41. while (dir != null)
  42. {
  43. var candidate = Path.Combine(new[] { dir.FullName }.Concat(parts).ToArray());
  44. if (File.Exists(candidate)) return candidate;
  45. dir = dir.Parent;
  46. }
  47. throw new FileNotFoundException(string.Join("/", parts));
  48. }
  49. }