products/shared/Xunit.Playwright/IntegrationTestBase.cs

51 lines
1.9 KiB
C#
Raw Permalink Normal View History

// Copyright (c) Duende Software. All rights reserved.
2025-03-01 18:55:40 +00:00
// See LICENSE in the project root for license information.
namespace Duende.Xunit.Playwright;
public class IntegrationTestBase<THost> : IDisposable where THost : class
{
private readonly IDisposable _loggingScope;
private readonly ITestOutputHelper _testOutputHelper = TestContext.Current.TestOutputHelper!;
public IntegrationTestBase(AppHostFixture<THost> fixture)
{
2025-01-14 14:59:42 +00:00
Fixture = fixture;
_loggingScope = fixture.ConnectLogger(_testOutputHelper.WriteLine);
2025-01-14 14:59:42 +00:00
if (Fixture.UsingAlreadyRunningInstance)
{
_testOutputHelper.WriteLine("Running tests against locally running instance");
}
else
{
#if DEBUG_NCRUNCH
2025-01-14 14:59:42 +00:00
// Running in NCrunch. NCrunch cannot build the aspire project, so it needs
// to be started manually.
Assert.Skip("When running the Host.Tests using NCrunch, you must start the Hosts.AppHost project manually. IE: dotnet run -p bff/samples/Hosts.AppHost. Or start without debugging from the UI. ");
#endif
}
}
public AppHostFixture<THost> Fixture { get; }
public ITestOutputHelper TestOutputHelper => _testOutputHelper;
public void Dispose()
{
2025-01-14 14:59:42 +00:00
if (!Fixture.UsingAlreadyRunningInstance)
{
_testOutputHelper.WriteLine(Environment.NewLine);
_testOutputHelper.WriteLine(Environment.NewLine);
_testOutputHelper.WriteLine(Environment.NewLine);
_testOutputHelper.WriteLine("*************************************************");
_testOutputHelper.WriteLine("** Startup logs ***");
_testOutputHelper.WriteLine("*************************************************");
_testOutputHelper.WriteLine(Fixture.StartupLogs);
}
_loggingScope.Dispose();
}
2025-01-14 14:59:42 +00:00
public HttpClient CreateHttpClient(string clientName) => Fixture.CreateHttpClient(clientName);
}