Skip to content
This repository has been archived by the owner on Jun 16, 2024. It is now read-only.

How to fake HttpClient requests #544

Answered by jordimontana82
vpandiri asked this question in Q&A
Discussion options

You must be logged in to vote

Hi Vikranth,

What I would normally do is:

1 - Add a public property of an interface of that service to the plugin/cwa like:

public IHttpClient myService;

2 - In the unit test, setup a specific plugin/cwa instance passing in a mock of that property (i.e. with FakeItEasy)

3 - Call the ExecutePluginWith / ExecuteCodeActivity method that allows you to pass in that plugin/cwa instance

4 - In the plugin / cwa 's .Execute method, add an if statement like the below so it would only create a real instance when not run from the unit test project (i.e. when runs against the real CRM/CDS/ instance)

if(myService == null) {
       //create an instance with real IP address and so on....
}

5 - The rest…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@vpandiri
Comment options

@jordimontana82
Comment options

@vpandiri
Comment options

Answer selected by vpandiri
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants