|
| 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 | +} |
0 commit comments