From 4bd1241cbd66abe5a4f0953320ee49807e636041 Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Sun, 15 Jun 2025 17:39:33 +0200 Subject: [PATCH 1/9] :recycle: refactored AddXunitTestLogging overloads to have same logic; e.g., if ITestOutputHelperAccessor is registered, favor this. --- .../ServiceCollectionExtensions.cs | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Codebelt.Extensions.Xunit.Hosting/ServiceCollectionExtensions.cs b/src/Codebelt.Extensions.Xunit.Hosting/ServiceCollectionExtensions.cs index d60624c..ab6961b 100644 --- a/src/Codebelt.Extensions.Xunit.Hosting/ServiceCollectionExtensions.cs +++ b/src/Codebelt.Extensions.Xunit.Hosting/ServiceCollectionExtensions.cs @@ -23,12 +23,26 @@ public static class ServiceCollectionExtensions public static IServiceCollection AddXunitTestLogging(this IServiceCollection services, LogLevel minimumLevel = LogLevel.Trace) { if (services == null) { throw new ArgumentNullException(nameof(services)); } - services.AddLogging(builder => + if (services.Any(sd => sd.ServiceType == typeof(ITestOutputHelperAccessor))) { - builder.SetMinimumLevel(minimumLevel); - builder.AddProvider(new XunitTestLoggerProvider()); - }); - + services.AddLogging(builder => + { + builder.SetMinimumLevel(minimumLevel); + builder.Services.AddSingleton(provider => + { + var accessor = provider.GetRequiredService(); + return new XunitTestLoggerProvider(accessor); + }); + }); + } + else + { + services.AddLogging(builder => + { + builder.SetMinimumLevel(minimumLevel); + builder.AddProvider(new XunitTestLoggerProvider()); + }); + } return services; } From 95e3f56b6235de924167046e92b10635aa068060 Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Sun, 15 Jun 2025 17:41:46 +0200 Subject: [PATCH 2/9] :recycle: opt-in for same relaxed approach with regards to no active test being present and be forgiving if TestOutput is null --- .../XunitTestLogger.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Codebelt.Extensions.Xunit.Hosting/XunitTestLogger.cs b/src/Codebelt.Extensions.Xunit.Hosting/XunitTestLogger.cs index 8410b19..efa5aab 100644 --- a/src/Codebelt.Extensions.Xunit.Hosting/XunitTestLogger.cs +++ b/src/Codebelt.Extensions.Xunit.Hosting/XunitTestLogger.cs @@ -36,8 +36,14 @@ public void Log(LogLevel logLevel, EventId eventId, TState state, Except if (_accessor != null) { - if (_accessor.TestOutput == null) { throw new InvalidOperationException($"{nameof(ITestOutputHelperAccessor)}.{nameof(ITestOutputHelperAccessor.TestOutput)} is null."); } - _accessor.TestOutput.WriteLine(message); + try + { + _accessor.TestOutput?.WriteLine(message); + } + catch (InvalidOperationException) + { + // can happen when there is no currently active test + } } else { From 52018b19b44e85f31430247657f442758c504e43 Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Sun, 15 Jun 2025 17:42:16 +0200 Subject: [PATCH 3/9] :white_check_mark: complementary unit tests --- .../ServiceCollectionExtensions.cs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/Codebelt.Extensions.Xunit.Hosting.Tests/ServiceCollectionExtensions.cs b/test/Codebelt.Extensions.Xunit.Hosting.Tests/ServiceCollectionExtensions.cs index 4fad74c..414a718 100644 --- a/test/Codebelt.Extensions.Xunit.Hosting.Tests/ServiceCollectionExtensions.cs +++ b/test/Codebelt.Extensions.Xunit.Hosting.Tests/ServiceCollectionExtensions.cs @@ -123,5 +123,40 @@ public void AddXunitTestLogging_ShouldAddXunitTestLoggingWithTestOutput() entry => Assert.Equal("Warning: SUT", entry.ToString()), entry => Assert.Equal("Information: Unique message for logger2.", entry.ToString())); } + + [Fact] + public void AddXunitTestLogging_ShouldAddXunitTestLogging_UsingHostTest() + { + using var test = HostTestFactory.Create(services => + { + services.AddXunitTestLogging(); + }); + + var logger = test.Host.Services.GetRequiredService>(); + logger.LogInformation("Test"); + + var store = logger.GetTestStore(); + + Assert.Equal("Information: Test", store.Query().First().Message); + } + + [Fact] + public void AddXunitTestLogging_ShouldAddXunitTestLogging_UsingHostTest_WithOutputToRunner() + { + using var test = HostTestFactory.Create(services => + { + services.AddXunitTestLoggingOutputHelperAccessor(); + services.AddXunitTestLogging(); + }); + + test.Host.Services.GetRequiredService().TestOutput = TestOutput; + + var logger = test.Host.Services.GetRequiredService>(); + logger.LogInformation("Test"); + + var store = logger.GetTestStore(); + + Assert.Equal("Information: Test", store.Query().First().Message); + } } } From b4df21c142c7a1f56e096d3863477a557b72e003 Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Sun, 15 Jun 2025 17:53:02 +0200 Subject: [PATCH 4/9] :arrow_up: bump dependencies --- .docfx/Dockerfile.docfx | 4 ++-- Directory.Packages.props | 26 +++++++++++++------------- testenvironments.json | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.docfx/Dockerfile.docfx b/.docfx/Dockerfile.docfx index 29307d0..dedeef4 100644 --- a/.docfx/Dockerfile.docfx +++ b/.docfx/Dockerfile.docfx @@ -1,4 +1,4 @@ -FROM --platform=$BUILDPLATFORM nginx:1.27.5-alpine AS base +FROM --platform=$BUILDPLATFORM nginx:1.28.0-alpine AS base RUN rm -rf /usr/share/nginx/html/* FROM --platform=$BUILDPLATFORM codebeltnet/docfx:2.78.3 AS build @@ -8,7 +8,7 @@ ADD [".", "docfx"] RUN cd docfx; \ docfx build -FROM nginx:1.27.5-alpine AS final +FROM nginx:1.28.0-alpine AS final WORKDIR /usr/share/nginx/html COPY --from=build /build/docfx/wwwroot /usr/share/nginx/html diff --git a/Directory.Packages.props b/Directory.Packages.props index abaf712..99064dd 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -4,11 +4,11 @@ true - - - - - + + + + + @@ -20,16 +20,16 @@ - + - - - - - - + + + + + + @@ -37,6 +37,6 @@ - + \ No newline at end of file diff --git a/testenvironments.json b/testenvironments.json index 0214cf5..9d87973 100644 --- a/testenvironments.json +++ b/testenvironments.json @@ -9,7 +9,7 @@ { "name": "Docker-Ubuntu", "type": "docker", - "dockerImage": "gimlichael/ubuntu-testrunner:net8.0.409-9.0.300" + "dockerImage": "gimlichael/ubuntu-testrunner:net8.0.411-9.0.301" } ] } From 760abce24f3c8352a7de8ead2472517641f466da Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Sun, 15 Jun 2025 17:53:13 +0200 Subject: [PATCH 5/9] :speech_balloon: updated community health pages --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1217af5..3f39420 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,15 @@ For more details, please refer to `PackageReleaseNotes.txt` on a per assembly ba > [!NOTE] > 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. +## [10.0.3] - 2025-06-15 + +This is a service update that focuses on package dependencies and minor improvements. + +### 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) + + ## [10.0.2] - 2025-06-01 This is a minor update that addresses some non-critical issues and improves the overall developer experience of the package. From 0475464fe4fda4ef7a0930f29c9aba8db58782f6 Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Sun, 15 Jun 2025 17:53:23 +0200 Subject: [PATCH 6/9] :package: updated NuGet package definition --- .../PackageReleaseNotes.txt | 8 +++++++- .../PackageReleaseNotes.txt | 8 +++++++- .../PackageReleaseNotes.txt | 11 ++++++++++- .../Codebelt.Extensions.Xunit/PackageReleaseNotes.txt | 8 +++++++- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/.nuget/Codebelt.Extensions.Xunit.App/PackageReleaseNotes.txt b/.nuget/Codebelt.Extensions.Xunit.App/PackageReleaseNotes.txt index 58e292f..0c0342d 100644 --- a/.nuget/Codebelt.Extensions.Xunit.App/PackageReleaseNotes.txt +++ b/.nuget/Codebelt.Extensions.Xunit.App/PackageReleaseNotes.txt @@ -1,4 +1,10 @@ -Version 10.0.2 +Version 10.0.3 +Availability: .NET 9 and .NET 8 +  +# ALM +- CHANGED Dependencies have been upgraded to the latest compatible versions for all supported target frameworks (TFMs) +  +Version 10.0.2 Availability: .NET 9 and .NET 8   # ALM diff --git a/.nuget/Codebelt.Extensions.Xunit.Hosting.AspNetCore/PackageReleaseNotes.txt b/.nuget/Codebelt.Extensions.Xunit.Hosting.AspNetCore/PackageReleaseNotes.txt index 8778d66..1db22d5 100644 --- a/.nuget/Codebelt.Extensions.Xunit.Hosting.AspNetCore/PackageReleaseNotes.txt +++ b/.nuget/Codebelt.Extensions.Xunit.Hosting.AspNetCore/PackageReleaseNotes.txt @@ -1,4 +1,10 @@ -Version 10.0.2 +Version 10.0.3 +Availability: .NET 9 and .NET 8 +  +# ALM +- CHANGED Dependencies have been upgraded to the latest compatible versions for all supported target frameworks (TFMs) +   +Version 10.0.2 Availability: .NET 9 and .NET 8   # ALM diff --git a/.nuget/Codebelt.Extensions.Xunit.Hosting/PackageReleaseNotes.txt b/.nuget/Codebelt.Extensions.Xunit.Hosting/PackageReleaseNotes.txt index 950a73d..622ee21 100644 --- a/.nuget/Codebelt.Extensions.Xunit.Hosting/PackageReleaseNotes.txt +++ b/.nuget/Codebelt.Extensions.Xunit.Hosting/PackageReleaseNotes.txt @@ -1,4 +1,13 @@ -Version 10.0.2 +Version 10.0.3 +Availability: .NET 9, .NET 8 and .NET Standard 2.0 +  +# ALM +- CHANGED Dependencies have been upgraded to the latest compatible versions for all supported target frameworks (TFMs) +  +# Improvements +- 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) +  +Version 10.0.2 Availability: .NET 9, .NET 8 and .NET Standard 2.0   # ALM diff --git a/.nuget/Codebelt.Extensions.Xunit/PackageReleaseNotes.txt b/.nuget/Codebelt.Extensions.Xunit/PackageReleaseNotes.txt index 537b5ab..5fef153 100644 --- a/.nuget/Codebelt.Extensions.Xunit/PackageReleaseNotes.txt +++ b/.nuget/Codebelt.Extensions.Xunit/PackageReleaseNotes.txt @@ -1,4 +1,10 @@ -Version 10.0.2 +Version 10.0.3 +Availability: .NET 9 and .NET 8 +  +# ALM +- CHANGED Dependencies have been upgraded to the latest compatible versions for all supported target frameworks (TFMs) +  +Version 10.0.2 Availability: .NET 9 and .NET 8   # ALM From eca1ee527f212d183d4513847b8dc6403ca7f3bc Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Sun, 15 Jun 2025 18:23:52 +0200 Subject: [PATCH 7/9] fix --- .github/workflows/pipelines.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pipelines.yml b/.github/workflows/pipelines.yml index 617ebad..acda6e1 100644 --- a/.github/workflows/pipelines.yml +++ b/.github/workflows/pipelines.yml @@ -59,6 +59,7 @@ jobs: configuration: ${{ matrix.configuration }} runs-on: ${{ matrix.os }} build-switches: -p:SkipSignAssembly=true + restore: true # we need to restore the packages for the test project sonarcloud: name: call-sonarcloud From df2f03cf5b27480820e046f2a8ed18b452a52572 Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Sun, 15 Jun 2025 19:22:45 +0200 Subject: [PATCH 8/9] refactored --- .../ServiceCollectionExtensions.cs | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/Codebelt.Extensions.Xunit.Hosting/ServiceCollectionExtensions.cs b/src/Codebelt.Extensions.Xunit.Hosting/ServiceCollectionExtensions.cs index ab6961b..bea18c4 100644 --- a/src/Codebelt.Extensions.Xunit.Hosting/ServiceCollectionExtensions.cs +++ b/src/Codebelt.Extensions.Xunit.Hosting/ServiceCollectionExtensions.cs @@ -25,15 +25,7 @@ public static IServiceCollection AddXunitTestLogging(this IServiceCollection ser if (services == null) { throw new ArgumentNullException(nameof(services)); } if (services.Any(sd => sd.ServiceType == typeof(ITestOutputHelperAccessor))) { - services.AddLogging(builder => - { - builder.SetMinimumLevel(minimumLevel); - builder.Services.AddSingleton(provider => - { - var accessor = provider.GetRequiredService(); - return new XunitTestLoggerProvider(accessor); - }); - }); + AddTestOutputHelperAccessor(services, minimumLevel); } else { @@ -62,27 +54,34 @@ public static IServiceCollection AddXunitTestLogging(this IServiceCollection ser if (services == null) { throw new ArgumentNullException(nameof(services)); } if (output == null) { throw new ArgumentNullException(nameof(output)); } if (services.Any(sd => sd.ServiceType == typeof(ITestOutputHelperAccessor))) + { + AddTestOutputHelperAccessor(services, minimumLevel); + } + else { services.AddLogging(builder => { builder.SetMinimumLevel(minimumLevel); - builder.Services.AddSingleton(provider => - { - var accessor = provider.GetRequiredService(); - accessor.TestOutput = output; - return new XunitTestLoggerProvider(accessor); - }); + builder.AddProvider(new XunitTestLoggerProvider(output)); }); } - else + return services; + } + + private static void AddTestOutputHelperAccessor(IServiceCollection services, LogLevel minimumLevel) + { + if (services.Any(sd => sd.ServiceType == typeof(ITestOutputHelperAccessor))) { services.AddLogging(builder => { builder.SetMinimumLevel(minimumLevel); - builder.AddProvider(new XunitTestLoggerProvider(output)); + builder.Services.AddSingleton(provider => + { + var accessor = provider.GetRequiredService(); + return new XunitTestLoggerProvider(accessor); + }); }); } - return services; } /// From eee1ab668d1636e9de3527533eea7f3b07a149bf Mon Sep 17 00:00:00 2001 From: Michael Mortensen Date: Sun, 15 Jun 2025 19:26:33 +0200 Subject: [PATCH 9/9] fix --- .../ServiceCollectionExtensions.cs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Codebelt.Extensions.Xunit.Hosting/ServiceCollectionExtensions.cs b/src/Codebelt.Extensions.Xunit.Hosting/ServiceCollectionExtensions.cs index bea18c4..ab42927 100644 --- a/src/Codebelt.Extensions.Xunit.Hosting/ServiceCollectionExtensions.cs +++ b/src/Codebelt.Extensions.Xunit.Hosting/ServiceCollectionExtensions.cs @@ -70,18 +70,15 @@ public static IServiceCollection AddXunitTestLogging(this IServiceCollection ser private static void AddTestOutputHelperAccessor(IServiceCollection services, LogLevel minimumLevel) { - if (services.Any(sd => sd.ServiceType == typeof(ITestOutputHelperAccessor))) + services.AddLogging(builder => { - services.AddLogging(builder => + builder.SetMinimumLevel(minimumLevel); + builder.Services.AddSingleton(provider => { - builder.SetMinimumLevel(minimumLevel); - builder.Services.AddSingleton(provider => - { - var accessor = provider.GetRequiredService(); - return new XunitTestLoggerProvider(accessor); - }); + var accessor = provider.GetRequiredService(); + return new XunitTestLoggerProvider(accessor); }); - } + }); } ///