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
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
Hi
I have a REST WCF service. I want to unit test it . How do I do that?
--CODE-------

--Interface---
[WebGet(ResponseFormat = WebMessageFormat.Xml)]
string GetProductData(string prodId);
--Interface---
--CODE-------

Also I want to ask to run unit test, should my wcf service be running?
asked by sudhirkalmegh (640 points)

4 Answers

0 votes
Hi,

It depends if you what do you want to test.
If you want to test the service than it should be up and running (this is actually an integration test not a unit test).
If you want to test the client than you don't need to run the service and just fake the interface and set the wanted behavior.

Example:
// Fake the interface
var fake = Isolate.Fake.Instance<IFoo>();
// set the behavior 
Isolate.WhenCalled(() => fake.GetProductData(string.Empty)).WillReturn("abc");
answered by ohad (35.4k points)
0 votes
Thanks for the reply.
I actually wanted to ask something else :? .
I mean, I have interface and the implementaion class. I just want to test whether this implementation class is working fine or not.

Shoud this test be a simple test then. Just testign the class function? Has it anything to do with Service testing?
answered by sudhirkalmegh (640 points)
0 votes
Hi,
The best practice says that you should do first the unit tests and than the integration tests
So in your case first test the logic in the class without calling the class dependencies. This will probably the place where you'll need the Isolator :)
Than do the integration tests where you actually call the dependencies and test that they work together.

Hope I understood the question, please let me know if it helps.
answered by ohad (35.4k points)
0 votes
Thanks. It helped.
answered by sudhir (3.5k points)
...