Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidPluginExecutionException Exceptions not thrown in Pipeline Simulation #85

Closed
bwmodular opened this issue Feb 7, 2023 · 5 comments · Fixed by DynamicsValue/fake-xrm-easy-plugins#33

Comments

@bwmodular
Copy link

When testing a plugin using Pipeline Simulation, if the plugin throws an InvalidPluginExecutionException this is not caught in the test.

If I test the plugin itself using ExecutePluginWith, the exception is caught in the test, but if I perform a CRUD operation in which the plugin is invoked, the test reports a different exception (System.Reflection.TargetInvocationException) and error message ('Exception has been thrown by the target of an invocation.')

I will create a failing test to demonstrate the issue....

@bwmodular
Copy link
Author

Here's a bit more detail before I upload the tests in case I'm not clear.

When a plugin throws an invalid plugin exception, I'd expect to be able to write a test like this, where I'm just performing the Create in order to trigger the plugin and the exception:
Contact contact = new Contact() { Id = Guid.NewGuid() }; Action act = () => _service.Create(contact); InvalidPluginExecutionException exception = Assert.Throws<InvalidPluginExecutionException>(act); Assert.Equal(PluginWhichThrowsAnException.PluginExceptionMessage, exception.Message);

but this test fails because the exception that gets thrown is actually a TargetInvocationException.

This test works though - so if I call the plugin directly it works:
Action act = () => _context.ExecutePluginWith<PluginWhichThrowsAnException>(pluginExecutionContext); InvalidPluginExecutionException exception = Assert.Throws<InvalidPluginExecutionException>(act); Assert.Equal(PluginWhichThrowsAnException.PluginExceptionMessage, exception.Message);

@BetimBeja
Copy link

I have faced the same issue this Monday

@bwmodular
Copy link
Author

I created this pull request in the samples project to demonstrate the issue:
DynamicsValue/fake-xrm-easy-samples#6

@jordimontana82 jordimontana82 added bug Something isn't working investigating labels Feb 16, 2023
@jordimontana82 jordimontana82 added this to To do in Main Backlog via automation Feb 16, 2023
@BetimBeja
Copy link

@jordimontana82
Copy link
Contributor

@bwmodular @BetimBeja

This made it to this version: https://www.nuget.org/packages/FakeXrmEasy.Plugins.v9/2.3.2#release-body-tab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
3 participants