WSDL.exe - generate an interface, as well as a specific class for easy fake / mocks later

Is it possible to get WSDL.exe for creating interfaces as well, or instead of specific classes, when it generates a proxy server for a web service?

We use a third-party web service from the ASP.Net application and created our proxy classes using WSDL.exe, everything is fine and good.

Now I want to write tests against my wrapper and business classes, starting a web service. There is no interface or abstract base class for the proxy, and they are marked as internal, that is, I can not inherit them without putting my Fake / mock code in my business project / assembly.

I could manually create an interface (using resharper) and edit the class, however, if the third part changes their WSDL / web service, I or my successors should also manually edit the interface and automatically generate classes that never look like a good idea.

What is the most elegant way to fake or mock this service? Should I put a fake in a business project? Do I have to manually edit files and create an interface? Should I do something completely different?

+6
soap testing mocking
source share
3 answers

Correctly, at the prompt of Philip, I reply that I went alone, and perhaps came up with a working solution. Using WSDL.exe, I created interfaces (using the / si switches) and regular proxy classes and added both to my business project.

Then I created a new class that inherits from a particular class AND implements the interface. This small class did not contain any code at all, since the inherited specific members provided implicit implementation of the interface members. The code was compiled first, and I was able to replace this small “pad” (? Adapter?) With a Class with my integration tests and make calls against a direct third-party server.

Now I can create other classes (mocks or fakes) that implement the interface, and replace them instead of the "shim" class.

Edit: Well, I worked a bit on this and did not allow a few complications that it works.

The first major issue is that proxy classes are still marked as “internal”, so the derived class (adapter / strip) must also be internal. This is not a problem if you put the Factory class in your business project / assembly that updates the proxy classes and returns them as an interface.

The second problem that I discovered was that we explicitly specified the URL and timeout properties of the web page, but they are not included in the interface, and are not inherited from System.Web.Services.Protocols.WebClientProtocol via SoapHttpClientProtocol. Again, I dealt with this in a factory, since this is a detail of the implementation that I'm happy about, not in the interface.

Edit: This still works well for me during the testing and development of our facade. Since I get the proxy server behind the interface, I also created a log decorator class that captures many sample calls to use debugging and when the third-party server is down.

I wrote what I did a bit more here: http://www.flowerchild.org.uk/archive/2010/09/21/mocking-or-faking-or-maybe-stubbing-a-wsdl-exe-soap .html

+6
source share

You can start wsdl with the /serverinterface or /si switch to get the interfaces for each binding in wsdl. This is intended to give you a server-side skeleton from a wsdl document, but the interfaces should direct you - if I understood the question correctly.

EDIT . After reading the comment, I believe that I misunderstood the question - do you need a client interface / specific so that you can encode, to conclude a contract not for implementation. The /si switch will probably not give you what you want.

I do not know a single switch that can give you this behavior, since wsdl basically creates one of three things: 1) client proxy classes: 2) abstract server classes (to create a server implementation); 3) server interfaces (again, to create a server implementation - it's just iface instead of an abstract class). I see no way to force client proxy classes to implement interfaces (except for INotifyPropertyChanged for data types)

+3
source share

I always found that these generated classes are too large to easily mimic (too many methods / properties).

Rather, create a facade or repository that implements only the calls you need, and return DTO-style objects with only your properties.

Write some simple integration tests with a real Webservice, and then scoff at the simpler Facade in the rest of the tests.

An additional advantage of this approach is that you effectively get a layer of anti-corruption, so third-party changes will only affect a small area of ​​your code.

+1
source share

All Articles