Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Configure a HttpClient request using Moq
var mockHttpMessageHandler = new Mock<HttpMessageHandler>();
.Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.Is<HttpRequestMessage>(x => x.RequestUri == testUri), ItExpr.IsAny<CancellationToken>())
.Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(testJson) }));
// Then ...
new HttpClient(mockHttpMessageHandler.Object)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.