using MewtocolNet; using MewtocolNet.Registers; using Xunit; using Xunit.Abstractions; namespace MewtocolTests { public class TestRegisterInterface { private readonly ITestOutputHelper output; public TestRegisterInterface(ITestOutputHelper output) { this.output = output; } [Fact(DisplayName = "Numeric mewtocol query building")] public void NumericRegisterMewtocolIdentifiers() { List registers = new List { new NumberRegister(50, _name: null), new NumberRegister(50, _name: null), new NumberRegister(50, _name : null), new NumberRegister(50, _name : null), new NumberRegister(50, _name : null), new NumberRegister(50, _name : null), }; List expectedIdents = new List { "D0005000050", //single word register "D0005000050", //single word register "D0005000051", //double word register "D0005000051", //double word register "D0005000051", //double word register "D0005000051", //double word register }; //test mewtocol idents for (int i = 0; i < registers.Count; i++) { IRegister? reg = registers[i]; string expect = expectedIdents[i]; Assert.Equal(expect, reg.BuildMewtocolQuery()); } } [Fact(DisplayName = "PLC register naming convention test")] public void PLCRegisterIdentifiers() { List registers = new List { //numeric ones new NumberRegister(50, _name: null), new NumberRegister(60, _name : null), new NumberRegister(70, _name : null), new NumberRegister(80, _name : null), new NumberRegister(90, _name : null), new NumberRegister(100, _name : null), //boolean new BoolRegister(IOType.R, 0, 100), new BoolRegister(IOType.R, 0, 0), new BoolRegister(IOType.X, 5), new BoolRegister(IOType.X, 0xA), new BoolRegister(IOType.X, 0xF, 109), new BoolRegister(IOType.Y, 0xC, 75), //string new BytesRegister(999, 5), }; List expcectedIdents = new List { //numeric ones "DT50", "DT60", "DDT70", "DDT80", "DDT90", "DDT100", //boolean "R100", "R0", "X5", "XA", "X109F", "Y75C", //string "DT999" }; //test mewtocol idents for (int i = 0; i < registers.Count; i++) { IRegister? reg = registers[i]; string expect = expcectedIdents[i]; Assert.Equal(expect, reg.GetRegisterPLCName()); } } [Fact(DisplayName = "Non allowed (Overflow address)")] public void OverFlowRegisterAddress() { var ex = Assert.Throws(() => { new NumberRegister(100000, _name: null); }); output.WriteLine(ex.Message.ToString()); var ex1 = Assert.Throws(() => { new BoolRegister(IOType.R, _areaAdress: 512); }); output.WriteLine(ex1.Message.ToString()); var ex2 = Assert.Throws(() => { new BoolRegister(IOType.X, _areaAdress: 110); }); output.WriteLine(ex2.Message.ToString()); var ex3 = Assert.Throws(() => { new BytesRegister(100000, 5); }); output.WriteLine(ex3.Message.ToString()); } [Fact(DisplayName = "Non allowed (Wrong data type)")] public void WrongDataTypeRegister() { var ex = Assert.Throws(() => { new NumberRegister(100, _name: null); }); output.WriteLine(ex.Message.ToString()); } } }