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

@ -8,6 +8,7 @@ namespace Tests.WeighingTests {
protected readonly TcpListener Server;
public int IdentNr { get; set; } = 0;
public int Tare { get; set; } = 0;
public int Weight { get; set; } = 0;
public string? Error { get; set; } = null;
@ -24,11 +25,11 @@ namespace Tests.WeighingTests {
public class CommandMockScale : MockScale {
private readonly Func<string, int, string?, int, (string, bool)> Handler;
private readonly Func<string, int, int, string?, int, (string, bool)> Handler;
private readonly Thread ServerThread;
private bool IsRunning = true;
public CommandMockScale(int port, Func<string, int, string?, int, (string, bool)> handler) :
public CommandMockScale(int port, Func<string, int, int, string?, int, (string, bool)> handler) :
base(port) {
Handler = handler;
ServerThread = new Thread(new ParameterizedThreadStart(Serve));
@ -44,7 +45,7 @@ namespace Tests.WeighingTests {
using var stream = client.GetStream();
while (true) {
int read = await stream.ReadAsync(buffer);
var (res, inc) = Handler(Encoding.ASCII.GetString(buffer, 0, read), Weight, Error, IdentNr + 1);
var (res, inc) = Handler(Encoding.ASCII.GetString(buffer, 0, read), Weight, Tare, Error, IdentNr + 1);
if (inc) IdentNr++;
await stream.WriteAsync(Encoding.ASCII.GetBytes(res));
}
@ -64,12 +65,12 @@ namespace Tests.WeighingTests {
public class EventMockScale : MockScale {
private readonly Func<int, string?, int, (string, bool)> Handler;
private readonly Func<int, int, string?, int, (string, bool)> Handler;
private readonly Thread ServerThread;
private TcpClient? Client;
private bool IsRunning = true;
public EventMockScale(int port, Func<int, string?, int, (string, bool)> handler) :
public EventMockScale(int port, Func<int, int, string?, int, (string, bool)> handler) :
base(port) {
Handler = handler;
ServerThread = new Thread(new ParameterizedThreadStart(Serve));
@ -86,13 +87,14 @@ namespace Tests.WeighingTests {
}
}
public async Task Weigh(int weight) {
public async Task Weigh(int weight, int tare = 0) {
Weight = weight;
Tare = tare;
await Weigh();
}
public async Task Weigh() {
var (res, inc) = Handler(Weight, Error, IdentNr + 1);
var (res, inc) = Handler(Weight, Tare, Error, IdentNr + 1);
if (inc) IdentNr++;
await Client!.GetStream().WriteAsync(Encoding.ASCII.GetBytes(res));
}