Files
SpdUp/SpdUp.Tests/LoggerTests.cs
T
Phil-icyou 19ba425e79 Initial commit: SpdUp Windows Gaming Booster v1.0.0
- .NET 8 WPF app with full MVVM architecture
- One-click boost: CPU, RAM, GPU, network, services, timer resolution
- Real-time system monitor (LibreHardwareMonitor)
- Auto game detection (30+ games)
- RAM optimizer with kernel-level cleanup
- Network optimizer (TCP registry tweaks)
- Service manager, process manager, shader cache cleaner
- Desktop widget overlay
- Debug log viewer
- Custom dark gaming theme with trans pride colors
- 84 unit tests (xUnit)
- Inno Setup installer script
- Landing page website
2026-03-08 17:34:45 +01:00

118 lines
2.8 KiB
C#

using SpdUp.Core;
namespace SpdUp.Tests;
/// <summary>
/// Tests for the Logger class.
/// </summary>
public class LoggerTests
{
[Fact]
public void Info_FiresLogWrittenEvent()
{
string? received = null;
Logger.LogWritten += handler;
try
{
Logger.Info("test info message");
Assert.NotNull(received);
Assert.Contains("[INFO]", received);
Assert.Contains("test info message", received);
}
finally
{
Logger.LogWritten -= handler;
}
void handler(string line) => received = line;
}
[Fact]
public void Warn_FiresLogWrittenEventWithWarnLevel()
{
string? received = null;
Logger.LogWritten += handler;
try
{
Logger.Warn("test warning");
Assert.NotNull(received);
Assert.Contains("[WARN]", received);
Assert.Contains("test warning", received);
}
finally
{
Logger.LogWritten -= handler;
}
void handler(string line) => received = line;
}
[Fact]
public void Error_IncludesExceptionDetails()
{
string? received = null;
Logger.LogWritten += handler;
try
{
Logger.Error("something failed", new InvalidOperationException("bad state"));
Assert.NotNull(received);
Assert.Contains("[ERROR]", received);
Assert.Contains("something failed", received);
Assert.Contains("InvalidOperationException", received);
Assert.Contains("bad state", received);
}
finally
{
Logger.LogWritten -= handler;
}
void handler(string line) => received = line;
}
[Fact]
public void Error_WithoutException_DoesNotContainPipe()
{
string? received = null;
Logger.LogWritten += handler;
try
{
Logger.Error("simple error");
Assert.NotNull(received);
Assert.Contains("[ERROR]", received);
Assert.Contains("simple error", received);
Assert.DoesNotContain("|", received);
}
finally
{
Logger.LogWritten -= handler;
}
void handler(string line) => received = line;
}
[Fact]
public void LogWritten_IncludesTimestamp()
{
string? received = null;
Logger.LogWritten += handler;
try
{
Logger.Info("timestamp check");
Assert.NotNull(received);
// Format: [yyyy-MM-dd HH:mm:ss.fff]
Assert.Matches(@"\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\]", received);
}
finally
{
Logger.LogWritten -= handler;
}
void handler(string line) => received = line;
}
}