From 1cbf9656575f547455d8091ed2c6c1be6bd95f25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Ty=C5=84ski?= Date: Sun, 4 Oct 2026 01:49:56 +0200 Subject: [PATCH] test(backend): add xUnit tests for the API skeleton Add tests/TarninaHub.Tests with health controller and SurrealDB endpoint builder tests, and register the test and layer projects in the solution. --- TarninaHub.slnx | 6 ++++ .../Controllers/HealthControllerTests.cs | 19 +++++++++++ .../Infrastructure/SurrealDbEndpointTests.cs | 34 +++++++++++++++++++ .../TarninaHub.Tests/TarninaHub.Tests.csproj | 26 ++++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 tests/TarninaHub.Tests/Controllers/HealthControllerTests.cs create mode 100644 tests/TarninaHub.Tests/Infrastructure/SurrealDbEndpointTests.cs create mode 100644 tests/TarninaHub.Tests/TarninaHub.Tests.csproj diff --git a/TarninaHub.slnx b/TarninaHub.slnx index 5c442a9..cd4ef04 100644 --- a/TarninaHub.slnx +++ b/TarninaHub.slnx @@ -1,5 +1,11 @@ + + + + + + diff --git a/tests/TarninaHub.Tests/Controllers/HealthControllerTests.cs b/tests/TarninaHub.Tests/Controllers/HealthControllerTests.cs new file mode 100644 index 0000000..00f868a --- /dev/null +++ b/tests/TarninaHub.Tests/Controllers/HealthControllerTests.cs @@ -0,0 +1,19 @@ +using Microsoft.AspNetCore.Mvc; +using TarninaHub.Controllers; + +namespace TarninaHub.Tests.Controllers; + +public class HealthControllerTests +{ + [Fact] + public void Get_ReturnsOkWithHealthyStatus() + { + var controller = new HealthController(); + + var result = controller.Get(); + + var ok = Assert.IsType(result.Result); + var payload = Assert.IsType(ok.Value); + Assert.Equal("ok", payload.Status); + } +} diff --git a/tests/TarninaHub.Tests/Infrastructure/SurrealDbEndpointTests.cs b/tests/TarninaHub.Tests/Infrastructure/SurrealDbEndpointTests.cs new file mode 100644 index 0000000..1a70e9a --- /dev/null +++ b/tests/TarninaHub.Tests/Infrastructure/SurrealDbEndpointTests.cs @@ -0,0 +1,34 @@ +using TarninaHub.Infrastructure.Settings; + +namespace TarninaHub.Tests.Infrastructure; + +public class SurrealDbEndpointTests +{ + [Fact] + public void Build_ReturnsRemoteUrl_WhenConfigured() + { + var settings = new SurrealDbSettings + { + RemoteUrl = "ws://127.0.0.1:8010/rpc", + }; + + var endpoint = SurrealDbEndpoint.Build(settings); + + Assert.Equal("ws://127.0.0.1:8010/rpc", endpoint); + } + + [Fact] + public void Build_ReturnsRocksDbEndpoint_WithForwardSlashes_WhenEmbedded() + { + var settings = new SurrealDbSettings + { + DataDirectory = "data", + }; + + var endpoint = SurrealDbEndpoint.Build(settings); + + Assert.StartsWith("rocksdb://", endpoint); + Assert.DoesNotContain('\\', endpoint); + Assert.EndsWith("/data", endpoint); + } +} diff --git a/tests/TarninaHub.Tests/TarninaHub.Tests.csproj b/tests/TarninaHub.Tests/TarninaHub.Tests.csproj new file mode 100644 index 0000000..ea8fe06 --- /dev/null +++ b/tests/TarninaHub.Tests/TarninaHub.Tests.csproj @@ -0,0 +1,26 @@ + + + + net10.0 + enable + enable + false + + + + + + + + + + + + + + + + + + + \ No newline at end of file