blockers 2

This commit is contained in:
StellaOps Bot
2025-11-23 16:57:18 +02:00
parent cce96f3596
commit 7768555f2d
17 changed files with 220 additions and 69 deletions

View File

@@ -1,7 +1,12 @@
using System.Net;
using System.Net.Http.Json;
using System.Reflection;
using FluentAssertions;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using StellaOps.SbomService.Repositories;
using Xunit;
namespace StellaOps.SbomService.Tests;
@@ -12,7 +17,29 @@ public class ProjectionEndpointTests : IClassFixture<WebApplicationFactory<Progr
public ProjectionEndpointTests(WebApplicationFactory<Program> factory)
{
_factory = factory.WithWebHostBuilder(_ => { });
_factory = factory.WithWebHostBuilder(builder =>
{
var fixturePath = GetProjectionFixturePath();
if (!File.Exists(fixturePath))
{
throw new InvalidOperationException($"Projection fixture missing at {fixturePath}");
}
builder.ConfigureAppConfiguration((_, config) =>
{
config.AddInMemoryCollection(new Dictionary<string, string?>
{
["SbomService:ProjectionsPath"] = fixturePath
});
});
builder.ConfigureServices(services =>
{
// Avoid MongoDB dependency in tests; use seeded in-memory repo.
services.RemoveAll<IComponentLookupRepository>();
services.AddSingleton<IComponentLookupRepository, InMemoryComponentLookupRepository>();
});
});
}
[Fact]
@@ -22,7 +49,11 @@ public class ProjectionEndpointTests : IClassFixture<WebApplicationFactory<Progr
var response = await client.GetAsync("/sboms/snap-001/projection");
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
if (response.StatusCode != HttpStatusCode.BadRequest)
{
var body = await response.Content.ReadAsStringAsync();
throw new Xunit.Sdk.XunitException($"Expected 400 but got {(int)response.StatusCode}: {response.StatusCode}. Body: {body}");
}
}
[Fact]
@@ -42,4 +73,14 @@ public class ProjectionEndpointTests : IClassFixture<WebApplicationFactory<Progr
}
private sealed record ProjectionResponse(string snapshotId, string tenantId, string schemaVersion, string hash, System.Text.Json.JsonElement projection);
private static string GetProjectionFixturePath()
{
// Resolve docs/modules/sbomservice/fixtures/lnm-v1/projections.json relative to test bin directory.
var baseDir = AppContext.BaseDirectory;
var candidate = Path.GetFullPath(Path.Combine(
baseDir,
"../../../../../../docs/modules/sbomservice/fixtures/lnm-v1/projections.json"));
return candidate;
}
}