-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Respond with HTTP 400 if the request body cannot be deserialized
- Loading branch information
1 parent
c12cbbe
commit e33b053
Showing
2 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
|
||
using GenHTTP.Modules.Functional; | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace GenHTTP.Testing.Acceptance.Modules.Conversion | ||
{ | ||
|
||
[TestClass] | ||
public class ErrorHandlingTests | ||
{ | ||
|
||
#region Supporting data structures | ||
|
||
record class MyEntity(string Data); | ||
|
||
#endregion | ||
|
||
#region Tests | ||
|
||
[TestMethod] | ||
public async Task UndeserializableBodyReturnsWithBadRequest() | ||
{ | ||
var inline = Inline.Create() | ||
.Post("/t", (MyEntity entity) => entity.Data); | ||
|
||
using var runner = TestRunner.Run(inline); | ||
|
||
using var request = runner.GetRequest("/t"); | ||
|
||
request.Method = HttpMethod.Post; | ||
|
||
request.Content = new StringContent("I cannot be deserialized", null, "application/json"); | ||
request.Content.Headers.ContentType = new("application/json"); | ||
|
||
using var response = await runner.GetResponse(request); | ||
|
||
Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); | ||
} | ||
|
||
#endregion | ||
|
||
} | ||
|
||
} |