TestServer is an in-memory ASP.NET Core server for sending HTTP requests and receiving responses without opening a network listener. It lets middleware and other application components run inside a framework-like request pipeline. section 36.3 section 36.5
A small TestServer integration test follows these steps:
- Create a HostBuilder and configure the test application's middleware. section 36.3.1
- Call UseTestServer() to replace the default Kestrel server. section 36.3.1
- Start the host, obtain an HttpClient with GetTestClient(), and send an in-memory request. section 36.3.1
Testing middleware at /ping
Configure a HostBuilder with StatusMiddleware, enable UseTestServer(), start the host, and call client.GetAsync("/ping"). The middleware receives a request that appears equivalent to a network request, although the request remains entirely in memory.
