diff --git a/PLCSharpWpf/Models/ProjectInspection.cs b/PLCSharpWpf/Models/ProjectInspection.cs index 8204cef..4fbfc92 100644 --- a/PLCSharpWpf/Models/ProjectInspection.cs +++ b/PLCSharpWpf/Models/ProjectInspection.cs @@ -19,7 +19,7 @@ public static class ProjectInspection if (operation == "get") { var id = Guid.Parse((string)args["id"]); - return rows.SingleOrDefault(row => Guid.Parse((string)row["ID"]) == id) + return rows.SingleOrDefault(row => Guid.Parse((string)row["ID"]) == id)?.DeepClone() ?? throw new ArgumentException("Object not found."); } if (operation != "list") throw new ArgumentException("Unknown operation."); diff --git a/Tests/PLCSharp.Tests/ProjectMcpTests.cs b/Tests/PLCSharp.Tests/ProjectMcpTests.cs index 81598e8..6ec70e9 100644 --- a/Tests/PLCSharp.Tests/ProjectMcpTests.cs +++ b/Tests/PLCSharp.Tests/ProjectMcpTests.cs @@ -1,5 +1,6 @@ using PLCSharp.Models; using PLCSharp.VVMs.GlobalVariables; +using PLCSharp.VVMs.MotionController; using System.IO; using System.Text.Json.Nodes; @@ -17,6 +18,8 @@ public class ProjectMcpTests var recipe = project.Recipes.Single(); var variable = new Variable { RecipeID = recipe.ID, Name = "Counter", Comment = "old" }; project.Data.Add(variable); + var point = new AxisPoint { RecipeID = recipe.ID, Name = "定位" }; + project.Data.Add(point); project.Save(folder.FullName); recipe.Name = "unsaved"; var changes = new ProjectChanges(); @@ -32,6 +35,8 @@ public class ProjectMcpTests new() { ["operation"] = operation, ["arguments"] = args }, () => throw new Exception("Unexpected offline access")); var live = Call("get", new() { ["kind"] = "Recipes", ["id"] = recipe.ID.ToString() }); Assert.Equal("unsaved", (string?)live["Name"]); + var livePoint = Call("get", new() { ["kind"] = "AxisPoints", ["id"] = point.ID.ToString() }); + Assert.Equal(point.Name, (string?)livePoint["Name"]); JsonNode Preview() => Call("preview", new() { ["kind"] = "Variables", ["id"] = variable.ID.ToString(), ["comment"] = "new" }); JsonNode Apply(JsonNode draft) => Call("apply", new() { ["draftId"] = (string?)draft["DraftId"] }); Assert.Equal("rejected", (string?)Apply(Preview())["Status"]);