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.
This commit is contained in:
@@ -1,5 +1,11 @@
|
|||||||
<Solution>
|
<Solution>
|
||||||
<Folder Name="/backend/">
|
<Folder Name="/backend/">
|
||||||
<Project Path="backend/TarninaHub.csproj" />
|
<Project Path="backend/TarninaHub.csproj" />
|
||||||
|
<Project Path="backend/Application/TarninaHub.Application.csproj" />
|
||||||
|
<Project Path="backend/Domain/TarninaHub.Domain.csproj" />
|
||||||
|
<Project Path="backend/Infrastructure/TarninaHub.Infrastructure.csproj" />
|
||||||
|
</Folder>
|
||||||
|
<Folder Name="/tests/">
|
||||||
|
<Project Path="tests/TarninaHub.Tests/TarninaHub.Tests.csproj" />
|
||||||
</Folder>
|
</Folder>
|
||||||
</Solution>
|
</Solution>
|
||||||
|
|||||||
@@ -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<OkObjectResult>(result.Result);
|
||||||
|
var payload = Assert.IsType<HealthResponse>(ok.Value);
|
||||||
|
Assert.Equal("ok", payload.Status);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="coverlet.collector" Version="6.0.4" />
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||||
|
<PackageReference Include="xunit" Version="2.9.3" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Using Include="Xunit" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\backend\TarninaHub.csproj" />
|
||||||
|
<ProjectReference Include="..\..\backend\Infrastructure\TarninaHub.Infrastructure.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
Reference in New Issue
Block a user