fix: Fixes JSON TypeConverter so that it can deserialize full name types (#1466)

This commit is contained in:
mdodkins 2023-08-22 05:25:09 +01:00 committed by GitHub
parent 52ca1fe686
commit 976680699c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 65 additions and 24 deletions

View file

@ -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);
}
}