Created
December 14, 2017 11:00
-
-
Save MichaelaIvanova/4e4ab256046694217fd69f83c7a1d646 to your computer and use it in GitHub Desktop.
HttpClient Unit Testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ICustomHttpClient | |
{ | |
Task<HttpResponseMessage> GetAsync(string url, int timeout); | |
} | |
//Decorating HttpClient in order to mock it | |
public class CustomHttpClient : ICustomHttpClient | |
{ | |
public CustomHttpClient() | |
{ | |
} | |
public async Task<HttpResponseMessage> GetAsync(string url, int timeout) | |
{ | |
using (var client = new HttpClient()) | |
{ | |
client.Timeout = TimeSpan.FromSeconds(timeout); | |
return await client.GetAsync(url); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment