39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Mvc.Testing;
|
|
|
|
namespace ItWorx.KnowledgeHub.Api.Tests;
|
|
|
|
public sealed class KnowledgeHubApiFactory : WebApplicationFactory<Program>
|
|
{
|
|
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
|
{
|
|
builder.UseContentRoot(
|
|
Path.Combine(
|
|
FindRepositoryRoot().FullName,
|
|
"src",
|
|
"backend",
|
|
"ItWorx.KnowledgeHub.Api"));
|
|
|
|
builder.UseEnvironment("Test");
|
|
}
|
|
|
|
private static DirectoryInfo FindRepositoryRoot()
|
|
{
|
|
DirectoryInfo? current = new(AppContext.BaseDirectory);
|
|
|
|
while (current is not null)
|
|
{
|
|
if (File.Exists(Path.Combine(current.FullName, "global.json"))
|
|
&& (File.Exists(Path.Combine(current.FullName, "CLAUDE.md"))
|
|
|| File.Exists(Path.Combine(current.FullName, "PUBLIC_SOURCE_EXPORT.md"))))
|
|
{
|
|
return current;
|
|
}
|
|
|
|
current = current.Parent;
|
|
}
|
|
|
|
throw new DirectoryNotFoundException("Could not locate the repository root.");
|
|
}
|
|
}
|