Skip to content

Instantly share code, notes, and snippets.

@lawrence-laz
Created March 25, 2021 10:02
Show Gist options
  • Save lawrence-laz/1f86738c7e2b4820768f39b76ed4ec4c to your computer and use it in GitHub Desktop.
Save lawrence-laz/1f86738c7e2b4820768f39b76ed4ec4c to your computer and use it in GitHub Desktop.
Hosting a test application for automated integration tests.
[Theory]
[InlineData("Development")]
public async Task CallSwaggerEndpoint_ShouldReturnHttpOk(string environment)
{
// Arrange
using var sut = await Program.CreateHostBuilder(null)
.UseEnvironment(environment)
.UseDefaultServiceProvider((context, options) =>
{
options.ValidateScopes = true;
options.ValidateOnBuild = true;
})
.ConfigureWebHost(webBuilder =>
{
webBuilder.UseTestServer();
})
.StartAsync();
var client = sut.GetTestServer().CreateClient();
// Act
var response = await client.GetAsync($"/swagger/v1/swagger.json");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment