31 lines
946 B
C#
31 lines
946 B
C#
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Net.Http;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Tuitio.PublishedLanguage.Dto;
|
|
|
|
namespace Tuitio.Wrapper.Tests.Stubs
|
|
{
|
|
public class HttpMessageHandlerStub<T> : HttpMessageHandler where T : class
|
|
{
|
|
private readonly Envelope<T> _response;
|
|
|
|
public HttpMessageHandlerStub(Envelope<T> response)
|
|
{
|
|
_response = response ?? throw new ArgumentNullException(nameof(response));
|
|
}
|
|
|
|
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
|
{
|
|
var httpResponseMessage = new HttpResponseMessage()
|
|
{
|
|
StatusCode = System.Net.HttpStatusCode.OK,
|
|
Content = new StringContent(JsonConvert.SerializeObject(_response))
|
|
};
|
|
|
|
return Task.FromResult(httpResponseMessage);
|
|
}
|
|
}
|
|
}
|