Files
git.stella-ops.org/src/Graph/__Tests/StellaOps.Graph.Api.Tests/GraphRuntimeRepositoryRegistrationTests.cs
master ee93c0bac2 feat(graph): add Postgres graph runtime repository + compatibility endpoints
Introduces IGraphRuntimeRepository + PostgresGraphRuntimeRepository that back
runtime-path graph reads with real persistence. Graph.Api Program.cs wires
the new repository into the DI graph. InMemory* services get small cleanups
so they remain viable for tests and local dev.

CompatibilityEndpoints: extends the integration-test surface.

Tests: GraphPostgresRuntimeIntegrationTests,
GraphRuntimeRepositoryRegistrationTests, expanded
GraphCompatibilityEndpointsIntegrationTests.

Docs: graph architecture page updated.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 11:15:07 +03:00

64 lines
2.3 KiB
C#

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using StellaOps.Graph.Api.Services;
namespace StellaOps.Graph.Api.Tests;
public sealed class GraphRuntimeRepositoryRegistrationTests : IClassFixture<GraphApiPostgresFixture>
{
private readonly GraphApiPostgresFixture _fixture;
public GraphRuntimeRepositoryRegistrationTests(GraphApiPostgresFixture fixture)
{
_fixture = fixture;
}
[Fact]
[Trait("Category", "Integration")]
[Trait("Intent", "Registration")]
public void Resolves_PostgresRuntimeRepository_WhenConnectionStringIsConfigured()
{
using var factory = CreateFactory(_fixture.ConnectionString);
using var scope = factory.Services.CreateScope();
var repository = scope.ServiceProvider.GetRequiredService<IGraphRuntimeRepository>();
Assert.IsType<PostgresGraphRuntimeRepository>(repository);
}
[Fact]
[Trait("Category", "Integration")]
[Trait("Intent", "Registration")]
public void Resolves_EmptyInMemoryRuntimeRepository_WhenConnectionStringIsMissing()
{
using var factory = CreateFactory(string.Empty);
using var scope = factory.Services.CreateScope();
var repository = scope.ServiceProvider.GetRequiredService<IGraphRuntimeRepository>();
var inMemoryRepository = Assert.IsType<InMemoryGraphRepository>(repository);
Assert.Empty(inMemoryRepository.GetCompatibilityNodes("acme"));
Assert.Empty(inMemoryRepository.GetCompatibilityEdges("acme"));
}
private static WebApplicationFactory<Program> CreateFactory(string? connectionString)
{
return new WebApplicationFactory<Program>()
.WithWebHostBuilder(builder =>
{
builder.UseEnvironment("Development");
builder.ConfigureAppConfiguration((_, configurationBuilder) =>
{
configurationBuilder.AddInMemoryCollection(new Dictionary<string, string?>
{
["Postgres:Graph:ConnectionString"] = connectionString,
["Postgres:Graph:SchemaName"] = "graph",
});
});
});
}
}