Skip to content

Commit 3239610

Browse files
Merge pull request #2 from FromDoppler/DE-135-self-hosting-integration-test
test: add an example of self-hosting integration test
2 parents c610946 + 4414007 commit 3239610

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

Doppler.HelloMicroservice.Test/Doppler.HelloMicroservice.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
<ItemGroup>
1010
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
11+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.5" />
1112
<PackageReference Include="xunit" Version="2.4.1" />
1213
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
1314
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Net;
3+
using System.Threading.Tasks;
4+
using Microsoft.AspNetCore.Mvc.Testing;
5+
using Xunit;
6+
7+
namespace Doppler.HelloMicroservice
8+
{
9+
public class IntegrationTest1
10+
: IClassFixture<WebApplicationFactory<Startup>>
11+
{
12+
private readonly WebApplicationFactory<Startup> _factory;
13+
14+
public IntegrationTest1(WebApplicationFactory<Startup> factory)
15+
{
16+
_factory = factory;
17+
}
18+
19+
[Theory]
20+
[InlineData("/WeatherForecast", HttpStatusCode.OK, "application/json; charset=utf-8")]
21+
[InlineData("/swagger", HttpStatusCode.Moved, null)]
22+
[InlineData("/swagger/index.html", HttpStatusCode.OK, "text/html; charset=utf-8")]
23+
[InlineData("/robots.txt", HttpStatusCode.OK, "text/plain")]
24+
[InlineData("/favicon.ico", HttpStatusCode.OK, "image/x-icon")]
25+
[InlineData("/swagger/v1/swagger.json", HttpStatusCode.OK, "application/json; charset=utf-8")]
26+
[InlineData("/", HttpStatusCode.NotFound, null)]
27+
[InlineData("/Not/Found", HttpStatusCode.NotFound, null)]
28+
public async Task GET_endpoints_return_correct_status_and_contentType(string url, HttpStatusCode expectedStatusCode, string expectedContentType)
29+
{
30+
// Arrange
31+
var client = _factory.CreateClient(new WebApplicationFactoryClientOptions()
32+
{
33+
AllowAutoRedirect = false
34+
});
35+
36+
// Act
37+
var response = await client.GetAsync(url);
38+
39+
// Assert
40+
Assert.Equal(expectedStatusCode, response.StatusCode);
41+
Assert.Equal(expectedContentType, response.Content?.Headers?.ContentType?.ToString());
42+
}
43+
}
44+
}

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,6 @@ If you prefer to run these commands without docker, you can read [Dockerfile](./
5454

5555
- Allow overriding project settings based on our Doppler conventions.
5656

57-
- Expose Swagger (with support for segment prefix)
57+
- Expose Swagger (with support for segment prefix).
58+
59+
- Including an example of a self-hosting integration test.

0 commit comments

Comments
 (0)