add tests for normalization and serving multiple pages
This commit is contained in:
parent
020075ad54
commit
aa06679742
|
|
@ -15,7 +15,7 @@ public class SimpleServerTest {
|
||||||
private async Task RequestGetStringAsync(string path) => await activeHttpClient!.GetStringAsync(GetRequestPath(path));
|
private async Task RequestGetStringAsync(string path) => await activeHttpClient!.GetStringAsync(GetRequestPath(path));
|
||||||
private async Task<HttpResponseMessage> AssertGetStatusCodeAsync(string path, HttpStatusCode statusCode) {
|
private async Task<HttpResponseMessage> AssertGetStatusCodeAsync(string path, HttpStatusCode statusCode) {
|
||||||
var resp = await activeHttpClient!.GetAsync(GetRequestPath(path));
|
var resp = await activeHttpClient!.GetAsync(GetRequestPath(path));
|
||||||
Assert.AreEqual(resp.StatusCode, statusCode);
|
Assert.AreEqual(statusCode, resp.StatusCode);
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,15 +56,50 @@ public class SimpleServerTest {
|
||||||
await Console.Out.WriteLineAsync("Shutdown finished.");
|
await Console.Out.WriteLineAsync("Shutdown finished.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static string GetHttpPageContentFromPrefix(string page)
|
||||||
|
=> $"It works!!!!!!56sg5sdf46a4sd65a412f31sdfgdf89h74g9f8h4as56d4f56as2as1f3d24f87g9d87{page}";
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public async Task CheckSimpleServe() {
|
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 {
|
public class TestEndpoints {
|
||||||
[HttpEndpoint(HttpRequestType.GET, "/", "index.html", "amogus.html")]
|
[HttpEndpoint(HttpRequestType.GET, "/", "index.html")]
|
||||||
public static async Task Index(RequestContext req) {
|
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"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user