Microsoft.AspNetCore.TestHost 10.0.0
About
Microsoft.AspNetCore.TestHost provides an ASP.NET Core web server for testing middleware in isolation.
Key Features
- Instantiate an app pipeline containing only the components that you need to test
- Send custom requests to verify middleware behavior
How to Use
To use Microsoft.AspNetCore.TestHost, follow these steps:
Installation
dotnet add package Microsoft.AspNetCore.TestHost
Usage
To set up the TestServer, configure it in your test project. Here's an example:
[Fact]
public async Task MiddlewareTest_ReturnsNotFoundForRequest()
{
// Build and start a host that uses TestServer
using var host = await new HostBuilder()
.ConfigureWebHost(builder =>
{
builder.UseTestServer()
.ConfigureServices(services =>
{
// Add any required services that the middleware uses
services.AddMyServices();
})
.Configure(app =>
{
// Configure the processing pipeline to use the middleware
// for the test
app.UseMiddleware<MyMiddleware>();
});
})
.StartAsync();
var response = await host.GetTestClient().GetAsync("/");
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
}
Main Types
The main types provided by this package are:
TestServer: AnIServerimplementation for executing testsTestServerOptions: Provides options for configuring aTestServer
Additional Documentation
For additional documentation and examples, refer to the official documentation for testing middleware in ASP.NET Core.
Feedback & Contributing
Microsoft.AspNetCore.TestHost is released as open-source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.
Showing the top 20 packages that depend on Microsoft.AspNetCore.TestHost.
| Packages |
|---|
|
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications.
This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/55738ff96b832439076e25584cfe0eb3bace9b01
|
|
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications.
This package was built from the source code at https://github.com/aspnet/AspNetCore/tree/509f6badec2f3162f0e50330cd9107e5624b379b
|
|
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications.
This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/f0cc6b11bd8f0826c63d75483578e868c8abe75e
|
|
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications.
This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/63d1187a01b82719c2891cecc74ee3d51ce892a8
|
|
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications.
This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/763b4ef31ca4df6dae07c7ee8f39ea259b6980fa
|
|
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications.
This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/c49ccc8727c620ce1cb8fb431bb3fe8f2e747236
|
|
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications.
This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/d9ba962869d1b1c410ea476b02de2f8e27eec762
|
|
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications.
This package was built from the source code at https://github.com/aspnet/AspNetCore/tree/d1fa2cb155ab9226f20b87ab0d7a1eb16b8a8b69
|
|
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications.
This package was built from the source code at https://github.com/aspnet/AspNetCore/tree/c04846dc66cc97f71d83a83a15437828435f5d44
|
|
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications.
This package was built from the source code at https://github.com/aspnet/AspNetCore/tree/4768f164d522e128f91827810527730f7468fd74
|
|
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications.
This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/610fe433e07b32ed451ed99d07df63be47c29050
|
|
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications.
This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/fedc545ce86467b7d3413d906f1ab02fb3db12ff
|
|
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications.
|
|
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications.
This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/8486d31e24f30e3fa1809a95699a0adc16f448d7
|
|
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications.
This package was built from the source code at https://github.com/aspnet/AspNetCore/tree/d12868dd7c10ff0433c16b06d3b59d03c40d987a
|
|
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications.
This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/d827c653b787c07de908240b7746ce34d3e6271e
|
|
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications.
This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/954f61dd38b33caa2b736c73530bd5a294174437
|
|
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications.
This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/6a01dd1e69c8b9bd1ae005ea465ef2bcd26294bf
|
|
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications.
This package was built from the source code at https://github.com/aspnet/AspNetCore/tree/561deb05ae2d6680206e3d4a6bc75de699585980
|
|
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications.
This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/67acc3d331454956fc06d6de2218a625e3e596f8
|
.NET 10.0
- No dependencies.