using System.Text.Json.Nodes; using PLCSharp.Models; namespace PLCSharp.Tests; public class WorkflowScriptApiTests { [Theory] [InlineData("VisionFunction.RunAllAsync", "vision", "Task VisionFunction.RunAllAsync()")] [InlineData("Run", "workflow", "void Workflow.Run(GlobalModel globalModel)")] public void PublishedExamplesCompileAgainstTheirRuntime(string method, string topic, string signature) { using var p = ProjectDirectory.New(); var id = Guid.NewGuid(); var api = ProjectInspection.Query(p, "scriptApi", new() { ["topic"] = method, ["workflowId"] = id.ToString() }); var part = Assert.Single(api["topics"]!.AsArray())!; Assert.Equal(typeof(ProjectDirectory).Assembly.ManifestModule.ModuleVersionId, Guid.Parse((string)api["buildId"]!)); Assert.Equal(topic, (string)part["topic"]!); Assert.Contains(part["members"]!.AsArray(), m => (string)m!["signature"]! == signature); var review = WorkflowScriptReview.Create(id, "", (string)part["example"]!); Assert.True(review.Compiled, string.Join("\n", review.Diagnostics)); } }