mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-04-24 05:57:20 -04:00
Add more tests for JsonGuidConverter
This commit is contained in:
parent
1cd3b3fc41
commit
10be618ec3
1 changed files with 34 additions and 14 deletions
|
@ -5,28 +5,48 @@ using Xunit;
|
|||
|
||||
namespace Jellyfin.Common.Tests.Extensions
|
||||
{
|
||||
public static class JsonGuidConverterTests
|
||||
public class JsonGuidConverterTests
|
||||
{
|
||||
[Fact]
|
||||
public static void Deserialize_Valid_Success()
|
||||
{
|
||||
var options = new JsonSerializerOptions();
|
||||
options.Converters.Add(new JsonGuidConverter());
|
||||
Guid value = JsonSerializer.Deserialize<Guid>(@"""a852a27afe324084ae66db579ee3ee18""", options);
|
||||
Assert.Equal(new Guid("a852a27afe324084ae66db579ee3ee18"), value);
|
||||
private readonly JsonSerializerOptions _options;
|
||||
|
||||
value = JsonSerializer.Deserialize<Guid>(@"""e9b2dcaa-529c-426e-9433-5e9981f27f2e""", 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 static void Roundtrip_Valid_Success()
|
||||
public void Roundtrip_Valid_Success()
|
||||
{
|
||||
var options = new JsonSerializerOptions();
|
||||
options.Converters.Add(new JsonGuidConverter());
|
||||
Guid guid = new Guid("a852a27afe324084ae66db579ee3ee18");
|
||||
string value = JsonSerializer.Serialize(guid, options);
|
||||
Assert.Equal(guid, JsonSerializer.Deserialize<Guid>(value, options));
|
||||
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_Null()
|
||||
{
|
||||
Assert.Equal("null", JsonSerializer.Serialize(Guid.Empty, _options));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue