Skip to content

Instantly share code, notes, and snippets.

@explorer14
Last active August 22, 2019 19:48
Show Gist options
  • Save explorer14/d3a91756ec88d9a6c8cc6a5c0bc2b5e9 to your computer and use it in GitHub Desktop.
Save explorer14/d3a91756ec88d9a6c8cc6a5c0bc2b5e9 to your computer and use it in GitHub Desktop.
namespace Domain.Tests.Unit.Stubs
{
internal class SubmissionServiceHttpHandlerStub : HttpMessageHandler
{
private Dictionary<string, Payload> _requestPayload;
protected override async Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request,
CancellationToken cancellationToken)
{
_payload = JsonConvert.DeserializeObject<Dictionary<string,
Payload>>(
await request.Content.ReadAsStringAsync());
// Assume that submission was successful,
// construct the response payload
var result = ConstructResponsePayload(_payload)
return new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(JsonConvert.SerializeObject(result))
};
}
internal Payload PayloadDto(
string key) =>
_payload[key].FirstOrDefault();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment