Closed
Description
How would you write unit tests for a class that has HttpClient injected in its constructor (such as the CatalogService example above)? I would prefer if there were an interface (something called IHttpClient, or maybe IHttpMessageInvoker) that could be injected instead. Then providing a mock implementation for a unit test would be more straightforward.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 7b506236-b211-eb9d-b571-5efecdde76c8
- Version Independent ID: 24434b0e-0b82-e477-9440-2cc8f135df75
- Content: Use HttpClientFactory to implement resilient HTTP requests
- Content Source: docs/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests.md
- Product: dotnet
- Technology: dotnet-ebooks
- GitHub Login: @nishanil
- Microsoft Alias: nanil