34 lines
803 B
C#
34 lines
803 B
C#
using System;
|
|
using System.Net.Http;
|
|
using RichardSzalay.MockHttp;
|
|
|
|
namespace Website.Tests {
|
|
public class HttpClientBuilder {
|
|
private string _url, _response;
|
|
private HttpMethod _method;
|
|
|
|
public HttpClientBuilder WithUrl(string url) {
|
|
_url = url;
|
|
return this;
|
|
}
|
|
|
|
public HttpClientBuilder WithResponse(string response) {
|
|
_response = response;
|
|
return this;
|
|
}
|
|
|
|
public HttpClientBuilder WithMethod(HttpMethod method) {
|
|
_method = method;
|
|
return this;
|
|
}
|
|
|
|
public HttpClient Build() {
|
|
var httpMessageHandler = new MockHttpMessageHandler();
|
|
httpMessageHandler.When(_method, _url).Respond("application/json", _response);
|
|
|
|
var httpClient = httpMessageHandler.ToHttpClient();
|
|
httpClient.BaseAddress = new Uri("http://example.com");
|
|
return httpClient;
|
|
}
|
|
}
|
|
}
|