N 单元使用回调测试 WCF
我正在对 WCF 服务进行单元测试。
流程是这样的。
- 应用程序(客户端)通过Webservice1向数据库插入命令。这是使用双工模式完成的。(带有回调)。
- WebService1 将命令插入数据库,并且该 Webservice1 调用另一个有关新命令到达的 Webservice2。(双工模式)。
- 然后,Webservice2 通过 Webservice3 读取命令、执行、插入结果并调用 Webservice1 上的回调方法,告知命令已执行。
- 然后Webservice1调用Application上的回调方法并通知结果到达。
我如何对这样的服务进行单元测试。
请发布任何包含如何测试回调的教程的链接。
谢谢,
I am unit testing a WCF service.
The flow goes like this.
- Application(Client) insert command to the DB through Webservice1. This is done using duplex pattern.(with callbacks).
- WebService1 inserts the command to DB and this Webservice1 invokes another webservice2 about the arrival of new command.(Duplex pattern).
- Webservice2 then reads the command through Webservice3, executes, inserts the results and invoke the callback method on Webservice1 telling the command is executed.
- Webservice1 then invoke callback method on the Application and informs the arrival of result.
How can I Unit test such a service.
Please post any links where there are tutorials how to test callbacks.
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该单独测试服务以进行单元测试,模拟它们将调用的服务的响应。通过这种方式,您可以将各个服务作为小工作单元进行测试,并验证它们是否按预期工作。您还可以专注于每个服务的功能,而不必真正担心服务如何相互交互。
我认为您所描述的更多的是集成测试。您应该仅在对上述特定服务执行单独的单元测试后才执行该测试。本质上:
对于双工服务的单元测试,这里有一篇详细记录的博客文章,描述了如何执行此操作(包含大量代码):http://blogs.msdn.com/b/ploeh/archive/2008/06/28/unit-testing-duplex-wcf -services.aspx
因此,您将创建单元测试来测试与列表中的项目 #1 和 #4 的交互(app -> ws1 和 ws1 -> app),然后测试与项目 #2 和 # 的交互3(ws1 -> ws2 和 ws2 -> ws1),然后对#3(ws2 -> ws3)的交互进行单元测试。最后一个你可以嘲笑。没有更多细节,这就是我开始进行单元测试的方式。
我希望这有帮助。
You should be testing the services individually for unit testing, mocking the responses from the services that they would be calling. This way you can test the individual services as small units of work and validate that they work as expected. You can also focus on the functionality of each service without really worrying, yet, about how the services interact with each other for real.
I think what you're describing is more of an integration test. You should perform that test only after you have performed individual unit tests on the specific services that you described above. In essence:
For unit testing your duplex services, here's a well documented blog post describing how to do this (with lots of code): http://blogs.msdn.com/b/ploeh/archive/2008/06/28/unit-testing-duplex-wcf-services.aspx
So you would create unit tests that test the interaction with items #1 and #4 from your list (app -> ws1 and ws1 -> app), then interactions with items #2 and #3 (ws1 -> ws2 and ws2 -> ws1), then unit test the interaction of #3 (ws2 -> ws3). This last one you can just mock. Without much more detail, that's how I'd start to go about unit testing this.
I hope this helps.