How to mock HttpClient in your .NET / C# unit tests

You have a class that depends on HttpClient (or IHttpClientFactory for that matter), and want to unit test that. Since you want a unit test and not an integration test, it should not call a real http endpoint. You decide to mock out your dependency on HttpClient, and soon thereafter you got stuck. After googling 'How to mock HttpClient' you landed on this post. So, how would you mock HttpClient for your unit tests?

I give you the short answer right away: Continue reading "How to mock HttpClient in your .NET / C# unit tests"