Sunday, March 14, 2010

Mocks for Unit Testing

This post is not exactly related to Designer, but something I am looking closely into nowadays. Recently a customer asked, how can he replace one of his long running activities with a different mock activity so that he can still unit test his workflow/composite activity logic.

Another scenario would be, how to replace an activity which queries a live Db( or does some other Aysnc work) with a test activity which can query a test Db or even a file during testing.

One way is to load the activity in the designer and then use the MorphHelper class to replace the long running activity with a mock activity. You can then use wd.Flush(wd is an object of type WorkflowDesigner) and then use the wd.Text to save the updated Xaml into a different file to finally unit test the workflow/composite activity.

The cleaner way though, is something that one of the Devs in our team, Dan Glick, suggested.  Instead of loading through the designer and going about multiple steps, the developer/tester can use a custom XamlSchemaContext.

For example: Suppose you want to replace a Prompt activity with an Action activity. Also, to add some complexity to the complexity, assume that Prompt activity has an InArgument<string> UserResponse. However Action has an InArgument<string> but with a different name – UserAction. Meaning, there is no 1:1 correspondence between the arguments/properties between the two activities.

Read more: Kushal Shah - Workflows

Posted via email from jasper22's posterous