Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ Availability: .NET 9, .NET 8 and .NET Standard 2.0
- CHANGED Dependencies to latest and greatest with respect to TFMs
- REMOVED Support for TFM .NET 6 (LTS)

# Breaking Changes
- REMOVED AddXunitTestLogging method (the overload that took an ITestOutputHelperAccessor argument) from the ServiceCollectionExtensions class in the Codebelt.Extensions.Xunit.Hosting namespace

# Improvements
- CHANGED AddXunitTestLogging method in the Codebelt.Extensions.Xunit.Hosting namespace to use an ILoggerProvider that utilizes either the ITestOutputHelper instance or a previously provided ITestOutputHelperAccessor service

Version 8.4.1
Availability: .NET 8, .NET 6 and .NET Standard 2.0

Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ This major release is first and foremost focused on ironing out any wrinkles tha
}
```

### Changed

- AddXunitTestLogging method in the Codebelt.Extensions.Xunit.Hosting namespace to use an ILoggerProvider that utilizes either the ITestOutputHelper instance or a previously provided ITestOutputHelperAccessor service

### Removed

- AddXunitTestLogging method (the overload that took an ITestOutputHelperAccessor argument) from the ServiceCollectionExtensions class in the Codebelt.Extensions.Xunit.Hosting namespace

Comment on lines +29 to +32
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking change: Overload of AddXunitTestLogging method removed.

The removal of the AddXunitTestLogging overload that accepted an ITestOutputHelperAccessor argument is a breaking change. Users who were using this specific overload will need to update their code.

To migrate, use the updated AddXunitTestLogging method that now uses an ILoggerProvider capable of working with an ITestOutputHelperAccessor service. This change, while breaking, simplifies the API and reduces complexity for users by consolidating the logging setup.

Please update the documentation to clearly communicate this breaking change and provide guidance on how to migrate to the new approach.

## [8.4.1] - 2024-09-16

### Added
Expand Down
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
</ItemGroup>

<ItemGroup Condition="'$(IsTestProject)' == 'true'">
<PackageReference Include="Cuemon.Core" Version="9.0.0-preview.5" PrivateAssets="all" />
<ProjectReference Include="..\..\src\Codebelt.Extensions.Xunit\Codebelt.Extensions.Xunit.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Cuemon.Extensions.DependencyInjection" Version="9.0.0-preview.5" />
<PackageReference Include="Cuemon.IO" Version="9.0.0-preview.5" />
<PackageReference Include="Cuemon.Extensions.DependencyInjection" Version="9.0.0-preview.5" PrivateAssets="all" />
<PackageReference Include="Cuemon.IO" Version="9.0.0-preview.5" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Cuemon.Core" Version="9.0.0-preview.5" PrivateAssets="all" />
<PackageReference Include="xunit.extensibility.core" Version="2.9.0" />
</ItemGroup>

Expand Down
4 changes: 1 addition & 3 deletions src/Codebelt.Extensions.Xunit.Hosting/LoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
using System.Collections;
using System.Linq;
using Cuemon;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Xunit.Abstractions;

namespace Codebelt.Extensions.Xunit.Hosting
{
Expand All @@ -14,7 +12,7 @@ namespace Codebelt.Extensions.Xunit.Hosting
public static class LoggerExtensions
{
/// <summary>
/// Returns the associated <see cref="ITestStore{T}"/> that is provided when settings up services from either <see cref="ServiceCollectionExtensions.AddXunitTestLogging(IServiceCollection,ITestOutputHelper,LogLevel)"/> or <see cref="ServiceCollectionExtensions.AddXunitTestLogging(IServiceCollection,ITestOutputHelperAccessor,LogLevel)"/>.
/// Returns the associated <see cref="ITestStore{T}"/> that is provided when settings up services from <see cref="ServiceCollectionExtensions.AddXunitTestLogging"/>.
/// </summary>
/// <param name="logger">The <see cref="ILogger{TCategoryName}"/> from which to retrieve the <see cref="ITestStore{T}"/>.</param>
/// <returns>Returns an implementation of <see cref="ITestStore{T}"/> with all logged entries expressed as <see cref="XunitTestLoggerEntry"/>.</returns>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using Cuemon;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
Expand All @@ -21,39 +22,33 @@ public static class ServiceCollectionExtensions
/// <exception cref="ArgumentNullException">
/// <paramref name="services"/> cannot be null -or-
/// <paramref name="output"/> cannot be null.
/// </exception>
/// </exception>
/// <remarks>This method will add a xUnit logger provider based on either <see cref="ITestOutputHelper"/> or <see cref="ITestOutputHelperAccessor"/>.</remarks>
public static IServiceCollection AddXunitTestLogging(this IServiceCollection services, ITestOutputHelper output, LogLevel minimumLevel = LogLevel.Trace)
{
Validator.ThrowIfNull(services);
Validator.ThrowIfNull(output);
services.AddLogging(builder =>
{
builder.SetMinimumLevel(minimumLevel);
builder.AddProvider(new XunitTestLoggerProvider(output));
});
return services;
}

/// <summary>
/// Adds a unit test optimized implementation of output logging to the <paramref name="services"/> collection.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection"/> to extend.</param>
/// <param name="accessor">The <see cref="ITestOutputHelperAccessor"/> that provides access to the output for the logging.</param>
/// <param name="minimumLevel">The <see cref="LogLevel"/> that specifies the minimum level to include for the logging.</param>
/// <returns>A reference to <paramref name="services" /> so that additional configuration calls can be chained.</returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="services"/> cannot be null -or-
/// <paramref name="accessor"/> cannot be null.
/// </exception>
public static IServiceCollection AddXunitTestLogging(this IServiceCollection services, ITestOutputHelperAccessor accessor, LogLevel minimumLevel = LogLevel.Trace)
{
Validator.ThrowIfNull(services);
Validator.ThrowIfNull(accessor);
services.AddLogging(builder =>
{
builder.SetMinimumLevel(minimumLevel);
builder.AddProvider(new XunitTestLoggerProvider(accessor));
});
Validator.ThrowIfNull(output);
if (services.Any(d => d.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);
});
});
}
else
{
services.AddLogging(builder =>
{
builder.SetMinimumLevel(minimumLevel);
builder.AddProvider(new XunitTestLoggerProvider(output));
});
}
return services;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Cuemon.Core" Version="9.0.0-preview.5" />
<PackageReference Include="Cuemon.Core" Version="9.0.0-preview.5" PrivateAssets="all" />
<PackageReference Include="xunit.assert" Version="2.9.0" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public override void ConfigureServices(IServiceCollection services)
o.E = true;
});
services.AddXunitTestLoggingOutputHelperAccessor();
services.AddXunitTestLogging(new TestOutputHelperAccessor(TestOutput));
services.AddXunitTestLogging(TestOutput);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public override void ConfigureServices(IServiceCollection services)
.AddApplicationPart(typeof(FakeController).Assembly);

services.AddXunitTestLoggingOutputHelperAccessor();
services.AddXunitTestLogging(new TestOutputHelperAccessor(TestOutput));
services.AddXunitTestLogging(TestOutput);
}

public override void ConfigureApplication(IApplicationBuilder app)
Expand Down