How to fake HttpClient requests #544
-
Hello everyone, Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi Vikranth, What I would normally do is: 1 - Add a public property of an interface of that service to the plugin/cwa like:
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)
5 - The rest of the plugin/cwa code to reference the interface (property) only. Note: adding plugin / cwa cause the approach is the same for both plugins and custom workflow activities... |
Beta Was this translation helpful? Give feedback.
Hi Vikranth,
What I would normally do is:
1 - Add a public property of an interface of that service to the plugin/cwa like:
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)
5 - The rest…