views:

116

answers:

2

I'm implementing a WCF web service based on WF. This web service consumes other web services which I'm not in charge of. So basically my service workflow contains several Send activities.

I'm following the TDD approach, so the service implementation is to be covered by unit tests. I want to test proper invocation of 3rd party services.

In a non-workflow case I would mock the external services via NMock. But in my case I cannot control the instantiation the workflow instance and I have no idea on how to trick the Send activities to use the mock objects instead of real services endpoints.

Although Unit Testing Workflows And Activities article on MSDN mentions mocks I couldn't find any complete example of mocking the remote end of Send activity.

Any idea on how to do that?

A: 

Using ServiceAgents wrappers for your web services would be one possible way of doing it.

This is a pattern i have followed in previous projects of mine.

Since they are interface based, you can easily mock out the services.

There are other advantages to this pattern (besides unit testing) including being able to abstract your application from external dependencies to a certain extent. However it does add the overhead of creating another class layer on top of the services.

InSane
A: 

please try Moles framework. http://research.microsoft.com/en-us/projects/pex/

There are samples about how to mock the sharepoint service. I believe the same trick should apply to WF workflow.

I have tried to mock the sqlconnection, Entity framework, web service call, it works very neat. Basically, it can mock almost any .net objects.

Russel Yang