How to unit test a WCF Client built with WCF Rest Starter Kit -


I have created some Pox services using the REST starter kit. First, Complex was, but in the end, it was well designed and I am successful in jumping context and setting expectations.

But, I'm starting now from the client's side, and I'm having some problems which is fun to do things, it's not so straight forward.

So, I have this sample method that sends data through data to transport data through datacountry and XML.

  public class Sewaclaint: Aisis {private String Const uri_template = "http: // {0}: {1} / Sissaisaississisisia" "Private Reedonli HTTP client http = new HTTP client (); public Services client (string host, Int port) {http.BaseAddress = new Uri (Stringkformet (Yuri_tamplet, host, port));} public void create (MyDataContract my_data_contract) {var content = HttpContentExtensions .CreateDataContract (my_data_contract, encoding. Default, "text / xml", tap); Var response = http.Post (" Create "materials); if (response.StatusCode! = HttpStatusCode.Created) {throw new Exception (" Something's not right ");}}}  

This is the way to work And actually posting data and serializing correctly.

What I want to do, is to test the unit.

My questions are:

  1. how do I Steb / Mock for hTTP Kansortakstenshn create, to learn that it does not implement any interfaces?

  2. and http Cly For what? This is the worst because it is filled with elsewhere defined extension methods (post and such methods are extensions).

In 2 I think that I send '' and it is overloaded, but then the same problem as the 1

I was thinking of doing, Actiteepitiantiakstekstns and remove interface Actiteepielant, every one To implement the interfaces that children create and handover to the parents, and then using the interface in my code.

But this much work is IMHO.

I am using as my witty structure Rainomoks so I fake /, and I would like it to stick, because I really think that the concrete sections of the joke is not very elegant.

So, is the cleaner / fast / smart way for unit testing codes like above?

PD: This WCF starter kit is for preview 2

If you really In this case, duplicate that code, one way to work for this scenario is to get HTTPPLICLL example in the service client class. The HTTP client class has a processing pipeline, which you can customize with custom handlers. For your tests, you can inject a handler in that httpclient example to return a counterfeit reaction to the test before being called in the original original handler (Transport Stage). Take a look at this post to get an idea of ​​how it can be implemented,

Regards, Pablo


Comments