Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .docfx/Dockerfile.docfx
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion .nuget/Codebelt.Extensions.Xunit.App/PackageReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 10 additions & 1 deletion .nuget/Codebelt.Extensions.Xunit.Hosting/PackageReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 7 additions & 1 deletion .nuget/Codebelt.Extensions.Xunit/PackageReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
26 changes: 13 additions & 13 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Cuemon.Core" Version="9.0.5" />
<PackageVersion Include="Cuemon.Extensions.AspNetCore" Version="9.0.5" />
<PackageVersion Include="Cuemon.Extensions.IO" Version="9.0.5" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.5" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
<PackageVersion Include="Cuemon.Core" Version="9.0.6" />
<PackageVersion Include="Cuemon.Extensions.AspNetCore" Version="9.0.6" />
<PackageVersion Include="Cuemon.Extensions.IO" Version="9.0.6" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.6" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageVersion Include="MinVer" Version="6.0.0" />
<PackageVersion Include="NativeLibraryLoader" Version="1.0.13" />
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.6.3" />
Expand All @@ -20,23 +20,23 @@
<PackageVersion Include="xunit.assert" Version="2.9.3" />
<PackageVersion Include="xunit.extensibility.core" Version="2.9.3" />
<PackageVersion Include="xunit.runner.console" Version="2.9.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.1" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('net9'))">
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="9.0.5" />
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.5" />
<PackageVersion Include="Microsoft.Extensions.Configuration.FileExtensions" Version="9.0.5" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="9.0.5" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="9.0.5" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="9.0.5" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="9.0.6" />
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.6" />
<PackageVersion Include="Microsoft.Extensions.Configuration.FileExtensions" Version="9.0.6" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="9.0.6" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="9.0.6" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="9.0.6" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('net8')) OR $(TargetFramework.StartsWith('netstandard2'))">
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="8.0.16" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="8.0.17" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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<ILoggerProvider>(provider =>
{
var accessor = provider.GetRequiredService<ITestOutputHelperAccessor>();
accessor.TestOutput = output;
return new XunitTestLoggerProvider(accessor);
});
});
AddTestOutputHelperAccessor(services, minimumLevel);
}
else
{
Expand All @@ -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<ILoggerProvider>(provider =>
{
var accessor = provider.GetRequiredService<ITestOutputHelperAccessor>();
return new XunitTestLoggerProvider(accessor);
});
});
}

/// <summary>
/// Adds a default implementation of <see cref="ITestOutputHelperAccessor"/> to the <paramref name="services"/> collection.
/// </summary>
Expand Down
10 changes: 8 additions & 2 deletions src/Codebelt.Extensions.Xunit.Hosting/XunitTestLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@

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)
{

Check warning on line 44 in src/Codebelt.Extensions.Xunit.Hosting/XunitTestLogger.cs

View check run for this annotation

Codecov / codecov/patch

src/Codebelt.Extensions.Xunit.Hosting/XunitTestLogger.cs#L43-L44

Added lines #L43 - L44 were not covered by tests
// can happen when there is no currently active test
}

Check warning on line 46 in src/Codebelt.Extensions.Xunit.Hosting/XunitTestLogger.cs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L46 was not covered by tests
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ILogger<ServiceCollectionExtensions>>();
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<ITestOutputHelperAccessor>().TestOutput = TestOutput;

var logger = test.Host.Services.GetRequiredService<ILogger<ServiceCollectionExtensions>>();
logger.LogInformation("Test");

var store = logger.GetTestStore();

Assert.Equal("Information: Test", store.Query().First().Message);
}
}
}
2 changes: 1 addition & 1 deletion testenvironments.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
Loading