2025-03-06 04:17:44 +00:00
// Copyright (c) Duende Software. All rights reserved.
2025-03-01 18:55:40 +00:00
// See LICENSE in the project root for license information.
2025-08-29 20:08:52 +00:00
namespace Duende.Xunit.Playwright ;
2025-01-09 08:18:52 +00:00
2025-08-29 20:08:52 +00:00
public class IntegrationTestBase < THost > : IDisposable where THost : class
2025-01-09 08:18:52 +00:00
{
private readonly IDisposable _loggingScope ;
2026-02-18 08:54:01 +00:00
private readonly ITestOutputHelper _testOutputHelper = TestContext . Current . TestOutputHelper ! ;
2025-01-09 08:18:52 +00:00
2026-02-18 08:54:01 +00:00
public IntegrationTestBase ( AppHostFixture < THost > fixture )
2025-01-09 08:18:52 +00:00
{
2025-01-14 14:59:42 +00:00
Fixture = fixture ;
2026-02-18 08:54:01 +00:00
_loggingScope = fixture . ConnectLogger ( _testOutputHelper . WriteLine ) ;
2025-01-14 14:59:42 +00:00
if ( Fixture . UsingAlreadyRunningInstance )
2025-01-09 08:18:52 +00:00
{
2026-02-18 08:54:01 +00:00
_testOutputHelper . WriteLine ( "Running tests against locally running instance" ) ;
2025-01-09 08:18:52 +00:00
}
else
{
#if DEBUG_NCRUNCH
2025-01-14 14:59:42 +00:00
// Running in NCrunch. NCrunch cannot build the aspire project, so it needs
2025-08-29 20:08:52 +00:00
// to be started manually.
2026-02-18 08:54:01 +00:00
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. " ) ;
2025-01-09 08:18:52 +00:00
#endif
}
}
2025-08-29 20:08:52 +00:00
public AppHostFixture < THost > Fixture { get ; }
2025-01-09 08:18:52 +00:00
2026-02-18 08:54:01 +00:00
public ITestOutputHelper TestOutputHelper = > _testOutputHelper ;
2025-01-09 08:18:52 +00:00
public void Dispose ( )
{
2025-01-14 14:59:42 +00:00
if ( ! Fixture . UsingAlreadyRunningInstance )
2025-01-09 08:18:52 +00:00
{
2026-02-18 08:54:01 +00:00
_testOutputHelper . WriteLine ( Environment . NewLine ) ;
_testOutputHelper . WriteLine ( Environment . NewLine ) ;
_testOutputHelper . WriteLine ( Environment . NewLine ) ;
_testOutputHelper . WriteLine ( "*************************************************" ) ;
_testOutputHelper . WriteLine ( "** Startup logs ***" ) ;
_testOutputHelper . WriteLine ( "*************************************************" ) ;
_testOutputHelper . WriteLine ( Fixture . StartupLogs ) ;
2025-01-09 08:18:52 +00:00
}
_loggingScope . Dispose ( ) ;
}
2025-01-14 14:59:42 +00:00
2025-04-07 06:10:10 +00:00
public HttpClient CreateHttpClient ( string clientName ) = > Fixture . CreateHttpClient ( clientName ) ;
2025-03-06 04:26:44 +00:00
}