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
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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: