chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male

Unit Testing WCF with Isolator – The Server

WCF actually cries out for unit testing. How can you make sure your logic actually works without relying on a response from a server? What happens when something happens on the wire? All kind of happenings make your tests not-repeatable.

And how is your logic handling what’s happening on the wire? A timeout for example. How do you test that? And finally, on the server side, how do you simulate issues that should come from the client or the wire?

You already know the answer.

Our example is simple. We have a single method we’re calling on the server side. Let’s take a look at the server code:

and here’s the server code of our XMLProvider:

I would like to test this method, based on it’s header. In this case I want to check the Name of the header info. With Isolator, here’s a test:

This is a simple test, with a simple setup – we fake the static calls (which will be out shortly in version 5.1), fake a MessageHeaderInfo object, and inject a name to satisfy the logic and confirm the result.

Now let’s see what happens if we get a bad message header. This time we expect an exception to occur:

Simple, isn’t it? And this is on the server side. Next time, we’ll look at how we unit test the client side.

Want to start unit testing? Take advantage of our 30-day FREE trial of Isolator Complete. Get it now