mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-11 21:05:18 +01:00
Attempt to fix JSON parsing of text/plain content type (#1172)
* UseContentType * Fix unit tests * Add a unit test and an integration test for the fix. * Simplify body type checking with GetBodyType extension. * Split IBodyDataExtension, and use imperative style instead of functional style * Remove excessive null forgiving operators * Adjust braces --------- Co-authored-by: Ruxo Zheng <rz@just.sent.as>
This commit is contained in:
@@ -49,6 +49,26 @@ public class HttpRequestMessageHelperTests
|
||||
Check.That(await message.Content.ReadAsByteArrayAsync().ConfigureAwait(false)).ContainsExactly(Encoding.UTF8.GetBytes("hi"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HttpRequestMessageHelper_Create_TextPlain()
|
||||
{
|
||||
// Assign
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsString = "0123", // or 83 in decimal
|
||||
BodyAsJson = 83,
|
||||
DetectedBodyType = BodyType.Json,
|
||||
DetectedBodyTypeFromContentType = BodyType.String
|
||||
};
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", ClientIp, body);
|
||||
|
||||
// Act
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
Check.That(await message.Content!.ReadAsStringAsync().ConfigureAwait(false)).Equals("0123");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HttpRequestMessageHelper_Create_Json()
|
||||
{
|
||||
@@ -64,7 +84,7 @@ public class HttpRequestMessageHelperTests
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
Check.That(await message.Content.ReadAsStringAsync().ConfigureAwait(false)).Equals("{\"x\":42}");
|
||||
Check.That(await message.Content!.ReadAsStringAsync().ConfigureAwait(false)).Equals("{\"x\":42}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user