I would say your HttpMessageHandlerMock class is more of a Stub than a Mock. A stub is a simple fake object with the data you need to pass a test, whereas mock's are usually smarter, such as allowing you to verify calls against them. I'd rename it to HttpMessageHandlerStub.
I heard on another video that it’s best to use the Http factory to create clients.. supposedly it handles potential memory leaks better... With that in mind would you say it’s possible to mock a factory to create clients for testing?
I am showing how to mock an httpclient for testing, I am not testing anything so you shouldn’t be asking yourself that because the video is not about writing a test.
Crushed it, I give this to anyone that asks about HttpClient. Thanks!
Awesome, just looking for this. U got a new subscriber today !!
This is Epic. I just got a notification for this. I have meaning to get to know this for quite sometime now
I would say your HttpMessageHandlerMock class is more of a Stub than a Mock. A stub is a simple fake object with the data you need to pass a test, whereas mock's are usually smarter, such as allowing you to verify calls against them. I'd rename it to HttpMessageHandlerStub.
Yea I avoid that type of terminology, fake,stub,mock etc.. are all mocks to me
Thanks for the video. It really helped.
I heard on another video that it’s best to use the Http factory to create clients.. supposedly it handles potential memory leaks better... With that in mind would you say it’s possible to mock a factory to create clients for testing?
You’d make the factory return an instance as described in the video.
Exactly what I was looking for! Thanks man :D
Hey, can we get the code repo for the above (it is not there in the description). Thanks!
great video, l learned a lot!
I am asking myself, what the test tests. In the second example, you test that the HttpClient returns a response that you provided
I am showing how to mock an httpclient for testing, I am not testing anything so you shouldn’t be asking yourself that because the video is not about writing a test.
I don't get why we need to delve into the specifics of http client for our tests.
what to do for recursive api call
Thanks for help, you are great :D
Wondering how to copy the source code from this video? I am trying to understand mocking, confusing.
Have you considered using Moq?
Moq only allows you to mock interfaces, not concrete types, and HttpClient is an old artifact of .net which has no interface.
var handlerMock = new Mock(MockBehavior.Strict);
handlerMock
.Protected()
.Setup(
"SendAsync",
ItExpr.IsAny(),
ItExpr.IsAny()
)
.ReturnsAsync(new HttpResponseMessage()
{
StatusCode = HttpStatusCode.NoContent
});
This works :)
Why don't we just wrap httpClient into some httpService and then mock it?
Even if you wrap infinitely down below there will still be an httpclient you’ll need to test.
Hi, thanks, where is the repo in your github?
Check description
Font too small, hard to see what you write
🔎
@@RawCoding on smartphone it's very inconvenient,I would appreciate if you try bigger font