|
3 | 3 | namespace EssentialCSharp.Web.Tests; |
4 | 4 |
|
5 | 5 | /// <summary> |
6 | | -/// Unit tests for the route parameter regex in RouteConfigurationService. |
7 | | -/// Calls RouteParameterRegex() directly to verify which patterns match (and should be |
8 | | -/// excluded from the sitemap) vs. which do not (and should be included). |
| 6 | +/// Parameterized tests for the route parameter regex in RouteConfigurationService. |
9 | 7 | /// </summary> |
10 | 8 | public class RouteParameterFilterTests |
11 | 9 | { |
12 | | - // --- patterns that SHOULD match (route is parameterised → excluded from sitemap) --- |
13 | | - |
14 | | - [Test] |
15 | | - public async Task RouteParameterRegex_MatchesSimpleCurlyBraceParameter() |
16 | | - => await Assert.That(RouteConfigurationService.RouteParameterRegex().IsMatch("{chapter}")).IsTrue(); |
17 | | - |
18 | | - [Test] |
19 | | - public async Task RouteParameterRegex_MatchesConstrainedParameter() |
20 | | - => await Assert.That(RouteConfigurationService.RouteParameterRegex().IsMatch("{id:guid}")).IsTrue(); |
21 | | - |
22 | | - [Test] |
23 | | - public async Task RouteParameterRegex_MatchesOptionalParameter() |
24 | | - => await Assert.That(RouteConfigurationService.RouteParameterRegex().IsMatch("{id?}")).IsTrue(); |
25 | | - |
26 | | - [Test] |
27 | | - public async Task RouteParameterRegex_MatchesParameterWithDefault() |
28 | | - => await Assert.That(RouteConfigurationService.RouteParameterRegex().IsMatch("{action=Index}")).IsTrue(); |
29 | | - |
30 | | - [Test] |
31 | | - public async Task RouteParameterRegex_MatchesCatchAllParameter() |
32 | | - => await Assert.That(RouteConfigurationService.RouteParameterRegex().IsMatch("{*catchall}")).IsTrue(); |
33 | | - |
34 | | - [Test] |
35 | | - public async Task RouteParameterRegex_MatchesParameterEmbeddedInPath() |
36 | | - => await Assert.That(RouteConfigurationService.RouteParameterRegex().IsMatch("chapter/{chapter}/listing/{listing}")).IsTrue(); |
37 | | - |
38 | | - [Test] |
39 | | - public async Task RouteParameterRegex_MatchesSquareBracketSegment() |
40 | | - => await Assert.That(RouteConfigurationService.RouteParameterRegex().IsMatch("[optional]")).IsTrue(); |
41 | | - |
42 | | - [Test] |
43 | | - public async Task RouteParameterRegex_MatchesSquareBracketEmbeddedInPath() |
44 | | - => await Assert.That(RouteConfigurationService.RouteParameterRegex().IsMatch("area/[optional]/page")).IsTrue(); |
45 | | - |
46 | | - // --- patterns that should NOT match (static route → eligible for sitemap) --- |
47 | | - |
48 | | - [Test] |
49 | | - public async Task RouteParameterRegex_DoesNotMatchBareWord() |
50 | | - => await Assert.That(RouteConfigurationService.RouteParameterRegex().IsMatch("about")).IsFalse(); |
51 | | - |
52 | | - [Test] |
53 | | - public async Task RouteParameterRegex_DoesNotMatchHyphenatedRoute() |
54 | | - => await Assert.That(RouteConfigurationService.RouteParameterRegex().IsMatch("mcp-setup")).IsFalse(); |
55 | | - |
56 | | - [Test] |
57 | | - public async Task RouteParameterRegex_DoesNotMatchStaticMultiSegmentPath() |
58 | | - => await Assert.That(RouteConfigurationService.RouteParameterRegex().IsMatch("identity/account/login")).IsFalse(); |
59 | | - |
60 | | - [Test] |
61 | | - public async Task RouteParameterRegex_DoesNotMatchApiPrefixAlone() |
62 | | - => await Assert.That(RouteConfigurationService.RouteParameterRegex().IsMatch("api/listing")).IsFalse(); |
63 | | - |
64 | 10 | [Test] |
65 | | - public async Task RouteParameterRegex_DoesNotMatchEmptyString() |
66 | | - => await Assert.That(RouteConfigurationService.RouteParameterRegex().IsMatch(string.Empty)).IsFalse(); |
| 11 | + [Arguments("{chapter}")] |
| 12 | + [Arguments("{id:guid}")] |
| 13 | + [Arguments("{id?}")] |
| 14 | + [Arguments("{action=Index}")] |
| 15 | + [Arguments("{*catchall}")] |
| 16 | + [Arguments("chapter/{chapter}/listing/{listing}")] |
| 17 | + [Arguments("[optional]")] |
| 18 | + [Arguments("area/[optional]/page")] |
| 19 | + public async Task RouteParameterRegex_MatchesParameterizedRoutes(string route) |
| 20 | + => await Assert.That(RouteConfigurationService.RouteParameterRegex().IsMatch(route)).IsTrue(); |
| 21 | + |
| 22 | + [Test] |
| 23 | + [Arguments("about")] |
| 24 | + [Arguments("mcp-setup")] |
| 25 | + [Arguments("identity/account/login")] |
| 26 | + [Arguments("api/listing")] |
| 27 | + [Arguments("")] |
| 28 | + public async Task RouteParameterRegex_DoesNotMatchStaticRoutes(string route) |
| 29 | + => await Assert.That(RouteConfigurationService.RouteParameterRegex().IsMatch(route)).IsFalse(); |
67 | 30 | } |
0 commit comments