Developing and Testing Code Activities

Similarly to plugins, FakeXrmEasy comes with helper methods to test CodeActivities.

CodeActivities are custom libraries which can contain multiple steps and they’re part of traditional (now legacy) workflows.

You can find more information about developing with CodeActivities on the official documentation site.

CodeActivities, which use System.Activities behind the scenes, have not been ported to .net core however.

What this means is there is no FakeXrmEasy v3.x (Version 3) available to test code activities, only Versions 2.x.


Install-Package FakeXrmEasy.CodeActivities.v9 -Version 2.x 

Your first CodeActivity

When you execute a codeactivity you can pass a dictionary of inputs that the codeactivity will use. These are passed as a dictionary where the property names should match the ones declared in the CodeActivity.


using FakeXrmEasy.CodeActivities;

public class MyCodeActivityTests: FakeXrmEasyTestsBase
    public void When_the_add_activity_is_executed_the_right_sum_is_returned()
        var inputs = new Dictionary<string, object>() {
        { "firstSummand", 2 },
        { "secondSummand", 3 }

        var result = _context_.ExecuteCodeActivity<AddActivity>(inputs);


Passing a Workflow Context

There will be some cases where you need to retrieve, in the codeactivity, some properties of the workflow context. These can be passed into the code activity by using a different overload that takes an extra workflow context parameter.

Another method overload will take a specific instance of a CodeActivity when is executed. This is handy for injecting external dependencies.

Please check the Dependency Injection documentation for more details.

public void When_passing_a_custom_workflow_activity_context_injected_property_is_returned()
    var wfContext = _context.GetDefaultWorkflowContext();
    wfContext.MessageName = "Update";

    var inputs = new Dictionary<string, object>();

    CheckContextPropertyActivity codeActivity = new CheckContextPropertyActivity();

    var result = _context.ExecuteCodeActivity<CheckContextPropertyActivity>
        (wfContext, inputs, codeActivity);