Writing some tests, namely the fake game server
This commit is contained in:
1 parent
4f168a6061
commit
30a6fac573
3 files changed
+321
-1
No files matched your search
@@ -0,0 +1,30 @@
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace FakeGameServer;
|
||||
|
||||
internal static class FakeOutput
|
||||
{
|
||||
public static void Log(string category, string message) =>
|
||||
Console.Out.WriteLine($"{Stamp()} [{category}] {message}");
|
||||
|
||||
// Mimics the real game's crash handling: print the error, write a crash log under
|
||||
// <dataPath>/Logs, and exit with a code that is 0 unless a test asks otherwise.
|
||||
public static int Crash(string dataPath, int exitCode, string message)
|
||||
{
|
||||
var text = $"{Stamp()}: Critical error occurred{Environment.NewLine}{message}";
|
||||
Console.Out.WriteLine(text);
|
||||
var logDir = Path.Combine(dataPath, "Logs");
|
||||
Directory.CreateDirectory(logDir);
|
||||
File.WriteAllText(Path.Combine(logDir, "server-crash.log"), text + Environment.NewLine);
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
private static string Stamp() =>
|
||||
DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss", CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
internal static class JsonOptions
|
||||
{
|
||||
public static readonly JsonSerializerOptions Indented = new() { WriteIndented = true };
|
||||
}
|
||||
Reference in new issue
Block a user