48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
namespace ItWorx.KnowledgeHub.IntegrationTests.Infrastructure;
|
|
|
|
/// <summary>
|
|
/// Base for test classes that need an already-completed first-run setup (an owner
|
|
/// account, in an isolated database, ready to log in). Each test class gets its own
|
|
/// database and its own owner — never a shared mutable fixture between test classes.
|
|
/// </summary>
|
|
public abstract class OwnerSetupTestBase : IAsyncLifetime
|
|
{
|
|
protected OwnerSetupTestBase(
|
|
PostgresContainerFixture postgres,
|
|
IReadOnlyDictionary<string, string?>? additionalConfiguration = null)
|
|
{
|
|
Factory = new KnowledgeHubIntegrationFactory(postgres, additionalConfiguration);
|
|
}
|
|
|
|
protected KnowledgeHubIntegrationFactory Factory { get; }
|
|
|
|
protected string OwnerEmail { get; } = "eigenaar@itworx.test";
|
|
|
|
protected string OwnerPassword { get; } = "correct-horse-battery-staple";
|
|
|
|
public async Task InitializeAsync()
|
|
{
|
|
await ((IAsyncLifetime)Factory).InitializeAsync();
|
|
|
|
using var client = Factory.CreateClient();
|
|
|
|
var response = await SetupHelper.CompleteFirstRunSetupAsync(
|
|
client,
|
|
"ItWorx Testomgeving",
|
|
"Eigenaar Testpersoon",
|
|
OwnerEmail,
|
|
OwnerPassword);
|
|
|
|
if (!response.IsSuccessStatusCode)
|
|
{
|
|
var body = await response.Content.ReadAsStringAsync();
|
|
throw new InvalidOperationException($"First-run setup failed ({response.StatusCode}): {body}");
|
|
}
|
|
}
|
|
|
|
public async Task DisposeAsync()
|
|
{
|
|
await ((IAsyncLifetime)Factory).DisposeAsync();
|
|
}
|
|
}
|