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/.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 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 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. 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/src/Codebelt.Extensions.Xunit.Hosting/ServiceCollectionExtensions.cs b/src/Codebelt.Extensions.Xunit.Hosting/ServiceCollectionExtensions.cs index d60624c..ab42927 100644 --- a/src/Codebelt.Extensions.Xunit.Hosting/ServiceCollectionExtensions.cs +++ b/src/Codebelt.Extensions.Xunit.Hosting/ServiceCollectionExtensions.cs @@ -23,12 +23,18 @@ 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()); - }); - + AddTestOutputHelperAccessor(services, minimumLevel); + } + else + { + services.AddLogging(builder => + { + builder.SetMinimumLevel(minimumLevel); + builder.AddProvider(new XunitTestLoggerProvider()); + }); + } return services; } @@ -49,16 +55,7 @@ public static IServiceCollection AddXunitTestLogging(this IServiceCollection ser if (output == null) { throw new ArgumentNullException(nameof(output)); } if (services.Any(sd => sd.ServiceType == typeof(ITestOutputHelperAccessor))) { - services.AddLogging(builder => - { - builder.SetMinimumLevel(minimumLevel); - builder.Services.AddSingleton(provider => - { - var accessor = provider.GetRequiredService(); - accessor.TestOutput = output; - return new XunitTestLoggerProvider(accessor); - }); - }); + AddTestOutputHelperAccessor(services, minimumLevel); } else { @@ -71,6 +68,19 @@ public static IServiceCollection AddXunitTestLogging(this IServiceCollection ser return services; } + private static void AddTestOutputHelperAccessor(IServiceCollection services, LogLevel minimumLevel) + { + services.AddLogging(builder => + { + builder.SetMinimumLevel(minimumLevel); + builder.Services.AddSingleton(provider => + { + var accessor = provider.GetRequiredService(); + return new XunitTestLoggerProvider(accessor); + }); + }); + } + /// /// Adds a default implementation of to the collection. /// 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 { 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); + } } } 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" } ] }