WeighingTests: Move all scale handlers into ScaleHandlers.cs
This commit is contained in:
@ -4,10 +4,10 @@ namespace Tests.WeighingTests {
|
||||
[TestFixture]
|
||||
class ScaleTestWolkersdorfIT6000E {
|
||||
|
||||
private MockScale? MockA;
|
||||
private MockScale? MockB;
|
||||
private SysTecITScale? ScaleA;
|
||||
private SysTecITScale? ScaleB;
|
||||
private MockScale MockA;
|
||||
private MockScale MockB;
|
||||
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(';') ?? [];
|
||||
@ -58,37 +58,37 @@ namespace Tests.WeighingTests {
|
||||
|
||||
[OneTimeTearDown]
|
||||
public void TeardownScale() {
|
||||
MockA?.Dispose();
|
||||
MockB?.Dispose();
|
||||
ScaleA?.Dispose();
|
||||
ScaleB?.Dispose();
|
||||
MockA.Dispose();
|
||||
MockB.Dispose();
|
||||
ScaleA.Dispose();
|
||||
ScaleB.Dispose();
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void ResetScale() {
|
||||
MockA!.IdentNr = 0;
|
||||
MockA!.Weight = 0;
|
||||
MockA!.Error = null;
|
||||
MockB!.IdentNr = 0;
|
||||
MockB!.Weight = 0;
|
||||
MockB!.Error = null;
|
||||
MockA.IdentNr = 0;
|
||||
MockA.Weight = 0;
|
||||
MockA.Error = null;
|
||||
MockB.IdentNr = 0;
|
||||
MockB.Weight = 0;
|
||||
MockB.Error = null;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Test_01_CurrentWeight() {
|
||||
MockA!.Weight = 1234;
|
||||
MockA.Weight = 1234;
|
||||
Assert.That(await ScaleA!.GetCurrentWeight(), Is.EqualTo(new WeighingResult {
|
||||
Weight = 1234, Date = new DateOnly(2020, 10, 8), Time = new TimeOnly(8, 47),
|
||||
}));
|
||||
MockB!.Weight = 3456;
|
||||
MockB.Weight = 3456;
|
||||
Assert.That(await ScaleB!.GetCurrentWeight(), Is.EqualTo(new WeighingResult {
|
||||
Weight = 3456, Date = new DateOnly(2020, 10, 8), Time = new TimeOnly(8, 47),
|
||||
}));
|
||||
MockA!.Weight = 1236;
|
||||
MockA.Weight = 1236;
|
||||
Assert.That(await ScaleA!.GetCurrentWeight(), Is.EqualTo(new WeighingResult {
|
||||
Weight = 1236, Date = new DateOnly(2020, 10, 8), Time = new TimeOnly(8, 47),
|
||||
}));
|
||||
MockB!.Weight = 3457;
|
||||
MockB.Weight = 3457;
|
||||
Assert.That(await ScaleB!.GetCurrentWeight(), Is.EqualTo(new WeighingResult {
|
||||
Weight = 3457, Date = new DateOnly(2020, 10, 8), Time = new TimeOnly(8, 47),
|
||||
}));
|
||||
@ -96,25 +96,25 @@ namespace Tests.WeighingTests {
|
||||
|
||||
[Test]
|
||||
public async Task Test_02_Normal() {
|
||||
MockA!.Weight = 1234;
|
||||
MockA.Weight = 1234;
|
||||
Assert.That(await ScaleA!.Weigh(), Is.EqualTo(new WeighingResult {
|
||||
Weight = 1234, WeighingId = "1",
|
||||
FullWeighingId = $"2020-10-08/1",
|
||||
Date = new DateOnly(2020, 10, 8), Time = new TimeOnly(8, 47),
|
||||
}));
|
||||
MockB!.Weight = 3456;
|
||||
MockB.Weight = 3456;
|
||||
Assert.That(await ScaleB!.Weigh(), Is.EqualTo(new WeighingResult {
|
||||
Weight = 3456, WeighingId = "1",
|
||||
FullWeighingId = $"2020-10-08/1",
|
||||
Date = new DateOnly(2020, 10, 8), Time = new TimeOnly(8, 47),
|
||||
}));
|
||||
MockA!.Weight = 4321;
|
||||
MockA.Weight = 4321;
|
||||
Assert.That(await ScaleA!.Weigh(), Is.EqualTo(new WeighingResult {
|
||||
Weight = 4321, WeighingId = "2",
|
||||
FullWeighingId = $"2020-10-08/2",
|
||||
Date = new DateOnly(2020, 10, 8), Time = new TimeOnly(8, 47),
|
||||
}));
|
||||
MockB!.Weight = 3333;
|
||||
MockB.Weight = 3333;
|
||||
Assert.That(await ScaleB!.Weigh(), Is.EqualTo(new WeighingResult {
|
||||
Weight = 3333, WeighingId = "2",
|
||||
FullWeighingId = $"2020-10-08/2",
|
||||
@ -124,39 +124,39 @@ namespace Tests.WeighingTests {
|
||||
|
||||
[Test]
|
||||
public void Test_03_Moving() {
|
||||
MockA!.Weight = 1_000;
|
||||
MockA!.Error = "moving";
|
||||
MockA.Weight = 1_000;
|
||||
MockA.Error = "moving";
|
||||
IOException ex = Assert.ThrowsAsync<IOException>(async () => await ScaleA!.Weigh());
|
||||
Assert.That(ex.Message, Contains.Substring("Waage in Bewegung"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_04_Overloaded() {
|
||||
MockA!.Weight = 10_000;
|
||||
MockA!.Error = "overloaded";
|
||||
MockA.Weight = 10_000;
|
||||
MockA.Error = "overloaded";
|
||||
IOException ex = Assert.ThrowsAsync<IOException>(async () => await ScaleA!.Weigh());
|
||||
Assert.That(ex.Message, Contains.Substring("Waage in Überlast"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_05_InvalidResponse() {
|
||||
MockA!.Weight = 1_000;
|
||||
MockA!.Error = "invalid";
|
||||
MockA.Weight = 1_000;
|
||||
MockA.Error = "invalid";
|
||||
Assert.ThrowsAsync<IOException>(async () => await ScaleA!.Weigh());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_06_InvalidCrc() {
|
||||
MockA!.Weight = 1_000;
|
||||
MockA!.Error = "crc";
|
||||
MockA.Weight = 1_000;
|
||||
MockA.Error = "crc";
|
||||
IOException ex = Assert.ThrowsAsync<IOException>(async () => await ScaleA!.Weigh());
|
||||
Assert.That(ex.Message, Contains.Substring("Invalid CRC16 checksum"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_07_InvalidUnit() {
|
||||
MockA!.Weight = 1_000;
|
||||
MockA!.Error = "unit";
|
||||
MockA.Weight = 1_000;
|
||||
MockA.Error = "unit";
|
||||
IOException ex = Assert.ThrowsAsync<IOException>(async () => await ScaleA!.Weigh());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user