mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-04-24 22:17:25 -04:00
Don't serialize empty GUID to null
(cherry picked from commit b6ecaccf92
)
Signed-off-by: Joshua M. Boniface <joshua@boniface.me>
52 lines
1.6 KiB
C#
52 lines
1.6 KiB
C#
using System;
|
|
using System.Text.Json;
|
|
using MediaBrowser.Common.Json.Converters;
|
|
using Xunit;
|
|
|
|
namespace Jellyfin.Common.Tests.Json
|
|
{
|
|
public class JsonGuidConverterTests
|
|
{
|
|
private readonly JsonSerializerOptions _options;
|
|
|
|
public JsonGuidConverterTests()
|
|
{
|
|
_options = new JsonSerializerOptions();
|
|
_options.Converters.Add(new JsonGuidConverter());
|
|
}
|
|
|
|
[Fact]
|
|
public void Deserialize_Valid_Success()
|
|
{
|
|
Guid value = JsonSerializer.Deserialize<Guid>(@"""a852a27afe324084ae66db579ee3ee18""", _options);
|
|
Assert.Equal(new Guid("a852a27afe324084ae66db579ee3ee18"), value);
|
|
}
|
|
|
|
[Fact]
|
|
public void Deserialize_ValidDashed_Success()
|
|
{
|
|
Guid value = JsonSerializer.Deserialize<Guid>(@"""e9b2dcaa-529c-426e-9433-5e9981f27f2e""", _options);
|
|
Assert.Equal(new Guid("e9b2dcaa-529c-426e-9433-5e9981f27f2e"), value);
|
|
}
|
|
|
|
[Fact]
|
|
public void Roundtrip_Valid_Success()
|
|
{
|
|
Guid guid = new Guid("a852a27afe324084ae66db579ee3ee18");
|
|
string value = JsonSerializer.Serialize(guid, _options);
|
|
Assert.Equal(guid, JsonSerializer.Deserialize<Guid>(value, _options));
|
|
}
|
|
|
|
[Fact]
|
|
public void Deserialize_Null_EmptyGuid()
|
|
{
|
|
Assert.Equal(Guid.Empty, JsonSerializer.Deserialize<Guid>("null", _options));
|
|
}
|
|
|
|
[Fact]
|
|
public void Serialize_EmptyGuid_EmptyGuid()
|
|
{
|
|
Assert.Equal($"\"{Guid.Empty}\"", JsonSerializer.Serialize(Guid.Empty, _options));
|
|
}
|
|
}
|
|
}
|