44 lines
1.7 KiB
C#
44 lines
1.7 KiB
C#
using PLCSharp.Models;
|
|
using PLCSharp.VVMs.GlobalVariables;
|
|
using PLCSharp.VVMs.Workflows;
|
|
|
|
namespace PLCSharp.Tests;
|
|
|
|
public class VariableRenameTests
|
|
{
|
|
[Fact]
|
|
public void PreviewReplacesBoundArgumentsAndListsRuntimeLookups()
|
|
{
|
|
using var project = ProjectDirectory.New();
|
|
var variable = new Variable { Name = "计数", RecipeID = project.DefaultRecipeId };
|
|
project.Data.Add(variable);
|
|
project.Data.Save();
|
|
var flow = new Workflow { Name = "搬运" };
|
|
flow.Code = $$"""
|
|
using PLCSharp.Models;
|
|
using PLCSharp.Core.Common;
|
|
using System.Linq;
|
|
public class Extension_{{flow.ID:N}} {
|
|
public void Run(GlobalModel model, FlowModel f) {
|
|
const string label = "计数";
|
|
_ = model.GetVariable(label);
|
|
_ = model.VariablesModel.Variables.FirstOrDefault(v => v.Name == "计数");
|
|
_ = model.GetVariable(f.Step.ToString());
|
|
// model.GetVariable("计数");
|
|
}
|
|
}
|
|
""";
|
|
project.Flows(variable.RecipeID).Add(flow);
|
|
var preview = project.PlanRename(variable.ID, "完成数");
|
|
Assert.True(preview.Compiled);
|
|
var edit = Assert.Single(preview.Scripts);
|
|
Assert.Contains("GetVariable(\"完成数\")", edit.After);
|
|
Assert.Contains("v.Name == \"完成数\"", edit.After);
|
|
Assert.Contains("const string label = \"计数\"", edit.After);
|
|
Assert.Contains("// model.GetVariable(\"计数\")", edit.After);
|
|
Assert.Single(preview.ManualReferences);
|
|
Assert.Equal(edit.Before, flow.Code);
|
|
}
|
|
}
|
|
|