WeighingTests: Add Haugsdorf and Sitzendorf
All checks were successful
Test / Run tests (push) Successful in 2m46s

This commit is contained in:
2024-07-24 16:42:38 +02:00
parent d741ba92dc
commit 8e9f2f4e90
7 changed files with 323 additions and 65 deletions

View File

@ -9,49 +9,10 @@ namespace Tests.WeighingTests {
private SysTecITScale ScaleA;
private SysTecITScale ScaleB;
private static (string, bool) ScaleHandler(string req, int weight, string? error, int identNr, string terminalNr) {
var modes = error?.Split(';') ?? [];
var overloaded = modes.Contains("overloaded");
var moving = modes.Contains("moving");
var invalid = modes.Contains("invalid");
var crc = modes.Contains("crc");
var unit = modes.Contains("unit");
if (invalid) {
return ("abcd\r\n", false);
} else if (!req.StartsWith('<') || !req.EndsWith('>')) {
return ("<31>\r\n", false);
}
req = req[1..^1];
bool incr;
if (req.Length > 3) {
return ("<32>\r\n", false);
} else if (req.StartsWith("RN")) {
incr = true;
} else if (req.StartsWith("RM")) {
incr = false;
} else {
return ("<32>\r\n", false);
}
if (overloaded)
return ("<12>\r\n", false);
if (moving && incr)
return ("<13>\r\n", false);
string data = $"00{(moving ? 1 : 0)}0{new DateTime(2020, 10, 8, 8, 47, 0):dd.MM.yyHH:mm}{(incr ? identNr : 0),4}1" +
$"{weight,8}{0,8}{weight,8}{(unit ? "lb" : "kg")} {terminalNr,3}";
ushort checksum = Elwig.Helpers.Utils.CalcCrc16Modbus(data);
if (crc) checksum += 10;
return ($"<{data}{checksum,8}>\r\n", incr);
}
[OneTimeSetUp]
public void SetupScale() {
MockA = new CommandMockScale(12345, (req, weight, error, identNr) => ScaleHandler(req, weight, error, identNr, "A"));
MockB = new CommandMockScale(12346, (req, weight, error, identNr) => ScaleHandler(req, weight, error, identNr, "B"));
MockA = new CommandMockScale(12345, (req, weight, tare, error, identNr) => ScaleHandlers.Handle_IT6000E(req, weight, tare, error, identNr, "A"));
MockB = new CommandMockScale(12346, (req, weight, tare, error, identNr) => ScaleHandlers.Handle_IT6000E(req, weight, tare, error, identNr, "B"));
ScaleA = new("A", "IT3000E", "tcp://127.0.0.1:12345");
ScaleB = new("B", "IT3000E", "tcp://127.0.0.1:12346");
}