A:初版
This commit is contained in:
1 parent
237cbd8788
commit
ab3721912d
102 files changed
+7929
-20
No files matched your search
@@ -0,0 +1,25 @@
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NetClient.Abstractions;
|
||||
|
||||
namespace NetClient.Test.TestDoubles;
|
||||
|
||||
public sealed class TestJsonSerializer : IHttpContentSerializer
|
||||
{
|
||||
private readonly JsonSerializerOptions _options;
|
||||
|
||||
public TestJsonSerializer(JsonSerializerOptions? options = null)
|
||||
{
|
||||
_options = options ?? new JsonSerializerOptions(JsonSerializerDefaults.Web);
|
||||
}
|
||||
|
||||
public string ContentType => "application/json";
|
||||
|
||||
public Task SerializeAsync<T>(Stream stream, T? value, CancellationToken cancellationToken = default)
|
||||
=> JsonSerializer.SerializeAsync(stream, value, _options, cancellationToken);
|
||||
|
||||
public Task<T?> DeserializeAsync<T>(Stream stream, CancellationToken cancellationToken = default)
|
||||
=> JsonSerializer.DeserializeAsync<T>(stream, _options, cancellationToken).AsTask();
|
||||
}
|
||||
Reference in new issue
Block a user