Unit testing your plugin with an in-memory context

When you are developing a plugin, you would often want to test your customization. If you have an on-premise instance, debugging your code is more or less straight forward. If you have an online instance, you can leverage the new plugin log capabilities or replay your plugin using the plugin registration tool, as described in Profiling your plugin later in this chapter.

If you try to integrate test your plugin with a live connection to your Dynamics 365 instance, then you will be penalized with a significant execution time that might quickly eat up the best practice 30 seconds timeframe to run all your unit tests. The best option is to rely on in-memory processing only.

In this recipe, we will unit test our plugin end-to-end as if it was triggered from Dynamics 365. The plugin will not connect to a live Dynamics 365 instance; instead, we will fake an in-memory repository. The unit test will focus on state verification as opposed to behavior verification.

We will use the XrmUnitTest framework (https://github.com/daryllabar/XrmUnitTest), created by Microsoft's Business Solutions MVP Daryl LaBar, to help us fake the organization service.

We will start by setting up our in-memory Dynamics 365 mock with testing data. We will then change the state of the record by executing the plugin. Finally, we will retrieve the records from our in-memory repository to assert that the plugin is doing its job.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.195.34