diff --git a/Directory.Build.props b/Directory.Build.props index 958da56..8e2aabf 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -18,10 +18,10 @@ S125;CA1848;CA1002;CA1515;S1118 - true - true - true - true + false + false + false + false $(NoWarn);CA5394;CA1707 diff --git a/tests/Directory.Packages.props b/tests/Directory.Packages.props index 3b5e6ce..ced950c 100644 --- a/tests/Directory.Packages.props +++ b/tests/Directory.Packages.props @@ -8,10 +8,11 @@ + - + \ No newline at end of file diff --git a/tests/IntegrationTests/ApiEndpointsTests.cs b/tests/IntegrationTests/ApiEndpointsTests.cs index 11e53cb..31fc014 100644 --- a/tests/IntegrationTests/ApiEndpointsTests.cs +++ b/tests/IntegrationTests/ApiEndpointsTests.cs @@ -9,7 +9,7 @@ namespace IntegrationTests; -public sealed class ApiEndpointsTests(Fixture fixture) : IntegrationTestBase(fixture) +public sealed class ApiEndpointsTests(Fixture fixture, ITestOutputHelper outputHelper) : IntegrationTestBase(fixture, outputHelper) { private const string DateFormat = "yyyy-MM-dd"; private const string BaseUrl = "/api/v1"; diff --git a/tests/IntegrationTests/IntegrationTests.csproj b/tests/IntegrationTests/IntegrationTests.csproj index 91b69d8..d80821e 100644 --- a/tests/IntegrationTests/IntegrationTests.csproj +++ b/tests/IntegrationTests/IntegrationTests.csproj @@ -9,6 +9,7 @@ + diff --git a/tests/IntegrationTests/Setup/ApplicationFactory.cs b/tests/IntegrationTests/Setup/ApplicationFactory.cs deleted file mode 100644 index 43b9ba7..0000000 --- a/tests/IntegrationTests/Setup/ApplicationFactory.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Common; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc.Testing; - -namespace IntegrationTests.Setup; - -public sealed class ApplicationFactory(Fixture fixture) : WebApplicationFactory -{ - protected override void ConfigureWebHost(IWebHostBuilder builder) - { - if (EnvVarAccessors.UseMocking) - { - builder?.UseSetting(EnvVarKeys.MarketClientUrl, $"http://localhost:{fixture.GetPort()}"); - } - } -} diff --git a/tests/IntegrationTests/Setup/IntegrationTestBase.cs b/tests/IntegrationTests/Setup/IntegrationTestBase.cs index 514e9b4..67f7542 100644 --- a/tests/IntegrationTests/Setup/IntegrationTestBase.cs +++ b/tests/IntegrationTests/Setup/IntegrationTestBase.cs @@ -4,12 +4,13 @@ namespace IntegrationTests.Setup; public abstract class IntegrationTestBase : IAsyncLifetime { - internal readonly ApplicationFactory _factory; + internal readonly TestApplicationFactory _factory; internal readonly HttpClient _client; - protected IntegrationTestBase(Fixture fixture) + protected IntegrationTestBase(Fixture fixture, ITestOutputHelper outputHelper) { - _factory = new ApplicationFactory(fixture); + _factory = new TestApplicationFactory(fixture); + _factory.SetTestOutputHelper(outputHelper); _client = _factory.CreateClient(); } diff --git a/tests/IntegrationTests/Setup/TestApplicationFactory.cs b/tests/IntegrationTests/Setup/TestApplicationFactory.cs new file mode 100644 index 0000000..9dc034b --- /dev/null +++ b/tests/IntegrationTests/Setup/TestApplicationFactory.cs @@ -0,0 +1,43 @@ +using Common; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc.Testing; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Options; +using Serilog; +using Serilog.Sinks.XUnit3; +using Xunit; + +namespace IntegrationTests.Setup; + +public sealed class TestApplicationFactory(Fixture fixture) : WebApplicationFactory +{ + protected override void ConfigureWebHost(IWebHostBuilder builder) + { + if (EnvVarAccessors.UseMocking) + { + builder?.UseSetting(EnvVarKeys.MarketClientUrl, $"http://localhost:{fixture.GetPort()}"); + } + } + + protected override IHost CreateHost(IHostBuilder builder) + { + builder.ConfigureServices(services => + { + services.AddSingleton(Options.Create(new XUnit3TestOutputSinkOptions())); + services.AddSingleton(); + }); + + builder.UseSerilog((ctx, sp, config) => + config.MinimumLevel.Information() + .MinimumLevel.Override("System", Serilog.Events.LogEventLevel.Error) + .MinimumLevel.Override("Microsoft.AspNetCore", Serilog.Events.LogEventLevel.Error) + .WriteTo.XUnit3TestOutput(sp.GetRequiredService()) + ); + + return base.CreateHost(builder); + } + + public void SetTestOutputHelper(ITestOutputHelper testOutputHelper) => + Services.GetRequiredService().TestOutputHelper = testOutputHelper; +} diff --git a/tests/IntegrationTests/packages.lock.json b/tests/IntegrationTests/packages.lock.json index 8a31c45..454c4a9 100644 --- a/tests/IntegrationTests/packages.lock.json +++ b/tests/IntegrationTests/packages.lock.json @@ -34,6 +34,17 @@ "Microsoft.Testing.Platform": "1.8.4" } }, + "Serilog.Sinks.XUnit3": { + "type": "Direct", + "requested": "[1.1.0, )", + "resolved": "1.1.0", + "contentHash": "XqGy76yqRh9pj4FGqpjDlU8fjuw7QnXrYOuBNaLgtyvBn+/ALtCQqyiG6AqYByHkynCzkz1Dx383P1OHyyTg/Q==", + "dependencies": { + "Microsoft.Extensions.Options": "9.0.9", + "Serilog": "4.3.0", + "xunit.v3.extensibility.core": "3.0.1" + } + }, "Shouldly": { "type": "Direct", "requested": "[4.3.0, )",