Unit Testing HttpClient In An ASP.NET MVC Controller

The nice thing about HttpClient is that it was designed with unit testing in mind, unlike previous .NET http objects like WebClient and WebRequest which required you to write wrappers. As such you don’t need to use dependency injection in order to unit test HttpClient, which keeps your code that much more readable. So, how to do it? First, you need to pass HttpClient into the controller’s constructor [Read More]