Last active
May 22, 2020 00:24
-
-
Save josephwoodward/7b7c1b751a8c570658b5afdad4d55709 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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