How to mock the new HttpClientFactory in .NET Core 2.1 using Moq

The HttpClientFactory is derived from IHttpClientFactory Interface So it is just a matter of creating a mock of the interface var mockFactory = new Mock<IHttpClientFactory>(); Depending on what you need the client for, you would then need to setup the mock to return a HttpClient for the test. This however requires an actual HttpClient. var … Read more