ServiceCollectionExtensions Class
Definition
- Namespace
- Codebelt.Extensions.Xunit.Hosting
- Assemblies
- Codebelt.Extensions.Xunit.Hosting.dll
Extension methods for the IServiceCollection interface.
public static class ServiceCollectionExtensions
- Inheritance
-
ServiceCollectionExtensions
Examples
The following example registers xUnit test logging and output helper services on an IServiceCollection so that ILogger<T> output is captured during a test run. Call AddXunitTestLogging with a minimum LogLevel, then register the ITestOutputHelperAccessor using AddXunitTestLoggingOutputHelperAccessor or a custom implementation with AddXunitTestLoggingOutputHelperAccessor<T>.
using Codebelt.Extensions.Xunit.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace HostFixtureTests;
public class ExampleFixture
{
public IServiceCollection ConfigureServices(IServiceCollection services)
{
services.AddXunitTestLogging(LogLevel.Information);
services.AddXunitTestLoggingOutputHelperAccessor();
return services;
}
}
Methods
| Name | Description |
|---|---|
| AddXunitTestLogging(IServiceCollection, LogLevel) | Adds a unit test optimized implementation of logging to the |
| AddXunitTestLogging(IServiceCollection, ITestOutputHelper, LogLevel) | Adds a unit test optimized implementation of output logging to the |
| AddXunitTestLoggingOutputHelperAccessor(IServiceCollection) | Adds a default implementation of ITestOutputHelperAccessor to the |
| AddXunitTestLoggingOutputHelperAccessor<T>(IServiceCollection) | Adds a specified implementation of ITestOutputHelperAccessor to the |