-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathFunctionalTests.cs
More file actions
58 lines (46 loc) · 1.92 KB
/
FunctionalTests.cs
File metadata and controls
58 lines (46 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System.Net;
namespace EssentialCSharp.Web.Tests;
public class FunctionalTests
{
[Theory]
[InlineData("/")]
[InlineData("/hello-world")]
[InlineData("/hello-world#hello-world")]
[InlineData("/guidelines")]
[InlineData("/healthz")]
public async Task WhenTheApplicationStarts_ItCanLoadLoadPages(string relativeUrl)
{
using WebApplicationFactory factory = new();
HttpClient client = factory.CreateClient();
using HttpResponseMessage response = await client.GetAsync(relativeUrl);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
[Theory]
[InlineData("/guidelines?rid=test-referral-id")]
[InlineData("/about?rid=abc123")]
[InlineData("/hello-world?rid=user-referral")]
[InlineData("/guidelines?rid=")]
[InlineData("/about?rid= ")]
[InlineData("/guidelines?foo=bar")]
[InlineData("/about?someOtherParam=value")]
public async Task WhenPagesAreAccessed_TheyReturnHtml(string relativeUrl)
{
using WebApplicationFactory factory = new();
HttpClient client = factory.CreateClient();
using HttpResponseMessage response = await client.GetAsync(relativeUrl);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
// Ensure the response has content (not blank)
string content = await response.Content.ReadAsStringAsync();
Assert.NotEmpty(content);
// Verify it's actually HTML content, not just whitespace
Assert.Contains("<html", content, StringComparison.OrdinalIgnoreCase);
}
[Fact]
public async Task WhenTheApplicationStarts_NonExistingPage_GivesCorrectStatusCode()
{
using WebApplicationFactory factory = new();
HttpClient client = factory.CreateClient();
using HttpResponseMessage response = await client.GetAsync("/non-existing-page1234");
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
}
}