Skip to content

Instantly share code, notes, and snippets.

@josephwoodward
Last active May 22, 2020 00:23
Show Gist options
  • Save josephwoodward/f309039e18912f1b041d086b36257d20 to your computer and use it in GitHub Desktop.
Save josephwoodward/f309039e18912f1b041d086b36257d20 to your computer and use it in GitHub Desktop.
hc3.cs
// Arrange
var options = new HttpClientInterceptorOptions {ThrowOnMissingRegistration = true};
new HttpRequestInterceptionBuilder()
.Requests()
.ForHttps()
.ForHost("bbc.co.uk")
.ForPath("/news")
.Responds()
.WithStatus(500)
.RegisterWith(options);
var handler = options.CreateHttpMessageHandler();
// Act
var client = new HttpClient(handler);
var response = await client.GetAsync("https://bbc.co.uk/news");
// Assert
response.StatusCode.ShouldBe(HttpStatusCode.InternalServerError);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment