68 lines
1.8 KiB
C#
68 lines
1.8 KiB
C#
using System.Net;
|
|
using Microsoft.AspNetCore.Mvc.Testing;
|
|
|
|
namespace Elternbeirat.Web.Tests;
|
|
|
|
/// <summary>
|
|
/// Smoke tests: every known route must return 200, unknown routes must return
|
|
/// 404. This catches broken content files, renamed slugs or routing regressions
|
|
/// before a deploy.
|
|
/// </summary>
|
|
public sealed class RouteSmokeTests : IClassFixture<WebApplicationFactory<Program>>
|
|
{
|
|
private readonly WebApplicationFactory<Program> _factory;
|
|
|
|
public RouteSmokeTests(WebApplicationFactory<Program> factory)
|
|
{
|
|
_factory = factory;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Every route that a visitor can reach through the navigation, the FAQ hub
|
|
/// or the news section.
|
|
/// </summary>
|
|
public static TheoryData<string> KnownRoutes =>
|
|
[
|
|
"/",
|
|
"/vorstandsteam",
|
|
"/foerderverein",
|
|
"/faq",
|
|
"/faq-mensa",
|
|
"/faq-schliessfach",
|
|
"/faq-elterneuro",
|
|
"/faq-elternarbeit",
|
|
"/downloads",
|
|
"/kontakt",
|
|
"/impressum",
|
|
"/datenschutz",
|
|
"/beitraege",
|
|
"/beitraege/neuer-vorstand-gewaehlt",
|
|
"/beitraege/neue-sporthalle-eroeffnet",
|
|
"/termine",
|
|
"/termine.ics",
|
|
];
|
|
|
|
[Theory]
|
|
[MemberData(nameof(KnownRoutes))]
|
|
public async Task Known_route_returns_200(string route)
|
|
{
|
|
var client = _factory.CreateClient();
|
|
|
|
var response = await client.GetAsync(new Uri(route, UriKind.Relative));
|
|
|
|
response.StatusCode.ShouldBe(HttpStatusCode.OK);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("/gibt-es-nicht")]
|
|
[InlineData("/beitraege/gibt-es-nicht")]
|
|
public async Task Unknown_route_returns_404(string route)
|
|
{
|
|
var client = _factory.CreateClient();
|
|
|
|
var response = await client.GetAsync(new Uri(route, UriKind.Relative));
|
|
|
|
response.StatusCode.ShouldBe(HttpStatusCode.NotFound);
|
|
}
|
|
}
|