Skip to content

Commit a24e7c5

Browse files
committed
Output server side errors with stack trace in integration testing
1 parent 706f946 commit a24e7c5

File tree

9 files changed

+42
-9
lines changed

9 files changed

+42
-9
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
run: dotnet build -c Release --no-restore
3434
- name: Test & collect coverage
3535
run: |
36-
dotnet test -c Release --no-restore --no-build -- \
36+
dotnet test -c Release --no-restore --no-build Tests/IntegrationTests/IntegrationTests.csproj -- \
3737
--coverage --coverage-output-format xml --coverage-output ${{ github.workspace }}/coverage.xml
3838
- name: Find coverage files and generate report
3939
run: |

App/Api/Setup/ApiMiddleware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static void ConfigureMiddleware(this WebApplication app, IWebHostEnvironm
1313

1414
app.UseRouting();
1515

16-
app.UseOutputCache();
16+
// app.UseOutputCache();
1717

1818
const string documentName = "/openapi/v1.json";
1919
const string apiName = "Bitcoin Web API v1";

App/Api/Setup/ApiServices.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ public static void ConfigureServices(this IServiceCollection services, IWebHostE
6060
opt.AddServerHeader = false;
6161
});
6262

63-
services.AddOutputCache(opt =>
64-
{
65-
opt.DefaultExpirationTimeSpan = TimeSpan.FromSeconds(10);
66-
opt.AddBasePolicy(builder => builder.Cache());
67-
});
63+
// services.AddOutputCache(opt =>
64+
// {
65+
// opt.DefaultExpirationTimeSpan = TimeSpan.FromSeconds(10);
66+
// opt.AddBasePolicy(builder => builder.Cache());
67+
// });
6868

6969
services.AddHsts(opt =>
7070
{

App/Services/MarketService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public class MarketService(ILogger<MarketService> logger, IMarketClient marketCl
2121
var prices = data.Select(x => x.Price).ToList();
2222
var longestDownwardPriceTrend = prices.LongestConsecutiveDecreasingSubset();
2323
_logger.LogInformation("Longest downward price trend {LongestDownwardPriceTrend} days.", longestDownwardPriceTrend);
24-
return longestDownwardPriceTrend;
24+
throw new InvalidOperationException("TEST EXCEPTION");
25+
// return longestDownwardPriceTrend;
2526
}
2627

2728
public async Task<(DateOnly Date, decimal Volume)?> GetHighestTradingVolume(DateOnly fromDate, DateOnly toDate)

Tests/Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
55
</PropertyGroup>
66
<ItemGroup>
7+
<PackageVersion Include="MartinCostello.Logging.XUnit.v3" Version="0.5.1" />
78
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.4" />
89
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
910
<PackageVersion Include="Microsoft.Testing.Extensions.CodeCoverage" Version="17.14.2" />

Tests/IntegrationTests/ApiEndpointsTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public sealed class ApiEndpointsTests(ApplicationFactory factory) : IntegrationT
2424
[MemberData(nameof(Cases))]
2525
public async Task LongestDownwardTrend(string? fromDate, string? toDate, HttpStatusCode status)
2626
{
27+
_factory.SetOutputHelper(TestContext.Current.TestOutputHelper);
2728
var ct = TestContext.Current.CancellationToken;
2829
var result = await _client.GetAsync($"{BaseUrl}/longestdownwardtrend?fromDate={fromDate}&toDate={toDate}", cancellationToken: ct);
2930
result.StatusCode.ShouldBeOneOf(status, HttpStatusCode.TooManyRequests);

Tests/IntegrationTests/ApplicationFactory.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
1+
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.Extensions.Logging;
13
using Microsoft.AspNetCore.Mvc.Testing;
24
using Xunit;
5+
using MartinCostello.Logging.XUnit;
36

47
namespace IntegrationTests;
58

6-
public sealed class ApplicationFactory : WebApplicationFactory<Program>, IAsyncLifetime
9+
public sealed class ApplicationFactory : WebApplicationFactory<Program>, IAsyncLifetime, ITestOutputHelperAccessor
710
{
11+
12+
public ITestOutputHelper? OutputHelper { get; set; }
13+
14+
public void ClearOutputHelper()
15+
=> OutputHelper = null;
16+
17+
public void SetOutputHelper(ITestOutputHelper? value)
18+
=> OutputHelper = value;
19+
20+
protected override void ConfigureWebHost(IWebHostBuilder builder)
21+
{
22+
builder.ConfigureLogging(loggingBuilder =>
23+
loggingBuilder.ClearProviders().AddXUnit(this)
24+
);
25+
}
26+
827
public ValueTask InitializeAsync()
928
{
1029
return ValueTask.CompletedTask;

Tests/IntegrationTests/IntegrationTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
</PropertyGroup>
88
<ItemGroup>
99
<ProjectReference Include="..\..\App\Api\Api.csproj" />
10+
<PackageReference Include="MartinCostello.Logging.XUnit.v3" />
1011
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" />
1112
<PackageReference Include="Microsoft.NET.Test.Sdk" />
1213
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" />

Tests/IntegrationTests/packages.lock.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
"version": 2,
33
"dependencies": {
44
"net9.0": {
5+
"MartinCostello.Logging.XUnit.v3": {
6+
"type": "Direct",
7+
"requested": "[0.5.1, )",
8+
"resolved": "0.5.1",
9+
"contentHash": "VBh06CBetEzaVJbSajn78sn8HZMnL5ZS7RKL4IGbyYkrw65cq7AueKIUw/oYDxwzd/gw2myBuIUjib5EJnEWgg==",
10+
"dependencies": {
11+
"Microsoft.Extensions.Logging": "8.0.1",
12+
"xunit.v3.extensibility.core": "1.0.0"
13+
}
14+
},
515
"Microsoft.AspNetCore.Mvc.Testing": {
616
"type": "Direct",
717
"requested": "[9.0.4, )",

0 commit comments

Comments
 (0)