2020-04-25 14:14:59 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Net.Http;
|
|
|
|
using System.Threading.Tasks;
|
2020-08-01 13:03:06 +00:00
|
|
|
using HttpClient = NucuCar.Domain.HttpClient;
|
2020-04-25 14:14:59 +00:00
|
|
|
|
|
|
|
namespace NucuCar.UnitTests.NucuCar.Common.Tests
|
|
|
|
{
|
2020-08-01 13:03:06 +00:00
|
|
|
public class MockHttpClient : Domain.HttpClient
|
2020-04-25 14:14:59 +00:00
|
|
|
{
|
|
|
|
public List<HttpRequestMessage> SendAsyncArgCalls;
|
|
|
|
public List<HttpResponseMessage> SendAsyncResponses;
|
|
|
|
|
|
|
|
private int _sendAsyncCallCounter;
|
|
|
|
|
|
|
|
public MockHttpClient(string baseAddress) : base(baseAddress)
|
|
|
|
{
|
|
|
|
_sendAsyncCallCounter = 0;
|
|
|
|
SendAsyncArgCalls = new List<HttpRequestMessage>();
|
|
|
|
SendAsyncResponses = new List<HttpResponseMessage>();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override Task<HttpResponseMessage> SendAsync(HttpRequestMessage requestMessage)
|
|
|
|
{
|
|
|
|
SendAsyncArgCalls.Add(requestMessage);
|
|
|
|
var response = SendAsyncResponses[_sendAsyncCallCounter];
|
|
|
|
_sendAsyncCallCounter += 1;
|
|
|
|
return Task.FromResult(response);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|