test(core/browser/platform): 26 extreme RED/GREEN TDD cycles and full regression hardening (3,235 PASS)
This commit is contained in:
parent
bcd242691f
commit
8677853822
100 changed files with 4814 additions and 333 deletions
152
tests/Paca.Tests/Server/ServerResilienceExtremeRedTests.cs
Normal file
152
tests/Paca.Tests/Server/ServerResilienceExtremeRedTests.cs
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Paca.Core.Platform;
|
||||
using Paca.Server;
|
||||
using Paca.Server.Discovery;
|
||||
using Xunit;
|
||||
|
||||
namespace Paca.Tests.Server;
|
||||
|
||||
public class ServerResilienceExtremeRedTests
|
||||
{
|
||||
// ==========================================
|
||||
// 1. PositionStore
|
||||
// ==========================================
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
public void PositionStore_Get_NullOrEmptyId_ReturnsZero(string? id)
|
||||
{
|
||||
var tempDir = Path.Combine(Path.GetTempPath(), "paca_test_pos_" + Guid.NewGuid().ToString("N"));
|
||||
try
|
||||
{
|
||||
var store = new PositionStore(tempDir);
|
||||
var pos = store.Get(id!);
|
||||
Assert.Equal(0, pos);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (Directory.Exists(tempDir)) Directory.Delete(tempDir, true);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
public void PositionStore_Set_NullOrWhitespaceId_DoesNotThrowAndDoesNotPersist(string? id)
|
||||
{
|
||||
var tempDir = Path.Combine(Path.GetTempPath(), "paca_test_pos_" + Guid.NewGuid().ToString("N"));
|
||||
try
|
||||
{
|
||||
var store = new PositionStore(tempDir);
|
||||
var ex = Record.Exception(() => store.Set(id!, 42.5));
|
||||
Assert.Null(ex);
|
||||
Assert.Equal(0, store.Get(id!));
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (Directory.Exists(tempDir)) Directory.Delete(tempDir, true);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
public void PositionStore_Constructor_NullOrEmptyFolder_DoesNotCrash(string? folder)
|
||||
{
|
||||
var ex = Record.Exception(() =>
|
||||
{
|
||||
var store = new PositionStore(folder!);
|
||||
var testKey = "test-key-" + Guid.NewGuid().ToString("N");
|
||||
Assert.Equal(0, store.Get(testKey));
|
||||
store.Set(testKey, 15.0);
|
||||
Assert.Equal(15.0, store.Get(testKey));
|
||||
});
|
||||
Assert.Null(ex);
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// 2. Thumbnailer
|
||||
// ==========================================
|
||||
|
||||
[Theory]
|
||||
[InlineData(null, "C:\\media\\test.mp4")]
|
||||
[InlineData("ffmpeg.exe", null)]
|
||||
[InlineData("", "C:\\media\\test.mp4")]
|
||||
[InlineData("ffmpeg.exe", " ")]
|
||||
public async Task Thumbnailer_GetThumbnailAsync_NullOrEmptyInputs_ReturnsNull(string? ffmpeg, string? media)
|
||||
{
|
||||
var thumb = new Thumbnailer(DesktopProcessRunner.Default);
|
||||
var res = await thumb.GetThumbnailAsync(ffmpeg!, media!);
|
||||
Assert.Null(res);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null, "C:\\media\\test.mp4")]
|
||||
[InlineData("ffmpeg.exe", null)]
|
||||
[InlineData("", "C:\\media\\test.mp4")]
|
||||
[InlineData("ffmpeg.exe", " ")]
|
||||
public async Task Thumbnailer_GetResolutionAsync_NullOrEmptyInputs_ReturnsNull(string? ffmpeg, string? media)
|
||||
{
|
||||
var thumb = new Thumbnailer(DesktopProcessRunner.Default);
|
||||
var res = await thumb.GetResolutionAsync(ffmpeg!, media!);
|
||||
Assert.Null(res);
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// 3. MediaLibrary
|
||||
// ==========================================
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
public void MediaLibrary_List_NullOrEmptyFolder_ReturnsEmpty(string? folder)
|
||||
{
|
||||
var list = MediaLibrary.List(folder!);
|
||||
Assert.NotNull(list);
|
||||
Assert.Empty(list);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null, "some-id")]
|
||||
[InlineData("C:\\Media", null)]
|
||||
[InlineData("", "some-id")]
|
||||
[InlineData("C:\\Media", " ")]
|
||||
public void MediaLibrary_Find_NullOrEmptyParameters_ReturnsNull(string? folder, string? id)
|
||||
{
|
||||
var item = MediaLibrary.Find(folder!, id!);
|
||||
Assert.Null(item);
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// 4. LanBeaconResponder
|
||||
// ==========================================
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
[InlineData("GARBAGE_PAYLOAD")]
|
||||
[InlineData("{ \"invalid\": true }")]
|
||||
public void LanBeaconResponder_ProcessIncomingPayload_NullOrGarbagePayload_ReturnsNull(string? payload)
|
||||
{
|
||||
var responder = new LanBeaconResponder("PACA-TEST", 52100);
|
||||
var response = responder.ProcessIncomingPayload(payload!, "192.168.1.50");
|
||||
Assert.Null(response);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LanBeaconResponder_BuildPongMessage_NullIp_UsesDefaultIp()
|
||||
{
|
||||
var responder = new LanBeaconResponder("PACA-TEST", 52100);
|
||||
var pong = responder.BuildPongMessage(null);
|
||||
Assert.NotNull(pong);
|
||||
Assert.Contains("0.0.0.0", pong.Endpoint);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue