Skip to content

Commit 580b8be

Browse files
committed
Server test.
1 parent 3a7178d commit 580b8be

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/Components/test/E2ETest/ServerRenderingTests/NoInteractivityTest.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Net.Http;
45
using Components.TestServer.RazorComponents;
56
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
67
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
@@ -25,6 +26,21 @@ public NoInteractivityTest(
2526
public override Task InitializeAsync()
2627
=> InitializeAsync(BrowserFixture.StreamingContext);
2728

29+
[Fact]
30+
public async Task CanRenderNotFound()
31+
{
32+
var url = $"{ServerPathBase}/render-not-found-ssr";
33+
Navigate(url);
34+
var statusCode = await GetStatusCodeAsync(url);
35+
Assert.Equal(404, statusCode);
36+
}
37+
private async Task<int> GetStatusCodeAsync(string relativeUrl)
38+
{
39+
using var client = new HttpClient();
40+
string absoluteUrl = $"{_serverFixture.RootUri}/{relativeUrl}";
41+
var response = await client.GetAsync(absoluteUrl);
42+
return (int)response.StatusCode;
43+
}
2844
[Fact]
2945
public void NavigationManagerCanRefreshSSRPageWhenInteractivityNotPresent()
3046
{
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@page "/render-not-found-ssr"
2+
@inject NavigationManager NavigationManager
3+
4+
<p id="test-info">Any content</p>
5+
6+
@code{
7+
protected override void OnInitialized()
8+
{
9+
NavigationManager.NotFound();
10+
}
11+
}

src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/Routing/RoutingTestCases.razor

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,13 @@
2323
<li>
2424
<a href="routing/complex-segment(value)">Complex segments</a>
2525
</li>
26+
<li>
27+
<a href="routing/not-found-ssr">Not found page for Static Server Rendering</a>
28+
</li>
29+
<li>
30+
<a href="routing/not-found-webassembly">Not found page for Interactive WebAssembly rendering</a>
31+
</li>
32+
<li>
33+
<a href="routing/not-found-server">Not found page for Interactive Server rendering</a>
34+
</li>
2635
</ul>

0 commit comments

Comments
 (0)