Geeks With Blogs
Abhishek Anand Bits & Bytes about .net technology framework.

Imagine you are testing a method that returns or processes a Workflow event. Normally, you would generate a fake instance of the class and insert it into the method using Moq. However, creating a fake Workflow event is difficult, as Workflow events do not expose any public constructors.

You can generate Workflow events using Microsoft.Activities.UnitTesting. Note: this is a package that must be installed.

Here is an example of generating “WorkflowApplicationCompletedEventArgs”. Basically, run a workflow with the sole purpose of generating a “Completed” event.


var activity = new FakeActivity();

var test = WorkflowApplicationTest.Create(activity);


WorkflowApplicationCompletedEventArgs eventArgs = null;

test.TestWorkflowApplication.Completed = e => eventArgs = e;





Assert.AreEqual(eventArgs.CompletionState, ActivityInstanceState.Closed);


If you are using fake Workflow events in more than one unit test, it is best practice to create a helper class to create these events for you. For example, create WorkflowEventUtility and implement WorkflowEventUtility.CreateCompletedEvent().

Posted on Thursday, November 21, 2013 12:12 PM unit testing , workflow | Back to top

Comments on this post: Testing Workflow Events

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Abhishek Anand | Powered by: