-
|
Having trouble injecting The application under test does a lot of Which means if I do _mockHttpClient = new MockHttpClient();
var httpClientFactoryMock = IHttpClientFactory.Mock();
httpClientFactoryMock.CreateClient(Any()).Returns(_mockHttpClient);then by the next httpClient invocation the mock will already be disposed, and I'll get an If I do var httpClientFactoryMock = IHttpClientFactory.Mock();
httpClientFactoryMock.CreateClient(Any()).Returns(() => { _mockHttpClient = new MockHttpClient(); return _mockHttpClient; });then I'm losing information about invocations on the previous clients if there were a few usings down the road of the class being tested. How do I preserve the information about HttpClient invocations? Note that I'm not using TestWebApplicationFactory. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
|
Can't you set the |
Beta Was this translation helpful? Give feedback.
-
|
@thomhurst maybe you could implement a better support for IHttpClientFactory outside of TestWebApplicationFactory for such cases. |
Beta Was this translation helpful? Give feedback.
So this becomes
And then I can test invocations directly from the handler.
Thank you!