jordimontana82 / fake-xrm-easy

The testing framework for Dynamics CRM and Dynamics 365 which runs on an In-Memory context and deals with mocks or fakes for you
https://dynamicsvalue.com/get-started/overview?source=git
Other
263 stars 182 forks source link

ExecutePluginWith<T>(...) has no parameter for MessageName - need to use obselete method ExecutePluginWithTargetAndPreEntityImages<T>(...) #597

Closed thomas-schiller closed 2 years ago

thomas-schiller commented 2 years ago

My PostUpdate plugin uses a preImage. I need to set the PreImage for my plugin execution. I don't see any possiblity to pass an PreImage AND set the message name to "Update" (always default--> "Create")

Hence I am forced to use the obsolete method "ExecutePluginWithTargetAndPreEntityImages". The obsolete warning tells me to use "ExecutePluginWith", but I don't find any possiblity to set the message name. Am I wrong?

jordimontana82 commented 2 years ago

Hi Thomas,

It is indeed possible. You can use the GetDefaultPluginContext method to retrieve a default context and override whatever is needed before passing it into the ExecutePluginWith method, including setting any PreEntityImages you want as well as the message name:

https://github.com/jordimontana82/fake-xrm-easy/blob/486c7ff0bd4c78262a9a5c1cd77056d9571fe4de/FakeXrmEasy.Shared/XrmFakedContext.Plugins.cs#L23-L32

Also, you might want to take a look at the later version cause v1.x is deprecated and will stop receiving updates soon....

https://dynamicsvalue.github.io/fake-xrm-easy-docs/quickstart/migrating-from-1x/

Feel free to ping me if you still have questions.

jordimontana82 commented 2 years ago

I'm also adding a sample using that approach, not necessarily for PreEntityImages but other InputParameters, although it should work as well:

https://dynamicsvalue.github.io/fake-xrm-easy-docs/quickstart/plugins/overview/