Skip to content

Commit 2dbc6a2

Browse files
authored
V10.0.3/service update (#40)
♻️ refactored AddXunitTestLogging overloads to have same logic; e.g., if ITestOutputHelperAccessor is registered, favor this. ♻️ opt-in for same relaxed approach with regards to no active test being present and be forgiving if TestOutput is null ✅ complementary unit tests ⬆️ bump dependencies 💬 updated community health pages 📦 updated NuGet package definition
1 parent 956a241 commit 2dbc6a2

File tree

12 files changed

+125
-37
lines changed

12 files changed

+125
-37
lines changed

.docfx/Dockerfile.docfx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM --platform=$BUILDPLATFORM nginx:1.27.5-alpine AS base
1+
FROM --platform=$BUILDPLATFORM nginx:1.28.0-alpine AS base
22
RUN rm -rf /usr/share/nginx/html/*
33

44
FROM --platform=$BUILDPLATFORM codebeltnet/docfx:2.78.3 AS build
@@ -8,7 +8,7 @@ ADD [".", "docfx"]
88
RUN cd docfx; \
99
docfx build
1010

11-
FROM nginx:1.27.5-alpine AS final
11+
FROM nginx:1.28.0-alpine AS final
1212
WORKDIR /usr/share/nginx/html
1313
COPY --from=build /build/docfx/wwwroot /usr/share/nginx/html
1414

.github/workflows/pipelines.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ jobs:
5959
configuration: ${{ matrix.configuration }}
6060
runs-on: ${{ matrix.os }}
6161
build-switches: -p:SkipSignAssembly=true
62+
restore: true # we need to restore the packages for the test project
6263

6364
sonarcloud:
6465
name: call-sonarcloud

.nuget/Codebelt.Extensions.Xunit.App/PackageReleaseNotes.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
Version 10.0.2
1+
Version 10.0.3
2+
Availability: .NET 9 and .NET 8
3+
 
4+
# ALM
5+
- CHANGED Dependencies have been upgraded to the latest compatible versions for all supported target frameworks (TFMs)
6+
 
7+
Version 10.0.2
28
Availability: .NET 9 and .NET 8
39

410
# ALM

.nuget/Codebelt.Extensions.Xunit.Hosting.AspNetCore/PackageReleaseNotes.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
Version 10.0.2
1+
Version 10.0.3
2+
Availability: .NET 9 and .NET 8
3+
 
4+
# ALM
5+
- CHANGED Dependencies have been upgraded to the latest compatible versions for all supported target frameworks (TFMs)
6+
  
7+
Version 10.0.2
28
Availability: .NET 9 and .NET 8
39

410
# ALM

.nuget/Codebelt.Extensions.Xunit.Hosting/PackageReleaseNotes.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
Version 10.0.2
1+
Version 10.0.3
2+
Availability: .NET 9, .NET 8 and .NET Standard 2.0
3+
 
4+
# ALM
5+
- CHANGED Dependencies have been upgraded to the latest compatible versions for all supported target frameworks (TFMs)
6+
 
7+
# Improvements
8+
- CHANGED AddXunitTestLogging method on the ServiceCollectionExtensions class in the Codebelt.Extensions.Xunit.Hosting namespace to use same logic as the overload equivalent and be forgiving when ITestOutputHelper is null (before an InvalidOperationException was thrown)
9+
 
10+
Version 10.0.2
211
Availability: .NET 9, .NET 8 and .NET Standard 2.0
312

413
# ALM

.nuget/Codebelt.Extensions.Xunit/PackageReleaseNotes.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
Version 10.0.2
1+
Version 10.0.3
2+
Availability: .NET 9 and .NET 8
3+
 
4+
# ALM
5+
- CHANGED Dependencies have been upgraded to the latest compatible versions for all supported target frameworks (TFMs)
6+
 
7+
Version 10.0.2
28
Availability: .NET 9 and .NET 8
39

410
# ALM

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ For more details, please refer to `PackageReleaseNotes.txt` on a per assembly ba
77
> [!NOTE]
88
> Changelog entries prior to version 8.4.0 was migrated from previous versions of Cuemon.Extensions.Xunit, Cuemon.Extensions.Xunit.Hosting, and Cuemon.Extensions.Xunit.Hosting.AspNetCore.
99
10+
## [10.0.3] - 2025-06-15
11+
12+
This is a service update that focuses on package dependencies and minor improvements.
13+
14+
### Changed
15+
16+
- AddXunitTestLogging method on the ServiceCollectionExtensions class in the Codebelt.Extensions.Xunit.Hosting namespace to use same logic as the overload equivalent and be forgiving when ITestOutputHelper is null (before an InvalidOperationException was thrown)
17+
18+
1019
## [10.0.2] - 2025-06-01
1120

1221
This is a minor update that addresses some non-critical issues and improves the overall developer experience of the package.

Directory.Packages.props

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
55
</PropertyGroup>
66
<ItemGroup>
7-
<PackageVersion Include="Cuemon.Core" Version="9.0.5" />
8-
<PackageVersion Include="Cuemon.Extensions.AspNetCore" Version="9.0.5" />
9-
<PackageVersion Include="Cuemon.Extensions.IO" Version="9.0.5" />
10-
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.5" />
11-
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
7+
<PackageVersion Include="Cuemon.Core" Version="9.0.6" />
8+
<PackageVersion Include="Cuemon.Extensions.AspNetCore" Version="9.0.6" />
9+
<PackageVersion Include="Cuemon.Extensions.IO" Version="9.0.6" />
10+
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.6" />
11+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
1212
<PackageVersion Include="MinVer" Version="6.0.0" />
1313
<PackageVersion Include="NativeLibraryLoader" Version="1.0.13" />
1414
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.6.3" />
@@ -20,23 +20,23 @@
2020
<PackageVersion Include="xunit.assert" Version="2.9.3" />
2121
<PackageVersion Include="xunit.extensibility.core" Version="2.9.3" />
2222
<PackageVersion Include="xunit.runner.console" Version="2.9.3" />
23-
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.0" />
23+
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.1" />
2424
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
2525
</ItemGroup>
2626
<ItemGroup Condition="$(TargetFramework.StartsWith('net9'))">
27-
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="9.0.5" />
28-
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.5" />
29-
<PackageVersion Include="Microsoft.Extensions.Configuration.FileExtensions" Version="9.0.5" />
30-
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="9.0.5" />
31-
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="9.0.5" />
32-
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="9.0.5" />
27+
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="9.0.6" />
28+
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.6" />
29+
<PackageVersion Include="Microsoft.Extensions.Configuration.FileExtensions" Version="9.0.6" />
30+
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="9.0.6" />
31+
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="9.0.6" />
32+
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="9.0.6" />
3333
</ItemGroup>
3434
<ItemGroup Condition="$(TargetFramework.StartsWith('net8')) OR $(TargetFramework.StartsWith('netstandard2'))">
3535
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
3636
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
3737
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
3838
<PackageVersion Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.1" />
3939
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
40-
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="8.0.16" />
40+
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="8.0.17" />
4141
</ItemGroup>
4242
</Project>

src/Codebelt.Extensions.Xunit.Hosting/ServiceCollectionExtensions.cs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@ public static class ServiceCollectionExtensions
2323
public static IServiceCollection AddXunitTestLogging(this IServiceCollection services, LogLevel minimumLevel = LogLevel.Trace)
2424
{
2525
if (services == null) { throw new ArgumentNullException(nameof(services)); }
26-
services.AddLogging(builder =>
26+
if (services.Any(sd => sd.ServiceType == typeof(ITestOutputHelperAccessor)))
2727
{
28-
builder.SetMinimumLevel(minimumLevel);
29-
builder.AddProvider(new XunitTestLoggerProvider());
30-
});
31-
28+
AddTestOutputHelperAccessor(services, minimumLevel);
29+
}
30+
else
31+
{
32+
services.AddLogging(builder =>
33+
{
34+
builder.SetMinimumLevel(minimumLevel);
35+
builder.AddProvider(new XunitTestLoggerProvider());
36+
});
37+
}
3238
return services;
3339
}
3440

@@ -49,16 +55,7 @@ public static IServiceCollection AddXunitTestLogging(this IServiceCollection ser
4955
if (output == null) { throw new ArgumentNullException(nameof(output)); }
5056
if (services.Any(sd => sd.ServiceType == typeof(ITestOutputHelperAccessor)))
5157
{
52-
services.AddLogging(builder =>
53-
{
54-
builder.SetMinimumLevel(minimumLevel);
55-
builder.Services.AddSingleton<ILoggerProvider>(provider =>
56-
{
57-
var accessor = provider.GetRequiredService<ITestOutputHelperAccessor>();
58-
accessor.TestOutput = output;
59-
return new XunitTestLoggerProvider(accessor);
60-
});
61-
});
58+
AddTestOutputHelperAccessor(services, minimumLevel);
6259
}
6360
else
6461
{
@@ -71,6 +68,19 @@ public static IServiceCollection AddXunitTestLogging(this IServiceCollection ser
7168
return services;
7269
}
7370

71+
private static void AddTestOutputHelperAccessor(IServiceCollection services, LogLevel minimumLevel)
72+
{
73+
services.AddLogging(builder =>
74+
{
75+
builder.SetMinimumLevel(minimumLevel);
76+
builder.Services.AddSingleton<ILoggerProvider>(provider =>
77+
{
78+
var accessor = provider.GetRequiredService<ITestOutputHelperAccessor>();
79+
return new XunitTestLoggerProvider(accessor);
80+
});
81+
});
82+
}
83+
7484
/// <summary>
7585
/// Adds a default implementation of <see cref="ITestOutputHelperAccessor"/> to the <paramref name="services"/> collection.
7686
/// </summary>

src/Codebelt.Extensions.Xunit.Hosting/XunitTestLogger.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,14 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
3636

3737
if (_accessor != null)
3838
{
39-
if (_accessor.TestOutput == null) { throw new InvalidOperationException($"{nameof(ITestOutputHelperAccessor)}.{nameof(ITestOutputHelperAccessor.TestOutput)} is null."); }
40-
_accessor.TestOutput.WriteLine(message);
39+
try
40+
{
41+
_accessor.TestOutput?.WriteLine(message);
42+
}
43+
catch (InvalidOperationException)
44+
{
45+
// can happen when there is no currently active test
46+
}
4147
}
4248
else
4349
{

0 commit comments

Comments
 (0)