Skip to content

Instantly share code, notes, and snippets.

@bellons91
Created July 30, 2021 16:21
Show Gist options
  • Save bellons91/925fdec2577d2f8a95b244023235724e to your computer and use it in GitHub Desktop.
Save bellons91/925fdec2577d2f8a95b244023235724e to your computer and use it in GitHub Desktop.
Mock<HttpMessageHandler> handler = new Mock<HttpMessageHandler>();
var factory = handler.CreateClientFactory(); // it comes from Moq.Contrib.HttpClient
Mock.Get(factory).Setup(x => x.CreateClient("matrics"))
.Returns(() =>
{
var client = handler.CreateClient();
client.BaseAddress = new Uri("https://code4it.dev");
return client;
});
handler.SetupAnyRequest().ReturnsResponse("validContent");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment