Easier Unit Testing of WCF Services with ServiceTestContext

Hi, and apologies for being so awfully quiet the last couple of months. Expect the traffic to pick up again (I’ll explain the silence in a blog post later).

Now, when unit testing WCF Services, I’ve often ended up with cluttering my tests with a lot of plumbing code to wire up the SUT; that is – the WCF service I want to exercise.

Now, being a lazy guy, wiring up (redundant) plumbing code again and again, I often end up trying to extract the essence and put together a tool or helper class.

So, this is my first shot of a fluent helper class that lets you test your WCF services.

The screenshot below pretty much sums up the functionality. It should be pretty self explaining; You end up writing an Action<TContract> implementation that acts as the client.

It will wire up an OperationContextScope automatically, but it can be disabled if you don’t need it.

ShouldReturnHttp200

The state/quality of the code is “Proof of Concept” and can be found here.

Be Sociable, Share!

  • namee

    what is that “Mocks.MockService”? do i need to download a library to use that?

  • larsw

    Hi,

    No, it’s just a simple mock implementation of a service I’ve used in that test context.

    –larsw