How to mock the HttpClient getasync using Nsubstitute.

1,620 views
Skip to first unread message

lakshman krishna

unread,
Sep 13, 2017, 11:05:51 AM9/13/17
to NSubstitute
Hi,

Can any one explain me how to mock the System.Net.Http.HttpClient.GetAsync method and return the mock result from the service layer.

Thanks in advance,
Lakshman.

David Tchepak

unread,
Sep 13, 2017, 7:50:45 PM9/13/17
to nsubs...@googlegroups.com
Hi Lakshman,

As far as I can tell there are two main options: wrap HttpClient in an
interface you can mock, or create a mock for the message handler.
Please see here for more explanation:

* https://stackoverflow.com/q/36425008/906
* https://stackoverflow.com/q/10693955/906

Regards,
David
> --
> You received this message because you are subscribed to the Google Groups
> "NSubstitute" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nsubstitute...@googlegroups.com.
> To post to this group, send email to nsubs...@googlegroups.com.
> Visit this group at https://groups.google.com/group/nsubstitute.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages