WSDL.EXE - 生成界面,以及具体的类,便于伪造/后嘲笑 [英] WSDL.exe - generate interface as well as concrete class for easy fake/mocks later

查看:225
本文介绍了WSDL.EXE - 生成界面,以及具体的类,便于伪造/后嘲笑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时有可能得到WSDL.EXE生成接口以及,或代替,当它产生proxys到Web服务?具体类

Is it possible to get WSDL.exe to generate interfaces as well as, or instead of, concrete classes when it generates proxys to a web service?

我们正在使用来自一个ASP.Net应用程序的第三方web服务,并使用WSDL.EXE一切都很好生成的我们的代理类。

We're consuming a 3rd party webservice from an ASP.Net application, and have generated our proxy classes using WSDL.exe all well and good.

我现在想通过伪造出来的Web服务来编写针对我的包装和商业类的测试。没有任何接口或抽象基类的代理,他们被标记内部,这意味着他们从没有把我的假/模拟测试code到我的公司的项目/集,我不能继承。

I now want to write tests against my wrapper and business classes by faking out the web service. There is no interface or abstract base class to the proxy, and they are marked internal, meaning I can't inherit from them without putting my Fake/mock test code into my business project/assemblies.

我可以手动创建一个接口(使用ReSharper的)和编辑类,但是如果第三部分改变自己的WSDL / Web服务我或我的继任者也必须手动编辑界面,并自动生成的类,它似乎永远是个好主意。

I could manually create an interface (using resharper) and edit the class, however if the 3rd part change their WSDL/web service I or my successors will have to also manually edit the interface, and automatically generated classes, which never seems like a good idea.

什么是最优雅的方式伪造或模拟这项服务?我应该把假的创业项目?我应该手动编辑的文件,并创建一个接口?我应该做的东西完全不同呢?

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

推荐答案

右,由菲利普的回答我在一个衬托,并可能已拿出一个可行的解决方案提示。使用WSDL.EXE我生成的接口(使用/ SI交换机)正常的代理类,并增加了两个对我的业务项目。

Right, prompted by Philip's answer I set off on one, and may have come up with a working solution. Using WSDL.exe I generated the interfaces (using the /si switch) and normal proxy classes, and added both to my business project.

然后,我创建了一个新的类继承自具体类和实现接口。这个小类包含基本没有code,作为继承混凝土构件提供了一个隐含的实现接口的成员。在code编译第一次,我已经能够替代这个小垫片(?适配器?)类为我的集成测试,并执行调用对现场的第三方服务器。

I then created a new class which inherits from the concrete class AND implements the interface. This little class contained basically no code, as the inherited concrete members provided an implicit implementation of the interface members. The code compiled first time and I've been able to substitute this little "shim" (?adaptor?) class into my integration tests, and execute calls against the live 3rd party server.

我现在可以创建其他类(嘲笑或假货),它实现接口,并substitue的垫片级的他们,而不是。

I can now create other classes (mocks or fakes) which implement the interface, and substitue them instead of the "shim" class.

编辑: 好了,我的工作对这个远一点,而除非有并发症少,它的工作。

OK, I've worked a little further on this, and barring a few complications it's working.

第一个显著的问题是,代理类仍然标有内部,所以派生(适配器/垫片)类必须是内部了。这不是一个问题,如果你把一个工厂类到你的业务项目/组件,新的向上的代理类,并将其返回作为接口。

The first significant issue is that the proxy classes are still marked "internal", so the derived (adaptor/shim) class has to be internal too. This isn't a problem if you put a Factory class into your business project/assembly which new's up the proxy classes, and returns them as the interface.

我发现的第二个问题是,我们设定明确的webserice的URL和超时属性,但这些并不包括在相反,他们是从System.Web.Services.Protocols.WebClientProtocol通过SoapHttpClientProtocol继承的接口。同样,我处理了这个在工厂,因为它是一个实现细节,我很高兴没有在接口。

The second issue I found was that we were setting the URL and timeout properties of the webserice explicitly, but these are not included in the interface instead they are inherited from System.Web.Services.Protocols.WebClientProtocol via SoapHttpClientProtocol. Again, I dealt with this in the factory, as it's an implementation detail that I'm happy isn't in the interface.

编辑: 这是仍在制定preTY很适合我,而测试和开发我们的门面。由于获得代理的接口后面,我还创建了一个日志装饰类,它捕捉例的负载要求使用调试,当第三方服务器处于脱机状态。

This is still working out prety well for me while testing and developing our Facade. Since getting the proxy behind an interface I've also created a logging decorator class, which is capturing loads of example calls for use debugging, and when the 3rd party server is offline.

我已经写了什么,我在一个小更详细的在这里做:<一href="http://www.flowerchild.org.uk/archive/2010/09/21/mocking-or-faking-or-maybe-stubbing-a-wsdl-exe-soap.html" rel="nofollow">http://www.flowerchild.org.uk/archive/2010/09/21/mocking-or-faking-or-maybe-stubbing-a-wsdl-exe-soap.html

I've written up what I did in a little more detail here: http://www.flowerchild.org.uk/archive/2010/09/21/mocking-or-faking-or-maybe-stubbing-a-wsdl-exe-soap.html

这篇关于WSDL.EXE - 生成界面,以及具体的类,便于伪造/后嘲笑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆