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...