How to mock the new HttpClientFactory in .NET Core 2.1 using Moq
问题 .NET Core 2.1 comes with this new factory called HttpClientFactory , but I can't figure out how to mock it to unit test some methods that include REST service calls. The factory is being injected using .NET Core IoC container, and what the method does is create a new client from the factory: var client = _httpClientFactory.CreateClient(); And then using the client to get data from a REST service: var result = await client.GetStringAsync(url); 回答1: The HttpClientFactory is derived from