[英]Unit testing with a mock HttpListener
I should say that I'm fairly new in the mock-framework world of C#. 我应该说,我在C#的模拟框架世界中还很陌生。 I'm building a small service that listens to incoming HTTP requests using a System.Net.HttpListener
and would like to unit test my implementation by injecting a mock instance of that class. 我正在构建一个小型服务,该服务使用System.Net.HttpListener
侦听传入的HTTP请求,并希望通过注入该类的模拟实例来对实现进行单元测试。 So I tried using Moq , but that of course requires that the mock target is an interface so that it can provide a stub implementation. 因此,我尝试使用Moq ,但是当然需要模拟目标是一个接口,以便它可以提供存根实现。 Then I tried using Microsoft Fakes, but it won't let me generate a StubHttpListener
. 然后我尝试使用Microsoft Fakes,但不会让我生成StubHttpListener
。 So is there any other way to mock the behaviour of System.Net.HttpListener
? 那么还有其他方法可以模拟System.Net.HttpListener
的行为吗?
写一个包装HttpListener的类并从中提取一个接口,然后可以模拟/存根包装器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.