DEV Community

Discussion on: How to test HttpClient with Moq in C#

Collapse
 
richardoey profile image
RichardOey

Hi, thank you very much for the tutorial ! It helps me to know how to test the SendAsync function.

However, I'm little confused with the assert action. Usually we will compare the unit test result with our expectation result, and we put inside the "assert" part. In your example, where do you put the assert? Thanks :)

Collapse
 
gautemeekolsen profile image
Gaute Meek Olsen

Hi thanks for the comment :)

In the first test you see I do the assert Assert.NotNull(retrievedPosts);, so it's there I would have it. Because my demo code GetPosts and CreatePost is simple it doesn't feel natural to add more assertions. But maybe one I could have added was Assert.Equal(2, retrievedPosts.Count); instead of Assert.NotNull(retrievedPosts); and there is where I would put it.