using PLCSharp.Models; using PLCSharp.VVMs.Robots; using PLCSharp.VVMs.Workflows; using System.IO; namespace PLCSharp.Tests; public class PointRenameTests { [Fact] public void RobotReferencesAndMatrixEditsStayWithinTheOwningRobot() { var root = Directory.CreateTempSubdirectory(); try { using var p = ProjectDirectory.New(); var a = new Robot { Name = "A" }; var b = new Robot { Name = "B" }; var target = new RobotPoint { Name = "P1", RobotID = a.ID, RecipeID = p.DefaultRecipeId }; var other = new RobotPoint { Name = "P1", RobotID = b.ID, RecipeID = p.DefaultRecipeId }; var matrix = new RobotMatrix { RobotID = a.ID, RecipeID = p.DefaultRecipeId, XEndName = "P1" }; p.Data.AddRange(a, b, target, other, matrix); p.Data.Save(); var caller = new Workflow { Name = "Caller", RecipeID = p.DefaultRecipeId }; caller.Code = $$""" using System.Linq; using PLCSharp.Models; using PLCSharp.Core.Common; public class Extension_{{caller.ID:N}} { public void Run(GlobalModel model, FlowModel flow) { model.GetRobot("A").RunPoint("P1"); model.GetRobot("B").RunPoint("P1"); model.GetRobot("A").Jog(cmd: "X+", dist: 10, pointName: "P1"); model.GetRobot("A").RunPoint(flow.Step.ToString()); model.GetRobot(flow.Step.ToString()).RunPoint("P1"); _ = model.GetRobot("A").Points.FirstOrDefault(p => p.Name == "P1"); } } """; p.Flows(p.DefaultRecipeId).Add(caller); p.Save(root.FullName); var preview = p.PlanPointRename("RobotPoints", target.ID, "Pick"); Assert.True(preview.Compiled); var output = Assert.Single(preview.Scripts).After; Assert.Contains("GetRobot(\"A\").RunPoint(\"Pick\")", output); Assert.Contains("GetRobot(\"B\").RunPoint(\"P1\")", output); Assert.Contains("pointName: \"Pick\"", output); Assert.Contains("p.Name == \"Pick\"", output); Assert.Equal(new[] { "dynamic", "possible" }, preview.ManualReferences.Select(h => (string?)h!["confidence"])); p.ApplyRename(preview); Assert.Equal("Pick", target.Name); Assert.Equal("Pick", matrix.XEndName); Assert.Equal("P1", other.Name); p.ApplyRename(p.PlanUndo(Guid.NewGuid(), preview)); Assert.Equal("P1", matrix.XEndName); Assert.Equal("P1", target.Name); } finally { root.Delete(true); } } }