44 lines
1.6 KiB
C#
44 lines
1.6 KiB
C#
using PLCSharp.Models;
|
|
using PLCSharp.VVMs.Cylinders;
|
|
using PLCSharp.VVMs.MotionController;
|
|
using System.IO;
|
|
|
|
namespace PLCSharp.Tests;
|
|
|
|
public class IoRenameTests
|
|
{
|
|
[Fact]
|
|
public void SameNamedInputAndOutputKeepSeparateBindingsAndUndoInReverseOrder()
|
|
{
|
|
var root = Directory.CreateTempSubdirectory();
|
|
try
|
|
{
|
|
using var p = ProjectDirectory.New();
|
|
var input = new DI { Name = "A" };
|
|
var output = new DQ { Name = "A" };
|
|
var unnamed = new DI();
|
|
var cylinder = new Cylinder { InA = "A", OutA = "A" };
|
|
p.Data.AddRange(input, output, unnamed, cylinder);
|
|
p.Save(root.FullName);
|
|
var path = Path.Combine(root.FullName, "configuration", "hardware.json");
|
|
var original = File.ReadAllBytes(path);
|
|
var a = p.PlanIoRename("DI", input.ID, "Input");
|
|
p.ApplyRename(a);
|
|
Assert.Equal("Input", cylinder.InA);
|
|
Assert.Equal("A", cylinder.OutA);
|
|
var b = p.PlanIoRename("DQ", output.ID, "Output");
|
|
p.ApplyRename(b);
|
|
Assert.ThrowsAny<IOException>(() => p.PlanUndo(Guid.NewGuid(), a));
|
|
p.ApplyRename(p.PlanUndo(Guid.NewGuid(), b));
|
|
p.ApplyRename(p.PlanUndo(Guid.NewGuid(), a));
|
|
var firstName = p.PlanIoRename("DI", unnamed.ID, "New");
|
|
Assert.Empty(firstName.CylinderReferences);
|
|
p.ApplyRename(firstName);
|
|
p.ApplyRename(p.PlanUndo(Guid.NewGuid(), firstName));
|
|
Assert.Null(unnamed.Name);
|
|
Assert.Equal(original, File.ReadAllBytes(path));
|
|
}
|
|
finally { root.Delete(true); }
|
|
}
|
|
}
|