liveBook · Manning

WebApplicationFactory

As explained in .NET in Action, Second Edition

WebApplicationFactory is an ASP.NET Core testing API that creates an in-memory application host and a client for sending requests to it.

WebApplicationFactory is an ASP.NET Core testing API that creates an in-memory host for a web service and supplies an HttpClient for requests against it. Creating the client starts the service, allowing configuration, dependency injection, controllers, and application logic to be exercised together in one process. section 8.5

A practical integration-test setup typically:

  • Removes the existing HttpClient registration and adds a client configured with a fake HttpMessageHandler when external HTTP calls must stay in-process. section 8.5

Testing a search endpoint

Configure the fake message handler with comics, create the factory client, and request /search?searchText=b. Assert an OK response, deserialize the content, and verify that only comic number 12 is returned.

How .NET in Action, Second Edition covers it

How deep it goes
Explains host creation, client-start timing, service replacement, environment selection, and response assertions, but not framework internals.
Examples
Uses a ComicFinderService, a fake external HTTP handler, and a search request whose JSON response is checked for one comic.
What it assumes
Assumes familiarity with ASP.NET Core services, dependency injection, HttpClient, and test assertions while demonstrating their integration.
What you can do after
Diagnose integration behavior by sending real HTTP-style requests through a configured in-memory application and asserting complete responses.
How it connects
Connects ASP.NET Core hosting with dependency injection, HttpClient, HttpMessageHandler, configuration, and integration testing.

Also explained in

Compare how 2 books explain WebApplicationFactory →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET in Action, Second Edition. The section links point to the parts of the book it draws on.