add tests for normalization and serving multiple pages

This commit is contained in:
GHXX 2024-01-14 00:56:56 +01:00
parent 020075ad54
commit aa06679742

View File

@ -15,7 +15,7 @@ public class SimpleServerTest {
private async Task RequestGetStringAsync(string path) => await activeHttpClient!.GetStringAsync(GetRequestPath(path));
private async Task<HttpResponseMessage> AssertGetStatusCodeAsync(string path, HttpStatusCode statusCode) {
var resp = await activeHttpClient!.GetAsync(GetRequestPath(path));
Assert.AreEqual(resp.StatusCode, statusCode);
Assert.AreEqual(statusCode, resp.StatusCode);
return resp;
}
@ -56,15 +56,50 @@ public class SimpleServerTest {
await Console.Out.WriteLineAsync("Shutdown finished.");
}
static string GetHttpPageContentFromPrefix(string page)
=> $"It works!!!!!!56sg5sdf46a4sd65a412f31sdfgdf89h74g9f8h4as56d4f56as2as1f3d24f87g9d87{page}";
[TestMethod]
public async Task CheckSimpleServe() {
await AssertGetStatusCodeAsync("/", HttpStatusCode.OK);
var resp = await AssertGetStatusCodeAsync("/", HttpStatusCode.OK);
var str = await resp.Content.ReadAsStringAsync();
Assert.AreEqual("It works!", str);
}
[TestMethod]
public async Task CheckMultiServe() {
foreach (var item in "index2.html;testpage;testpage2;testpage3".Split(';')) {
await Console.Out.WriteLineAsync($"Checking page: /{item}");
var resp = await AssertGetStatusCodeAsync(item, HttpStatusCode.OK);
var str = await resp.Content.ReadAsStringAsync();
Assert.AreEqual(GetHttpPageContentFromPrefix(item), str);
}
}
public class TestEndpoints {
[HttpEndpoint(HttpRequestType.GET, "/", "index.html", "amogus.html")]
[HttpEndpoint(HttpRequestType.GET, "/", "index.html")]
public static async Task Index(RequestContext req) {
await req.RespWriter.WriteLineAsync("It works!");
await req.RespWriter.WriteAsync("It works!");
}
[HttpEndpoint(HttpRequestType.GET, "index2.html")]
public static async Task Index2(RequestContext req) {
await req.RespWriter.WriteAsync(GetHttpPageContentFromPrefix("index2.html"));
}
[HttpEndpoint(HttpRequestType.GET, "/testpage")]
public static async Task TestPage(RequestContext req) {
await req.RespWriter.WriteAsync(GetHttpPageContentFromPrefix("testpage"));
}
[HttpEndpoint(HttpRequestType.GET, "testpage2")]
public static async Task TestPage2(RequestContext req) {
await req.RespWriter.WriteAsync(GetHttpPageContentFromPrefix("testpage2"));
}
[HttpEndpoint(HttpRequestType.GET, "/testpage3")]
public static async Task TestPage3(RequestContext req) {
await req.RespWriter.WriteAsync(GetHttpPageContentFromPrefix("testpage3"));
}
}
}