Created
August 3, 2022 18:38
-
-
Save iknowcodesoup/c25ca24351a04f3e6269b14e255d1f1e to your computer and use it in GitHub Desktop.
MockHttpMessageHandler
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
using System.Net.Http; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace Namespace123 | |
{ | |
public class MockHttpMessageHandler : HttpMessageHandler | |
{ | |
private readonly HttpResponseMessage? message; | |
public MockHttpMessageHandler(HttpResponseMessage? message = null) | |
{ | |
this.message = message; | |
} | |
protected override Task<HttpResponseMessage> SendAsync( | |
HttpRequestMessage request, | |
CancellationToken cancellationToken) | |
{ | |
return SendAsync(request); | |
} | |
public virtual Task<HttpResponseMessage> SendAsync(HttpRequestMessage request) | |
{ | |
return Task.FromResult( | |
message ?? | |
new HttpResponseMessage(System.Net.HttpStatusCode.OK) | |
{ | |
RequestMessage = request | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment