Skip to content

Instantly share code, notes, and snippets.

@flashlin
Last active August 28, 2020 13:57
Show Gist options
  • Save flashlin/22b36afc62bba5598795dd59eff67e30 to your computer and use it in GitHub Desktop.
Save flashlin/22b36afc62bba5598795dd59eff67e30 to your computer and use it in GitHub Desktop.
System Under Test (SUT) Integration Test for dotnet core 3 #test #aspnetcore3
public class BasicSystemUnderTest<TStartup> : IClassFixture<WebApplicationFactory<TStartup>>
where TStartup : class
{
protected readonly WebApplicationFactory<TStartup> _factory;
public BasicSystemUnderTest(WebApplicationFactory<TStartup> factory)
{
_factory = factory;
}
public async Task Test1()
{
var client = _factory
.CreateClient();
var response = await client.GetAsync("/Home/Hello");
//response.EnsureSuccessStatusCode(); // Status Code 200-299
var content = await response.Content.ReadAsStringAsync();
Assert.Equal("text/plain; charset=utf-8", response.Content.Headers.ContentType.ToString());
Assert.Equal("Hello Razor", content);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment