Skip to content

Instantly share code, notes, and snippets.

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