TEST-SOFTWARE

This commit is contained in:
Tim G. | SnapixLP 2025-06-05 23:03:03 +02:00
parent d5bb061987
commit c0462e01b1
2 changed files with 134 additions and 0 deletions

119
TestClient/Program.cs Normal file
View File

@ -0,0 +1,119 @@
using System.Text.Json;
using DX86.Modules;
using Library;
namespace ChatClient;
public class Tester
{
public static async Task Main(string[] args)
{
MessageSender ms = new MessageSender("log.txt");
ItemSelector selector = new ItemSelector(ms);
InputBox inputBox = new InputBox(ms);
MessageBox messageBox = new MessageBox(ms);
Console.Write("Enter the server IP address: ");
string ip = Console.ReadLine();
Console.Write("Enter the port: ");
int port = int.Parse(Console.ReadLine());
Server server = new Server(ip, port);
bool running = true;
string[] testCommands = new[] {
"login",
"logout",
"get self employee",
"get worker byid",
"get worker bycode",
"clock in",
"clock out",
"clock break",
"help"
};
server.OnMessageReceived = (message) =>
{
ms.Log(message);
};
while (running)
{
try
{
string command = selector.SelectItemFromList(testCommands);
if (command == "help")
{
string response = await server.HelpCommand();
// split response into string[] at \n
var responseLines = response.Split('\n').ToList();
await messageBox.ShowAsync("Command Result: Help", responseLines);
}
else if (command == "login")
{
string user = inputBox.ShowAsync("Login", new List<string> { "Enter username" });
string password = inputBox.ShowAsync("Login", new List<string> { "Enter password" });
string response = await server.Login(user, password);
// split response into string[] at \n
var responseLines = response.Split('\n').ToList();
messageBox.ShowAsync("Command Result: Login", responseLines);
}
else if (command == "logout")
{
string response = await server.Logout();
// split response into string[] at \n
var responseLines = response.Split('\n').ToList();
messageBox.ShowAsync("Command Result: Logout", responseLines);
}
else if (command == "get self employee")
{
Employee employee = await server.GetLoggedInEmployee();
messageBox.ShowAsync("Command Result: Get Self Employee", new List<string>
{
$"ID: {employee.Id}",
$"Code: {employee.Code}",
$"Surname: {employee.Surname}",
$"Forename: {employee.Forename}",
});
}
}
catch (Exception ex)
{
await messageBox.ShowAsync("Error", new List<string> { ex.Message });
}
/*
string input = "";
if (command.Contains("login"))
input = inputBox.ShowAsync("Login", new List<string> { "Enter username and password (space-separated)" });
else if (command.Contains("get worker"))
input = inputBox.ShowAsync("Worker", new List<string> { "Enter ID or Code" });
else
inputBox.ShowAsync("Info", new List<string> { "No additional parameters required." });
string fullCmd = $"{command} {input}".Trim();
string response = await server.ExecuteCommandAsync(fullCmd);
try
{
using var doc = JsonDocument.Parse(response);
var formatted = JsonSerializer.Serialize(doc, new JsonSerializerOptions { WriteIndented = true });
await messageBox.ShowAsync("Server Response", formatted.Split('\n').ToList());
}
catch
{
await messageBox.ShowAsync("Server Response", new List<string> { response });
}
string again = inputBox.ShowAsync("Continue?", new List<string> { "Type 'exit' to quit, anything else to continue" });
if (again.Trim().ToLower() == "exit")
running = false;
*/
}
}
}

View File

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DX86\DX86.csproj" />
<ProjectReference Include="..\Library\Library.csproj" />
</ItemGroup>
</Project>