Automatic Registration

Minimum Version: 2.3.0 / 3.3.0

Video: Intro to Automatic Plugin Step Registration in FakeXrmEasy

Automatic Registration of plugin steps is a new feature added to FakeXrmEasy.

You can use it to declaratively specify how to discover plugin steps, which is handy if you used another 3rd party tool (like Spkl or similar), to deploy your plugins.

The automatic registration using a discovery function saves duplicate attributes for registration, because you can instruct FakeXrmEasy to use your own, existing ones.

Automatic Registration of Plugin Steps

Automatic registration of plugin steps is a way of translating registration attributes into PluginStepDefinition objects, which is what FakeXrmEasy understands and needs to execute plugin steps as part of the pipeline simulation.

You do that via specifying a CustomPluginStepDiscoveryFunction that will be executed for each assembly you specify in PluginAssemblies during the middleware setup, as follows:

    .AddPipelineSimulation(new PipelineOptions()
                {
                    UsePluginStepAudit = true,
                    UseAutomaticPluginStepRegistration = true,
                    PluginAssemblies = new List<Assembly>()
                    {
                        Assembly.GetAssembly(typeof(FollowUpPlugin))
                    },
                    CustomPluginStepDiscoveryFunction = PluginStepDiscoveryFn
                })

We provide a sample discovery function which already works with spkl’s CrmPluginRegistrationAttribute. If you use a different method or a different tool, you can use it as an example to build your own.

See the sample code below.

Automatic Registration of Custom Apis

Custom Apis are slightly different in that they run in the Main Operation, and they’re executed like another message. So the setup with FakeXrmEasy is different. We would need to add an extension method to register them similar to this example (AddAutomaticCustomApiFakeMessageExecutors):

public FakeXrmEasyAutomaticRegistrationTestsBase()
        {
            _context = MiddlewareBuilder
                            .New()

                            // Add* -> Middleware configuration
                            .AddCrud()
                            .AddFakeMessageExecutors(Assembly.GetAssembly(typeof(AddListMembersListRequestExecutor)))
                            .AddAutomaticCustomApiFakeMessageExecutors(Assembly.GetAssembly(typeof(CustomApiSumPlugin)))

If you look at the sample code provided below, you’ll see an implementation for Spkl’s custom apis.

Automatic Plugin registration with Spkl Sample code

You can find a working example under the spkl folder on the samples repo.

https://github.com/DynamicsValue/fake-xrm-easy-samples/tree/main/spkl

Look into the FakeXrmEasyAutomaticRegistrationTestsBase.cs class and go from there.