Linked Questions

0 votes
0 answers
120 views

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 ...
David Tembo's user avatar
0 votes
0 answers
82 views

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 ...
justme's user avatar
  • 356
291 votes
24 answers
396k views

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 ...
tjugg's user avatar
  • 3,467
20 votes
4 answers
43k views

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; ...
Amitava Karan's user avatar
13 votes
1 answer
15k views

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 ...
rjacobsen0's user avatar
  • 1,467
5 votes
2 answers
7k views

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 ...
Barış Velioğlu's user avatar
-1 votes
2 answers
5k views

Update: Complete code example: public class DelegatingHandlerStub : DelegatingHandler { private readonly Func<HttpRequestMessage, CancellationToken, Task<HttpResponseMessage>> ...
Ogglas's user avatar
  • 71.4k
1 vote
0 answers
2k views

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&...
Garry A's user avatar
  • 485
1 vote
1 answer
869 views

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 ...
prakashrajansakthivel's user avatar
1 vote
1 answer
821 views

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 ...
chris31389's user avatar
  • 9,536
1 vote
0 answers
600 views

I am writing unit test for a simple function public async Task<HttpResponseMessage> MakeRestCallAsync(Uri uri, string input) { using (httpClient = new HttpClient()) { using (var ...
Polina F.'s user avatar
  • 649