views:

30

answers:

1

Hi All,

I am unit testing a WCF service.

The flow goes like this.

  1. Application(Client) insert command to the DB through Webservice1. This is done using duplex pattern.(with callbacks).
  2. WebService1 inserts the command to DB and this Webservice1 invokes another webservice2 about the arrival of new command.(Duplex pattern).
  3. Webservice2 then reads the command through Webservice3, executes, inserts the results and invoke the callback method on Webservice1 telling the command is executed.
  4. Webservice1 then invoke callback method on the Application and informs the arrival of result.

How can I Unit test such a service.

Please post any links where there are tutorials how to test callbacks.

Thanks,

A: 

You should be testing the services individually for unit testing, mocking the responses from the services that they would be calling. This way you can test the individual services as small units of work and validate that they work as expected. You can also focus on the functionality of each service without really worrying, yet, about how the services interact with each other for real.

I think what you're describing is more of an integration test. You should perform that test only after you have performed individual unit tests on the specific services that you described above. In essence:

The purpose of integration testing is to verify functional, performance, and reliability requirements placed on major design items.

For unit testing your duplex services, here's a well documented blog post describing how to do this (with lots of code): http://blogs.msdn.com/b/ploeh/archive/2008/06/28/unit-testing-duplex-wcf-services.aspx

So you would create unit tests that test the interaction with items #1 and #4 from your list (app -> ws1 and ws1 -> app), then interactions with items #2 and #3 (ws1 -> ws2 and ws2 -> ws1), then unit test the interaction of #3 (ws2 -> ws3). This last one you can just mock. Without much more detail, that's how I'd start to go about unit testing this.

I hope this helps.

David Hoerster