Skip to content

Instantly share code, notes, and snippets.

@GeorgDangl
Created November 21, 2017 22:55
Show Gist options
  • Save GeorgDangl/0e128bfb3fff96e51a0bbc89ea331e89 to your computer and use it in GitHub Desktop.
Save GeorgDangl/0e128bfb3fff96e51a0bbc89ea331e89 to your computer and use it in GitHub Desktop.
How to not implement your HttpMessageHandler when using the Asp.Net Core TestHost
public class IntegrationTestsHttpMessageHandler : HttpMessageHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var handler = TestServer.CreateHandler();
return handler.SendAsync(request, cancellationToken);
}
}
public class IntegrationTestsHttpMessageHandler : HttpMessageHandler
{
private HttpClient Client => TestServer.CreateClient();
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
return Client.SendAsync(request, cancellationToken);
}
}
Action<JwtBearerOptions> additionalJwtOptions = options =>
{
options.BackchannelHttpHandler = new IntegrationTestsHttpMessageHandler();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment