Codebelt.Extensions.Xunit.Hosting.AspNetCore 10.0.0

dotnet add package Codebelt.Extensions.Xunit.Hosting.AspNetCore --version 10.0.0
                    
NuGet\Install-Package Codebelt.Extensions.Xunit.Hosting.AspNetCore -Version 10.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Codebelt.Extensions.Xunit.Hosting.AspNetCore" Version="10.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Codebelt.Extensions.Xunit.Hosting.AspNetCore" Version="10.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Codebelt.Extensions.Xunit.Hosting.AspNetCore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Codebelt.Extensions.Xunit.Hosting.AspNetCore --version 10.0.0
                    
#r "nuget: Codebelt.Extensions.Xunit.Hosting.AspNetCore, 10.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Codebelt.Extensions.Xunit.Hosting.AspNetCore&version=10.0.0
                    
Install Codebelt.Extensions.Xunit.Hosting.AspNetCore as a Cake Addin
#tool nuget:?package=Codebelt.Extensions.Xunit.Hosting.AspNetCore&version=10.0.0
                    
Install Codebelt.Extensions.Xunit.Hosting.AspNetCore as a Cake Tool

About

An open-source project (MIT license) that targets and complements the xUnit.net test platform. It provides a uniform and convenient way of doing unit test for all project types in .NET.

Perhaps even more convenient than what WebApplicationFactory has to offer?

It is, by heart, free, flexible and built to extend and boost your agile codebelt.

Codebelt.Extensions.Xunit.Hosting.AspNetCore for .NET

The Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace contains types that provides a uniform way of doing unit testing that depends on ASP.NET Core and used in conjunction with Microsoft Dependency Injection. The namespace relates to the Microsoft.AspNetCore.TestHost namespace.

More documentation available at our documentation site:

CSharp Example

Source: ServerTimingMiddlewareTest.cs

[Fact]
public async Task InvokeAsync_ShouldMimicSimpleAspNetProject()
{
    using var response = await WebHostTestFactory.RunAsync(
        services =>
        {
            services.AddServerTiming(o => o.SuppressHeaderPredicate = _ => false);
        }
        , app =>
        {
            app.UseServerTiming();
            app.Use(async (context, next) =>
            {
                var sw = Stopwatch.StartNew();
                context.Response.OnStarting(() =>
                {
                    sw.Stop();
                    context.RequestServices.GetRequiredService<IServerTiming>().AddServerTiming("use-middleware", sw.Elapsed);
                    return Task.CompletedTask;
                });
                await next(context).ConfigureAwait(false);
            });
            app.Run(context =>
            {
                Thread.Sleep(400);
                return context.Response.WriteAsync("Hello World!");
            });
        }).ConfigureAwait(false);

    Assert.StartsWith("use-middleware;dur=", response.Headers.Single(kvp => kvp.Key == ServerTiming.HeaderName).Value.FirstOrDefault());
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Codebelt.Extensions.Xunit.Hosting.AspNetCore:

Package Downloads
Codebelt.Extensions.Xunit.App

Provides a convenient set of default API additions for building .NET test projects based on xUnit.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
10.0.0 1,334 4/12/2025
10.0.0-preview.3 66 4/12/2025
10.0.0-preview.2 149 4/9/2025
10.0.0-preview.1 123 4/7/2025
9.1.3 226 4/3/2025
9.1.2 363 4/3/2025
9.1.1 158 4/1/2025
9.1.0 154 3/31/2025
9.0.1 596 1/25/2025
9.0.0 1,053 11/13/2024
9.0.0-rc.1 521 11/11/2024
9.0.0-preview.11 131 10/26/2024
9.0.0-preview.10 238 10/9/2024
9.0.0-preview.9 299 10/6/2024
9.0.0-preview.8 205 10/4/2024
9.0.0-preview.7 64 10/3/2024
9.0.0-preview.6 140 10/1/2024
9.0.0-preview.5 65 9/30/2024
9.0.0-preview.4 398 9/25/2024
9.0.0-preview.3 60 9/23/2024
9.0.0-preview.2 139 9/17/2024
9.0.0-preview.1 84 9/15/2024
8.4.1 436 9/16/2024
8.4.0 151 9/15/2024

Version 10.0.0
Availability: .NET 9 and .NET 8
 
# ALM
- CHANGED Dependencies to latest and greatest with respect to TFMs
 
# Breaking Changes
- RENAMED AspNetCoreHostFixture class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace to ManagedWebHostFixture
- REMOVED AspNetCoreHostFixtureExtensions class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace
- RENAMED AspNetCoreHostTest class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace to WebHostTest
- RENAMED BlockingAspNetCoreHostFixture class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace to BlockingManagedWebHostFixture
- RENAMED IAspNetCoreHostFixture interface in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace to IWebHostFixture
 
# New Features
- ADDED WebHostFixtureExtensions class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace that consist of one extension method for the IWebHostFixture interface: HasValidState
- ADDED HostBuilderApplicationExtensions class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace that consist of one extension method for the IHostApplicationBuilder interface: ToHostBuilder
- ADDED IWebMinimalHostFixture interface in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace that provides a way to use Microsoft Dependency Injection in unit tests (minimal style)
- ADDED ManagedWebMinimalHostFixture class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace that provides a default implementation of the IWebMinimalHostFixture interface
- ADDED WebMinimalHostFixtureExtensions class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace that consist of one extension method for the IWebMinimalHostFixture interface: HasValidState
- ADDED MinimalWebHostTest{T} class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace that represents a base class from which all implementations of unit testing, that uses Microsoft Dependency Injection and depends on ASP.NET Core (minimal style), should derive
- ADDED MinimalWebHostTestFactory class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace that provides a set of static methods for ASP.NET Core (minimal style) unit testing
- ADDED SelfManagedWebHostFixture class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace that provides a self-managed implementation of the ManagedWebHostFixture class (i.e., the host is not started automatically)
- ADDED SelfManagedWebMinimalHostFixture class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace that provides a self-managed implementation of the ManagedWebMinimalHostFixture class (i.e., the host is not started automatically)
 
Version 9.1.3
Availability: .NET 9 and .NET 8
 
# ALM
- CHANGED Dependencies to latest and greatest with respect to TFMs
 
# Improvements
- CHANGED AspNetCoreHostTest class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace to include the IWebHostTest interface
 
Version 9.1.2
Availability: .NET 9 and .NET 8
 
# ALM
- CHANGED Dependencies to latest and greatest with respect to TFMs
 
Version 9.1.1
Availability: .NET 9 and .NET 8
 
# ALM
- CHANGED Dependencies to latest and greatest with respect to TFMs
 
# Bug Fixes
- FIXED AspNetCoreHostTest class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace to have same behavior as prior to 9.1.0 release (hereby being backward compatible as originally intended)
 
Version 9.1.0
Availability: .NET 9 and .NET 8
 
# ALM
- CHANGED Dependencies to latest and greatest with respect to TFMs
 
# New Features
- ADDED AspNetCoreHostFixtureExtensions class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace that consist of one extension method for the IAspNetCoreHostFixture interface: HasValidState
- ADDED BlockingAspNetCoreHostFixture class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace that provides a blocking implementation of the AspNetCoreHostFixture implementation
 
# Improvements
- CHANGED WebHostTestFactory class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace to accept an optional argument taking a custom implementation of IAspNetCoreHostFixture (promote DIP)
 
Version 9.0.1
Availability: .NET 9 and .NET 8
 
# ALM
- CHANGED Dependencies to latest and greatest with respect to TFMs
 
Version 9.0.0
Availability: .NET 9 and .NET 8
 
# ALM
- CHANGED Dependencies to latest and greatest with respect to TFMs
- REMOVED Support for TFM .NET 6 (LTS)
 
# Bug Fixes
- FIXED AspNetCoreHostFixture class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace to preserve ExecutionContext and AsyncLocal{T} values from the client to the server (vital for ITestOutputHelperAccessor combined with xUnit test logging when using HttpClient)
- FIXED AspNetCoreHostFixture class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace to only enable ValidateOnBuild and ValidateScopes when TFM is .NET 9 (or greater)
 
# New Features
- EXTENDED FakeHttpContextAccessor class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore.Http namespace to support IServiceProvidersFeature (e.g., RequestServices property will be available for consumption by tests)
 
# Improvements
- CHANGED ServiceCollectionExtensions class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace to have AddFakeHttpContextAccessor lifetime argument as optional with a default value of ServiceLifetime.Singleton
 
Version 8.4.0
Availability: .NET 8 and .NET 6
 
# ALM
- CHANGED Dependencies to latest and greatest with respect to TFMs
 
# Breaking Changes
- REMOVED IMiddlewareTest interface from the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace
- REMOVED MiddlewareTestFactory static class from the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace
- RENAMED Run method on the WebHostTestFactory class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore to RunAsync
- RENAMED RunWithHostBuilderContext method on the WebHostTestFactory class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore to RunWithHostBuilderContextAsync
 
# Improvements
- CHANGED AspNetCoreHostFixture class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace to use same hostbuilder validation as introduced with the forthcoming .NET 9
 
# New Features
- ADDED HttpClientExtensions class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace that consist of one extension method for the HttpClient class: ToHttpResponseMessageAsync
 
Version 8.3.2
Availability: .NET 8 and .NET 6
 
# ALM
- REMOVED Support for TFM .NET 7 (STS)
- CHANGED Dependencies to latest and greatest with respect to TFMs
 
Version 8.3.1
Availability: .NET 8, .NET 7 and .NET 6
 
# ALM
- CHANGED Dependencies to latest and greatest with respect to TFMs
 
# Improvements
- ADDED IWebHostTest interface in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace that represents the members needed for ASP.NET Core (including but not limited to MVC, Razor and related) testing
- ADDED WebHostTestFactory class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace that provides a set of static methods for ASP.NET Core (including, but not limited to MVC, Razor and related) unit testing
- DEPRECATED IMiddlewareTest interface in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace; use the consolidated IWebHostTest instead
- DEPRECATED MiddlewareTestFactory class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace; use the consolidated WebHostTestFactory instead
 
Version 8.3.0
Availability: .NET 8, .NET 7 and .NET 6
 
# ALM
- CHANGED Dependencies to latest and greatest with respect to TFMs
 
Version 8.2.0
Availability: .NET 8, .NET 7 and .NET 6
 
# ALM
- CHANGED Dependencies to latest and greatest with respect to TFMs
 
Version: 8.1.0
Availability: .NET 8, .NET 7 and .NET 6
 
# ALM
- CHANGED Dependencies to latest and greatest with respect to TFMs
 
Version: 8.0.1
Availability: .NET 8, .NET 7 and .NET 6
 
# ALM
- CHANGED Dependencies to latest and greatest with respect to TFMs
 
Version: 8.0.0
Availability: .NET 8, .NET 7 and .NET 6
 
# ALM
- ADDED TFM for net8.0
- REMOVED TFM for netstandard2.0
- CHANGED Dependencies to latest and greatest with respect to TFMs
 
# Breaking Changes
- CHANGED MiddlewareTestFactory class in the Codebelt.Extensions.Xunit.Hosting.AspNetCore namespace received a long overdue change of signature from Action{IApplicationBuilder} pipelineSetup, Action{IServiceCollection} serviceSetup --> Action{IServiceCollection} serviceSetup, Action{IApplicationBuilder} pipelineSetup as this is more logical, intuitive and in consistency with GenericHostTestFactory