Skip to content

Commit

Permalink
JsonContent PR feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
ManickaP committed Jul 1, 2020
1 parent 14eae27 commit 6e90249
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,4 @@
<data name="SerializeWrongType" xml:space="preserve">
<value>The specified type {0} must derive from the specific value's type {1}.</value>
</data>
<data name="SyncNotSupported" xml:space="preserve">
<value>Synchronous serialization of JsonContent is not supported.</value>
</data>
</root>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ private async Task SerializeToStreamAsyncCore(Stream targetStream, bool async, C
else
{
// Have to use Utf8JsonWriter because JsonSerializer doesn't support sync serialization into stream directly.
// ToDo: Remove Utf8JsonWriter usage after https://github.com/dotnet/runtime/issues/1574
using Utf8JsonWriter writer = new Utf8JsonWriter(transcodingStream);
JsonSerializer.Serialize(writer, Value, ObjectType, _jsonSerializerOptions);
}
Expand Down Expand Up @@ -121,7 +122,7 @@ private async Task SerializeToStreamAsyncCore(Stream targetStream, bool async, C
using Utf8JsonWriter writer = new Utf8JsonWriter(targetStream);
JsonSerializer.Serialize(writer, Value, ObjectType, _jsonSerializerOptions);
#else
throw new NotSupportedException(SR.SyncNotSupported);
Debug.Assert(async);
#endif
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Net.Http.Headers;
using System.Net.Test.Common;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
Expand Down Expand Up @@ -83,7 +84,7 @@ await LoopbackServer.CreateClientAndServerAsync(
var request = new HttpRequestMessage(HttpMethod.Post, uri);
request.Content = content;
await client.SendAsync(request);
await SendAsync(client, request);
}
},
async server => {
Expand Down Expand Up @@ -115,7 +116,7 @@ await LoopbackServer.CreateClientAndServerAsync(
var request = new HttpRequestMessage(HttpMethod.Post, uri);
MediaTypeHeaderValue mediaType = MediaTypeHeaderValue.Parse("foo/bar; charset=utf-8");
request.Content = JsonContent.Create(Person.Create(), mediaType: mediaType);
await client.SendAsync(request);
await SendAsync(client, request);
}
},
async server => {
Expand Down Expand Up @@ -162,7 +163,7 @@ public void JsonContentThrowsOnIncompatibleTypeAsync()
}

[Fact]
public static async Task ValidateUtf16IsTranscodedAsync()
public async Task ValidateUtf16IsTranscodedAsync()
{
await LoopbackServer.CreateClientAndServerAsync(
async uri =>
Expand All @@ -173,7 +174,7 @@ await LoopbackServer.CreateClientAndServerAsync(
MediaTypeHeaderValue mediaType = MediaTypeHeaderValue.Parse("application/json; charset=utf-16");
// Pass new options to avoid using the Default Web Options that use camelCase.
request.Content = JsonContent.Create(Person.Create(), mediaType: mediaType, options: new JsonSerializerOptions());
await client.SendAsync(request);
await SendAsync(client, request);
}
},
async server => {
Expand All @@ -196,7 +197,7 @@ await LoopbackServer.CreateClientAndServerAsync(
EnsureDefaultOptions dummyObj = new EnsureDefaultOptions();
var request = new HttpRequestMessage(HttpMethod.Post, uri);
request.Content = JsonContent.Create(dummyObj);
await client.SendAsync(request);
await SendAsync(client, request);
}
},
server => server.HandleRequestAsync());
Expand All @@ -216,7 +217,7 @@ await LoopbackServer.CreateClientAndServerAsync(
content.Headers.ContentType = null;
request.Content = content;
await client.SendAsync(request);
await SendAsync(client, request);
}
},
async server => {
Expand Down

0 comments on commit 6e90249

Please sign in to comment.