{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/corefx/issues/1624","labels_url":"https://api.github.com/repos/dotnet/corefx/issues/1624/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/1624/comments","events_url":"https://api.github.com/repos/dotnet/corefx/issues/1624/events","html_url":"https://github.com/dotnet/corefx/issues/1624","id":72915733,"number":1624,"title":"An simple way to mock an httpClient.GetAsync(..) method for unit tests?","user":{"login":"PureKrome","id":899878,"avatar_url":"https://avatars.githubusercontent.com/u/899878?v=3","gravatar_id":"","url":"https://api.github.com/users/PureKrome","html_url":"https://github.com/PureKrome","followers_url":"https://api.github.com/users/PureKrome/followers","following_url":"https://api.github.com/users/PureKrome/following{/other_user}","gists_url":"https://api.github.com/users/PureKrome/gists{/gist_id}","starred_url":"https://api.github.com/users/PureKrome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PureKrome/subscriptions","organizations_url":"https://api.github.com/users/PureKrome/orgs","repos_url":"https://api.github.com/users/PureKrome/repos","events_url":"https://api.github.com/users/PureKrome/events{/privacy}","received_events_url":"https://api.github.com/users/PureKrome/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dotnet/corefx/labels/System.Net","name":"System.Net","color":"d4c5f9"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":49,"created_at":"2015-05-04T04:03:43Z","updated_at":"2015-05-15T02:02:16Z","closed_at":null,"body":"`System.Net.Http` has now been uploaded to the repo :smile: :tada: :balloon: \r\n\r\nWhenever I've used this in some service, it works great but makes it hard to unit test => my unit tests don't want to actually ever hit that real end point.\r\n\r\nAges ago, I asked @davidfowl what should we do? I hoping I paraphrase and don't misquote him - but he suggested that I need to fake up a message handler (ie. `HttpClientHandler`), wire that up, etc. \r\n\r\nAs such, I ended up making a helper library called [HttpClient.Helpers](https://github.com/PureKrome/HttpClient.Helpers) to help me run my unit tests.\r\n\r\nSo this works ... but it feels _very_ messy and .. complicated. I'm sure I'm not the first person that needs to make sure my unit tests don't do a real call to an external service.\r\n\r\nIs there an easier way? Like .. can't we just have an `IHttpClient` interface and we can inject that into our service?"},"comment":{"url":"https://api.github.com/repos/dotnet/corefx/issues/comments/102221167","html_url":"https://github.com/dotnet/corefx/issues/1624#issuecomment-102221167","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/1624","id":102221167,"user":{"login":"luisrudge","id":941075,"avatar_url":"https://avatars.githubusercontent.com/u/941075?v=3","gravatar_id":"","url":"https://api.github.com/users/luisrudge","html_url":"https://github.com/luisrudge","followers_url":"https://api.github.com/users/luisrudge/followers","following_url":"https://api.github.com/users/luisrudge/following{/other_user}","gists_url":"https://api.github.com/users/luisrudge/gists{/gist_id}","starred_url":"https://api.github.com/users/luisrudge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/luisrudge/subscriptions","organizations_url":"https://api.github.com/users/luisrudge/orgs","repos_url":"https://api.github.com/users/luisrudge/repos","events_url":"https://api.github.com/users/luisrudge/events{/privacy}","received_events_url":"https://api.github.com/users/luisrudge/received_events","type":"User","site_admin":false},"created_at":"2015-05-15T02:02:16Z","updated_at":"2015-05-15T02:02:16Z","body":"@drub0y you forgot to mention that someone will have to figure it out that one needs to implement a `MockHttpMessageHandler` in the first place. That's the whole point of this discussion. It isn't straight forward enough. With aspnet5, you can test everything just mocking public class from interfaces or base classes with virtual methods, but this specific API entry is different, less discoverable and less intuitive."}}