dotnet / dotnet/AspNetCore.Docs

How to unit test with IHttpClientFactory

Open
#25,140 0 comments 1 reaction 0 assignees View on GitHub
doc-enhancement Pri2 Source - Docs.ms
Dominant language
C#
Stars
13.1k
Forks
24.6k
Avg merge
1d 3h
Merged PRs (30d)
97

Description

Suggest to add a section on how to write unit tests for components using the IHttpClientFactory to create your HttpClient. I don't see it done easily, as you still get the HttpClient which can't be mocked without accessing protected members.

---
#### Document Details

⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*

* ID: 881cef77-11ef-ac11-06d0-0996a1ccfa1b
* Version Independent ID: 3d356334-e672-7e8b-1fef-7944ebee99eb
* Content: [Make HTTP requests using IHttpClientFactory in ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-6.0#use-ihttpclientfactory-in-a-console-app)
* Content Source: [aspnetcore/fundamentals/http-requests.md](https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/fundamentals/http-requests.md)
* Product: **aspnet-core**
* Technology: **aspnetcore-fundamentals**
* GitHub Login: @stevejgordon
* Microsoft Alias: **scaddie**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.