I have a client application which calls my WCF service (Security Token Service i.e. STS, to be precise) which authenticates the user. We have many applications integrated together and this specific WCF service (STS) in turn calls other web service of some third party application because my STS needs some details from the third party web service to proceed.
Now I want to write unit tests for my STS as well as for my client application login functionality.
My questions are:
-
Shall I write unit test just for STS methods with some hard coded values as input from third party web service? If no, unit tests will fail if something goes wrong with the third party web service.
-
Instead of calling my STS from unit tests of client application, can i hard code the input (e.g. username and password) values? Is it the right approach?
-
Is it necessary to actually call the web service from unit tests written for client application? If yes, why?
A unit test does not cross process boundaries, integration tests do that. Your purpose is to test the behaviour of your STS only. In order to do so you need to inject a mock implementation of the 3rd party service. I suggest you look a MOQ. you may also need a DI container (I use ms unity, but are many to chose from) from which your STS will resolve a reference to the 3rd party service.