Created
May 22, 2020 00:28
-
-
Save josephwoodward/171c89097d1f2c4b2cdca562b3451a10 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public class ControllerTests : IClassFixture<Fixture<Startup>> | |
{ | |
private readonly Fixture<Startup> _fixture; | |
public ControllerTests(Fixture<Startup> fixture) => _fixture = fixture; | |
[Fact] | |
public async Task ReturnsOrganizationRepositories() | |
{ | |
// Arrange | |
using var _ = _fixture.InterceptorOptions.BeginScope(); | |
new HttpRequestInterceptionBuilder() | |
.Requests() | |
.ForHttps() | |
.ForHost("api.github.com") | |
.ForPath("orgs/weyland-yutani/repos") | |
.ForQuery("per_page=10") | |
.Responds() | |
.WithSystemTextJsonContent(new[] {new {id = 1, name = "foo"}, new {id = 2, name = "bar"}}) | |
.RegisterWith(_fixture.InterceptorOptions); | |
// Act | |
using var httpClient = _fixture.CreateClient(); | |
string json = await httpClient.GetStringAsync("api/repos"); | |
var actual = JsonConvert.DeserializeObject<string[]>(json); | |
// Assert | |
actual.ShouldBe(new[] {"bar", "foo"}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment