Codebelt.Extensions.Xunit.Hosting.AspNetCore 9.0.0-preview.6

This is a prerelease version of Codebelt.Extensions.Xunit.Hosting.AspNetCore.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Codebelt.Extensions.Xunit.Hosting.AspNetCore --version 9.0.0-preview.6                
NuGet\Install-Package Codebelt.Extensions.Xunit.Hosting.AspNetCore -Version 9.0.0-preview.6                
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="9.0.0-preview.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Codebelt.Extensions.Xunit.Hosting.AspNetCore --version 9.0.0-preview.6                
#r "nuget: Codebelt.Extensions.Xunit.Hosting.AspNetCore, 9.0.0-preview.6"                
#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.
// Install Codebelt.Extensions.Xunit.Hosting.AspNetCore as a Cake Addin
#addin nuget:?package=Codebelt.Extensions.Xunit.Hosting.AspNetCore&version=9.0.0-preview.6&prerelease

// Install Codebelt.Extensions.Xunit.Hosting.AspNetCore as a Cake Tool
#tool nuget:?package=Codebelt.Extensions.Xunit.Hosting.AspNetCore&version=9.0.0-preview.6&prerelease                

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. 
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
9.0.0 968 11/13/2024
9.0.0-rc.1 504 11/11/2024
9.0.0-preview.11 118 10/26/2024
9.0.0-preview.10 228 10/9/2024
9.0.0-preview.9 288 10/6/2024
9.0.0-preview.8 189 10/4/2024
9.0.0-preview.7 54 10/3/2024
9.0.0-preview.6 131 10/1/2024
9.0.0-preview.5 50 9/30/2024
9.0.0-preview.4 390 9/25/2024
9.0.0-preview.3 49 9/23/2024
9.0.0-preview.2 127 9/17/2024
9.0.0-preview.1 75 9/15/2024
8.4.1 416 9/16/2024
8.4.0 134 9/15/2024

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