Add route smoke tests

This commit is contained in:
tleininger committed 2026-09-21 15:57:52 +02:00
1 parent 5e9146f2cb
commit f24a4e73a2
4 files changed
+98

No files matched your search

@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="10.0.12" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
</ItemGroup>
<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Elternbeirat.Web\Elternbeirat.Web.csproj" />
</ItemGroup>
</Project>
+65
View File
@@ -0,0 +1,65 @@
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",
];
[Theory]
[MemberData(nameof(KnownRoutes))]
public async Task Known_route_returns_200(string route)
{
var client = _factory.CreateClient();
var response = await client.GetAsync(route);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
[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(route);
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
}
}
+6
View File
@@ -7,6 +7,12 @@
<BlazorDisableThrowNavigationException>true</BlazorDisableThrowNavigationException>
</PropertyGroup>
<!-- The test project uses WebApplicationFactory<Program>, which needs the
auto-generated Program class (internal with top-level statements). -->
<ItemGroup>
<InternalsVisibleTo Include="Elternbeirat.Web.Tests" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Markdig" Version="0.38.0" />
</ItemGroup>
+1
View File
@@ -1,3 +1,4 @@
<Solution>
<Project Path="Elternbeirat.Web/Elternbeirat.Web.csproj" />
<Project Path="Elternbeirat.Web.Tests/Elternbeirat.Web.Tests.csproj" />
</Solution>