-
Notifications
You must be signed in to change notification settings - Fork 1
Introduce DI support and customizable server options #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,59 +7,63 @@ | |||||||||||||||||||
| using FluentAssertions; | ||||||||||||||||||||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||||||||||||||||||||
| using Newtonsoft.Json; | ||||||||||||||||||||
| using Yllibed.HttpServer.Json; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| namespace Yllibed.HttpServer.Json.Tests | ||||||||||||||||||||
| namespace Yllibed.HttpServer.Json.Tests; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| [TestClass] | ||||||||||||||||||||
| public class JsonHandlerBaseFixture : FixtureBase | ||||||||||||||||||||
| { | ||||||||||||||||||||
| [TestClass] | ||||||||||||||||||||
| public class JsonHandlerBaseFixture : FixtureBase | ||||||||||||||||||||
| [TestMethod] | ||||||||||||||||||||
| public async Task TestSimpleGet_WithJsonHandler() | ||||||||||||||||||||
| { | ||||||||||||||||||||
| [TestMethod] | ||||||||||||||||||||
| public async Task TestSimpleGet_WithJsonHandler() | ||||||||||||||||||||
| { | ||||||||||||||||||||
| var server = new Server(); | ||||||||||||||||||||
| var server = new Server(); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| var (uri4, uri6) = server.Start(); | ||||||||||||||||||||
| var requestUri = uri4 + "abcd?a=1&b=%20%2020"; | ||||||||||||||||||||
| var (uri4, uri6) = server.Start(); | ||||||||||||||||||||
| var requestUri = uri4 + "abcd?a=1&b=%20%2020"; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| var sut = new MyJsonHandler("GET", "abcd"); | ||||||||||||||||||||
| var sut = new MyJsonHandler("GET", "abcd"); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| using (server.RegisterHandler(sut)) | ||||||||||||||||||||
| using (server.RegisterHandler(sut)) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| using (var client = new HttpClient()) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| using (var client = new HttpClient()) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| var response = await client.GetAsync(requestUri, CT); | ||||||||||||||||||||
| response.StatusCode.Should().Be(HttpStatusCode.OK); | ||||||||||||||||||||
| var response = await client.GetAsync(requestUri, CT); | ||||||||||||||||||||
| response.StatusCode.Should().Be(HttpStatusCode.OK); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| var result = JsonConvert.DeserializeObject<MyResultPayload>(await response.Content.ReadAsStringAsync(CT)); | ||||||||||||||||||||
| result.Should().NotBeNull(); | ||||||||||||||||||||
| result.Should().BeEquivalentTo(new { A = "1", B = " 20" }); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| var result = JsonConvert.DeserializeObject<MyResultPayload>(await response.Content.ReadAsStringAsync(CT).ConfigureAwait(false)); | ||||||||||||||||||||
| result.Should().NotBeNull(); | ||||||||||||||||||||
| result.Should().BeEquivalentTo(new { A = "1", B = " 20" }); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| public class MyResultPayload | ||||||||||||||||||||
| public class MyResultPayload | ||||||||||||||||||||
| { | ||||||||||||||||||||
| public string? A { get; set; } | ||||||||||||||||||||
| public string? B { get; set; } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| private sealed class MyJsonHandler : JsonHandlerBase<MyResultPayload> | ||||||||||||||||||||
| { | ||||||||||||||||||||
| public MyJsonHandler(string method, string path) : base(method, path) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| public string? A { get; set; } | ||||||||||||||||||||
| public string? B { get; set; } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
carldebilly marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+47
to
52
|
||||||||||||||||||||
| private sealed class MyJsonHandler : JsonHandlerBase<MyResultPayload> | |
| { | |
| public MyJsonHandler(string method, string path) : base(method, path) | |
| { | |
| public string? A { get; set; } | |
| public string? B { get; set; } | |
| } | |
| private sealed class MyJsonHandler(string method, string path) : JsonHandlerBase<MyResultPayload>(method, path) | |
| { |
Uh oh!
There was an error while loading. Please reload this page.