views:

27

answers:

1

I thought that I could create a WCF in and call it in Silverlight. I would inject an interface to the WCF. Then in my unit test I would mock the wcf....

However when I actually got to do this I notice that the interface does not actually have the methods that I am calling.

ie

myWCF.myfunctionCompleted(myhandler);
myWCF.myfunctionAsyc("test");

How to people typically accomplish this?

+2  A: 

I would create a MyWCFService class which would wrap all the work calling out to my generated WCF proxies.

This helps in a few ways:

  1. Gives you a single point to keep all of the code related to calling WCF (which can be quite a bit with proper error handling).

  2. Gives you a class you can mock out for calling.

  3. Gives you an opening to easily replace WCF if you need/want too by not avoiding WCF specific code being sprinkled everywhere (unlikely but you never know).

ShaneC
wow that really is disappointing. That is a lot of code to add just to make a unit test work better.
zachary
Testing is all about creating seams within your code where you can insert fakes. You'll see this technique quite a lot.
ShaneC