tuitio/test/UnitTests/Tuitio.Wrapper.Tests/Stubs/HttpMessageHandlerStub.cs

31 lines
946 B
C#
Raw Normal View History

2023-03-14 01:06:09 +02:00
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);
}
}
}