Linked Questions
11 questions linked to/from How to mock the new HttpClientFactory in .NET Core 2.1 using Moq
0 votes
0 answers
120 views
how do i unit test a repo that calls IHttpClientFactory with Nunit [duplicate]
i want to test a repository that uses the IHttpClientFactory interface.The repository i want to test makes an external api call to a web service using the httpclient.The web service returns json data ...
0 votes
0 answers
82 views
How to inject mocked httpservice to asp.net core controller [duplicate]
I need to inject mocked version of httpclient into my controller. I have read some topics like this Mocking HttpClient in unit tests but it does not solve my case. [Fact] public async Task ...
291 votes
24 answers
396k views
Mocking HttpClient in unit tests
I have some issues trying to wrap my code to be used in unit tests. The issues is this. I have the interface IHttpHandler: public interface IHttpHandler { HttpClient client { get; } } And the ...
20 votes
4 answers
43k views
Mock HttpClient using Moq
I would like to unit test a class that uses HttpClient. We injected the HttpClient object in the class constructor. public class ClassA : IClassA { private readonly HttpClient _httpClient; ...
13 votes
1 answer
15k views
Mocking HttpMessageHandler with moq - How do I get the contents of the request?
Is there a way to get the contents of the http request before deciding what kind of response I want to send back for the test? Multiple tests will use this class and each test will have multiple http ...
5 votes
2 answers
7k views
Mock HttpClientFactory to create a mocked HttpClient Using Moq Framework
I have method which contains a HttpClientFactory that creates a HttpClient. The method calls SendAsync method in it. I need to manipulate SendAsync method to send me a succeed message whatever it ...
-1 votes
2 answers
5k views
HttpConfiguration from System.Web.Http in .NET 5 project
Update: Complete code example: public class DelegatingHandlerStub : DelegatingHandler { private readonly Func<HttpRequestMessage, CancellationToken, Task<HttpResponseMessage>> ...
1 vote
0 answers
2k views
How to unit test with mocked Uri
I have the following code and I want to unit test it, as below public class MarketLiability : IMarketLiability { private readonly string serviceAddress; private readonly ILogger&...
1 vote
1 answer
869 views
Mocking Fails for Azure Function (IHttpClientFactory)
I am facing issues while mocking the IHttpClientFactory Interface in Azure Function. Here is What am doing, I have trigger, once the message the received I am calling an API to update data. I am using ...
1 vote
1 answer
821 views
When using HttpClientFactory in c#, how can I test the Http call being made?
I have a SessionService that has HttpClient injected into it and is registered as a Typed Client See Microsoft example here. I want to be able to write an integration test that I can control the ...
1 vote
0 answers
600 views
c# UnitTesting Test that API call was made
I am writing unit test for a simple function public async Task<HttpResponseMessage> MakeRestCallAsync(Uri uri, string input) { using (httpClient = new HttpClient()) { using (var ...