65 lines
2.1 KiB
C#
65 lines
2.1 KiB
C#
using System.Net;
|
|
using Recordingtest.EgPlugin;
|
|
using Xunit;
|
|
|
|
namespace Recordingtest.EgPlugin.Tests;
|
|
|
|
public class StateRouterTests
|
|
{
|
|
private sealed class FixedProvider : IEngineStateProvider
|
|
{
|
|
public IReadOnlyList<string> GetSelectedIds() => new[] { "x", "y" };
|
|
public CameraSnapshot GetCamera() => new(new double[] { 1, 2, 3 }, new double[] { 0, 0, 0 }, new double[] { 0, 0, 1 }, 45);
|
|
public SceneSnapshot GetScene() => new(7, "doc.hmeg");
|
|
public bool GetRenderComplete() => true;
|
|
}
|
|
|
|
private sealed class FaultyProvider : IEngineStateProvider
|
|
{
|
|
public IReadOnlyList<string> GetSelectedIds() => throw new InvalidOperationException("boom");
|
|
public CameraSnapshot GetCamera() => throw new InvalidOperationException();
|
|
public SceneSnapshot GetScene() => throw new InvalidOperationException();
|
|
public bool GetRenderComplete() => throw new InvalidOperationException();
|
|
}
|
|
|
|
[Fact]
|
|
public void StateRouter_SelectionPath_UsesProvider_ReturnsJson()
|
|
{
|
|
var r = new StateRouter(new FixedProvider(), 38080);
|
|
var (status, body) = r.Route("/selection");
|
|
Assert.Equal(HttpStatusCode.OK, status);
|
|
Assert.Contains("\"selected_ids\":[\"x\",\"y\"]", body);
|
|
}
|
|
|
|
[Fact]
|
|
public void StateRouter_FaultyProvider_ReturnsErrorPayload()
|
|
{
|
|
var r = new StateRouter(new FaultyProvider(), 38080);
|
|
var (_, body) = r.Route("/selection");
|
|
Assert.Contains("\"error\"", body);
|
|
Assert.Contains("boom", body);
|
|
}
|
|
|
|
[Fact]
|
|
public void StateRouter_UnknownPath_Returns404()
|
|
{
|
|
var r = new StateRouter(new FixedProvider(), 38080);
|
|
var (status, _) = r.Route("/nope");
|
|
Assert.Equal(HttpStatusCode.NotFound, status);
|
|
}
|
|
|
|
[Fact]
|
|
public void PortResolver_EnvVarSet_ReturnsEnvPort()
|
|
{
|
|
var p = PortResolver.Resolve(_ => "45000");
|
|
Assert.Equal(45000, p);
|
|
}
|
|
|
|
[Fact]
|
|
public void PortResolver_EnvVarMissing_ReturnsDefault()
|
|
{
|
|
var p = PortResolver.Resolve(_ => null);
|
|
Assert.Equal(PortResolver.DefaultPort, p);
|
|
}
|
|
}
|