fix: Fixes JSON TypeConverter so that it can deserialize full name types (#1466)
This commit is contained in:
parent
52ca1fe686
commit
976680699c
4 changed files with 65 additions and 24 deletions
|
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using System.Text.Json;
|
||||
|
||||
using Server.Json;
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests;
|
||||
|
||||
public class TypeConverterTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
[Fact]
|
||||
public void TestReadAfterWrite()
|
||||
{
|
||||
// Arrange
|
||||
Type itemType = typeof(Item);
|
||||
|
||||
JsonSerializerOptions options = new JsonSerializerOptions();
|
||||
|
||||
TypeConverter converter = new TypeConverter();
|
||||
var bufferWriter = new ArrayBufferWriter<byte>();
|
||||
using var jsonWriter = new Utf8JsonWriter(bufferWriter);
|
||||
converter.Write(jsonWriter, itemType, options);
|
||||
|
||||
// Act
|
||||
jsonWriter.Flush();
|
||||
var jsonData = bufferWriter.WrittenSpan;
|
||||
|
||||
Utf8JsonReader jsonReader = new Utf8JsonReader(jsonData);
|
||||
jsonReader.Read();
|
||||
|
||||
// Assert
|
||||
Type readType = converter.Read(ref jsonReader, typeof(Type), options);
|
||||
Assert.Equal(typeof(Item), readType);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue