How To Mock HttpClient in C# Unit Tests

preview_player
Показать описание
How to mock the c# http client when for your unit tests.

#aspnetcore #httpclient #csharp
Рекомендации по теме
Комментарии
Автор

Crushed it, I give this to anyone that asks about HttpClient. Thanks!

BrentDowdy-kn
Автор

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.

MayronWoW
Автор

This is Epic. I just got a notification for this. I have meaning to get to know this for quite sometime now

sajagjain
Автор

I don't get why we need to delve into the specifics of http client for our tests.

burakb
Автор

I am asking myself, what the test tests. In the second example, you test that the HttpClient returns a response that you provided

carstenvoss
Автор

Exactly what I was looking for! Thanks man :D

stefanbogdanovic
Автор

Wondering how to copy the source code from this video? I am trying to understand mocking, confusing.

JoelStrait-jm
Автор

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?

ivanvincent
Автор

Why don't we just wrap httpClient into some httpService and then mock it?

boarov
Автор

Hey, can we get the code repo for the above (it is not there in the description). Thanks!

SuperTenja
Автор

Hi, thanks, where is the repo in your github?

Kevinob
Автор

Font too small, hard to see what you write

assafkerenak
visit shbcf.ru