-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathFunctionalTests.cs
More file actions
68 lines (56 loc) · 2.51 KB
/
FunctionalTests.cs
File metadata and controls
68 lines (56 loc) · 2.51 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
59
60
61
62
63
64
65
66
67
68
using System.Net;
namespace EssentialCSharp.Web.Tests;
[NotInParallel("FunctionalTests")]
[ClassDataSource<WebApplicationFactory>(Shared = SharedType.PerClass)]
public class FunctionalTests(WebApplicationFactory factory)
{
[Test]
[Arguments("/")]
[Arguments("/hello-world")]
[Arguments("/hello-world#hello-world")]
[Arguments("/guidelines")]
[Arguments("/health")]
[Arguments("/alive")]
public async Task WhenTheApplicationStarts_ItCanLoadLoadPages(string relativeUrl)
{
HttpClient client = factory.CreateClient();
using HttpResponseMessage response = await client.GetAsync(relativeUrl);
await Assert.That(response.StatusCode).IsEqualTo(HttpStatusCode.OK);
}
[Test]
[Arguments("/guidelines?rid=test-referral-id")]
[Arguments("/about?rid=abc123")]
[Arguments("/hello-world?rid=user-referral")]
[Arguments("/guidelines?rid=")]
[Arguments("/about?rid= ")]
[Arguments("/guidelines?foo=bar")]
[Arguments("/about?someOtherParam=value")]
public async Task WhenPagesAreAccessed_TheyReturnHtml(string relativeUrl)
{
HttpClient client = factory.CreateClient();
using HttpResponseMessage response = await client.GetAsync(relativeUrl);
await Assert.That(response.StatusCode).IsEqualTo(HttpStatusCode.OK);
// Ensure the response has content (not blank)
string content = await response.Content.ReadAsStringAsync();
await Assert.That(content).IsNotEmpty();
// Verify it's actually HTML content, not just whitespace
await Assert.That(content).Contains("<html", StringComparison.OrdinalIgnoreCase);
}
[Test]
[Arguments("/guidelines", "window.PERCENT_COMPLETE = null;")]
public async Task WhenNonContentPageIsRendered_LayoutIncludesNullPercentComplete(string relativeUrl, string expectedSnippet)
{
HttpClient client = factory.CreateClient();
using HttpResponseMessage response = await client.GetAsync(relativeUrl);
await Assert.That(response.StatusCode).IsEqualTo(HttpStatusCode.OK);
string content = await response.Content.ReadAsStringAsync();
await Assert.That(content).Contains(expectedSnippet);
}
[Test]
public async Task WhenTheApplicationStarts_NonExistingPage_GivesCorrectStatusCode()
{
HttpClient client = factory.CreateClient();
using HttpResponseMessage response = await client.GetAsync("/non-existing-page1234");
await Assert.That(response.StatusCode).IsEqualTo(HttpStatusCode.NotFound);
}
}