52 lines
1.7 KiB
C#
52 lines
1.7 KiB
C#
using Microsoft.Extensions.Logging;
|
|
|
|
namespace HSchool.AppHost.Tests;
|
|
|
|
/// <summary>
|
|
/// Boots the AppHost once for the whole suite — starting it per test costs about ten
|
|
/// seconds each. The client resource is skipped (<c>HSchool:Headless</c>), so the tests
|
|
/// need no Node install.
|
|
/// </summary>
|
|
public sealed class AppHostFixture : IAsyncLifetime
|
|
{
|
|
private static readonly TimeSpan StartupTimeout = TimeSpan.FromSeconds(120);
|
|
|
|
private DistributedApplication? _app;
|
|
|
|
public DistributedApplication App =>
|
|
_app ?? throw new InvalidOperationException("The AppHost has not been started.");
|
|
|
|
public async ValueTask InitializeAsync()
|
|
{
|
|
var appHost = await DistributedApplicationTestingBuilder
|
|
.CreateAsync<Projects.HSchool_AppHost>(["--HSchool:Headless=true"], CancellationToken.None);
|
|
|
|
appHost.Services.AddLogging(logging =>
|
|
{
|
|
logging.SetMinimumLevel(LogLevel.Warning);
|
|
logging.AddFilter("Aspire.", LogLevel.Warning);
|
|
});
|
|
|
|
_app = await appHost.BuildAsync().WaitAsync(StartupTimeout);
|
|
await _app.StartAsync().WaitAsync(StartupTimeout);
|
|
await _app.ResourceNotifications
|
|
.WaitForResourceHealthyAsync("server", CancellationToken.None)
|
|
.WaitAsync(StartupTimeout);
|
|
}
|
|
|
|
public async ValueTask DisposeAsync()
|
|
{
|
|
if (_app is not null)
|
|
{
|
|
await _app.DisposeAsync();
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>Groups every integration test around the single AppHost instance.</summary>
|
|
[CollectionDefinition(Name)]
|
|
public sealed class AppHostCollection : ICollectionFixture<AppHostFixture>
|
|
{
|
|
public const string Name = "apphost";
|
|
}
|