Mocking HttpClient in unit tests
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have some issues trying to wrap my code to be used in unit tests. The issues is this. I Have the interface IHttpHandler: public interface IHttpHandler { HttpClient client { get; } } And the class using it, HttpHandler: public class HttpHandler : IHttpHandler { public HttpClient client { get { return new HttpClient(); } } } And then the Connection class, which uses simpleIOC to inject the client implementation: public class Connection { private IHttpHandler _httpClient; public Connection(IHttpHandler httpClient) { _httpClient = httpClient;