using Xunit; namespace Admin.NET.Plugin.AiDOP.Tests.Production; public class ProductionSchedulePrimaryKeyContractTests { [Fact] public void LegacySchedulePrimaryKeys_UseGlobalSequenceAndSerializedGeneration() { var generation = File.ReadAllText(FindFile( "server", "Plugins", "Admin.NET.Plugin.AiDOP", "Production", "ProductionScheduleGenerationService.cs")); var action = File.ReadAllText(FindFile( "server", "Plugins", "Admin.NET.Plugin.AiDOP", "Production", "ProductionSchedulingActionService.cs")); Assert.Contains("MAX(RecID), 0) FROM PeriodSequenceDet\"", generation); Assert.Contains("MAX(RecID), 0) FROM ScheduleExceptionMaster\"", generation); Assert.Contains("MAX(RecID), 0) FROM ScheduleResultOpMaster\"", generation); Assert.DoesNotContain("MAX(RecID), 0) FROM PeriodSequenceDet WHERE tenant_id", generation); Assert.DoesNotContain("MAX(RecID), 0) FROM ScheduleExceptionMaster WHERE tenant_id", generation); Assert.DoesNotContain("MAX(RecID), 0) FROM ScheduleResultOpMaster WHERE tenant_id", generation); Assert.Contains("GlobalScheduleGate.WaitAsync()", generation); Assert.Contains("GlobalScheduleGate.Release()", generation); Assert.Contains("var key = $\"S2_SCHEDULE:{tenantId}\"", action); } [Fact] public void FullSchedule_EnsuresMissingWorkOrderRoutingsBeforeGeneration() { var action = File.ReadAllText(FindFile( "server", "Plugins", "Admin.NET.Plugin.AiDOP", "Production", "ProductionSchedulingActionService.cs")); var routing = File.ReadAllText(FindFile( "server", "Plugins", "Admin.NET.Plugin.AiDOP", "WorkOrder", "WorkOrderRoutingSyncService.cs")); Assert.Contains("await routingSync.EnsureAllPendingAsync(tenantId, account)", action); Assert.Contains("NOT EXISTS", routing); Assert.Contains("wr.tenant_id = w.tenant_id", routing); Assert.Contains("LOWER(IFNULL(w.Status, '')) IN ('p', 'r')", routing); } private static string FindFile(params string[] parts) { var dir = new DirectoryInfo(AppContext.BaseDirectory); while (dir != null) { var candidate = Path.Combine(new[] { dir.FullName }.Concat(parts).ToArray()); if (File.Exists(candidate)) return candidate; dir = dir.Parent; } throw new FileNotFoundException(string.Join("/", parts)); } }