Huge refactor; Passing tests
This commit is contained in:
@@ -1,15 +1,52 @@
|
||||
using SimpleHttpServer;
|
||||
using SimpleHttpServerTest.SimpleTestServer;
|
||||
|
||||
namespace SimpleHttpServerTest;
|
||||
|
||||
[TestClass]
|
||||
public class SimpleServerTest {
|
||||
|
||||
const int PORT = 8833;
|
||||
|
||||
private HttpServer? activeServer = null;
|
||||
private static string GetRequestPath(string url) => $"http://localhost:{PORT}/{url.TrimStart('/')}";
|
||||
|
||||
[TestInitialize]
|
||||
public void Init() {
|
||||
var conf = new SimpleHttpServerConfiguration();
|
||||
if (activeServer != null)
|
||||
throw new InvalidOperationException("Tried to create another httpserver instance when an existing one was already running.");
|
||||
|
||||
Console.WriteLine("Starting server...");
|
||||
activeServer = new HttpServer(PORT, conf);
|
||||
activeServer.RegisterEndpointsFromType<TestEndpoints>();
|
||||
activeServer.Start();
|
||||
|
||||
Console.WriteLine("Server started.");
|
||||
}
|
||||
|
||||
|
||||
[TestCleanup]
|
||||
public async Task Cleanup() {
|
||||
var ctokSrc = new CancellationTokenSource(TimeSpan.FromMinutes(2));
|
||||
if (activeServer == null) {
|
||||
throw new InvalidOperationException("Tried to shut down server when an existing one wasnt runnign yet");
|
||||
}
|
||||
await Console.Out.WriteLineAsync("Shutting down server...");
|
||||
await activeServer.StopAsync(ctokSrc.Token);
|
||||
await Console.Out.WriteLineAsync("Shutdown finished.");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void RunTestServer() {
|
||||
var server = HttpServer.Create(8833, "localhost", typeof(SimpleEndpointDefinition));
|
||||
server.Start();
|
||||
Console.WriteLine("press any key to exit");
|
||||
Assert.IsTrue(server.Shutdown(10000), "server did not exit gracefully");
|
||||
public async Task CheckSimpleServe() {
|
||||
using var hc = new HttpClient();
|
||||
await hc.GetStringAsync(GetRequestPath("/"));
|
||||
}
|
||||
|
||||
public class TestEndpoints {
|
||||
|
||||
[HttpEndpoint(HttpRequestType.GET, "/", "index.html", "amogus.html")]
|
||||
public static async Task Index(RequestContext req) {
|
||||
await req.RespWriter.WriteLineAsync("It works!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
namespace SimpleHttpServerTest.SimpleTestServer;
|
||||
internal class LdAuthorizer {
|
||||
private readonly LoginProvider lprov;
|
||||
|
||||
internal LdAuthorizer(LoginProvider lprov) {
|
||||
this.lprov = lprov;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
namespace SimpleHttpServerTest.SimpleTestServer;
|
||||
internal class SimpleEndpointDefinition {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user