LANCommander/LANCommander.Server.UI.Tests/FreshServerFixture.cs
Aaron Powell c856a51504 Fix stack overflow on test disposal with FreshServerFixture
- Refactor FirstTimeSetupTests to use FreshServerFixture via ICollectionFixture
  instead of creating its own UITestApplicationFactory per test
- Skip _realHost.Dispose() in UITestApplicationFactory since the DI container's
  deep dependency chain causes an uncatchable native StackOverflowException
- All 62 tests pass with exit code 0 (61 pass, 1 skip)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-08 08:41:11 +11:00

36 lines
1.1 KiB
C#

using Microsoft.Playwright;
namespace LANCommander.Server.UI.Tests;
/// <summary>
/// Fixture for FirstTimeSetupTests that provides a fresh unconfigured server.
/// Unlike ConfiguredServerFixture, this does NOT create an admin user or set DatabaseContext.Provider,
/// so the server will redirect to /FirstTimeSetup.
/// </summary>
public class FreshServerFixture : IAsyncLifetime
{
public PlaywrightFixture Playwright { get; private set; } = null!;
public UITestApplicationFactory Factory { get; private set; } = null!;
public async Task InitializeAsync()
{
Playwright = new PlaywrightFixture();
await Playwright.InitializeAsync();
Factory = new UITestApplicationFactory();
_ = Factory.Services;
}
public async Task DisposeAsync()
{
await Factory.DisposeAsync();
await Playwright.DisposeAsync();
}
public async Task<(IBrowserContext Context, IPage Page)> CreatePageAsync()
{
var context = await Playwright.NewContextAsync(Factory.BaseAddress);
var page = await context.NewPageAsync();
return (context, page);
}
}