You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.2 KiB
69 lines
2.2 KiB
4 years ago
|
using System;
|
||
|
using System.Text.Json;
|
||
3 years ago
|
using Jellyfin.Extensions.Json.Converters;
|
||
4 years ago
|
using Xunit;
|
||
|
|
||
3 years ago
|
namespace Jellyfin.Extensions.Tests.Json.Converters
|
||
4 years ago
|
{
|
||
4 years ago
|
public class JsonGuidConverterTests
|
||
4 years ago
|
{
|
||
4 years ago
|
private readonly JsonSerializerOptions _options;
|
||
|
|
||
|
public JsonGuidConverterTests()
|
||
|
{
|
||
|
_options = new JsonSerializerOptions();
|
||
|
_options.Converters.Add(new JsonGuidConverter());
|
||
|
}
|
||
|
|
||
4 years ago
|
[Fact]
|
||
4 years ago
|
public void Deserialize_Valid_Success()
|
||
4 years ago
|
{
|
||
4 years ago
|
Guid value = JsonSerializer.Deserialize<Guid>(@"""a852a27afe324084ae66db579ee3ee18""", _options);
|
||
4 years ago
|
Assert.Equal(new Guid("a852a27afe324084ae66db579ee3ee18"), value);
|
||
4 years ago
|
}
|
||
4 years ago
|
|
||
4 years ago
|
[Fact]
|
||
|
public void Deserialize_ValidDashed_Success()
|
||
|
{
|
||
|
Guid value = JsonSerializer.Deserialize<Guid>(@"""e9b2dcaa-529c-426e-9433-5e9981f27f2e""", _options);
|
||
4 years ago
|
Assert.Equal(new Guid("e9b2dcaa-529c-426e-9433-5e9981f27f2e"), value);
|
||
|
}
|
||
4 years ago
|
|
||
|
[Fact]
|
||
4 years ago
|
public void Roundtrip_Valid_Success()
|
||
4 years ago
|
{
|
||
|
Guid guid = new Guid("a852a27afe324084ae66db579ee3ee18");
|
||
4 years ago
|
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]
|
||
4 years ago
|
public void Serialize_EmptyGuid_EmptyGuid()
|
||
4 years ago
|
{
|
||
4 years ago
|
Assert.Equal($"\"{Guid.Empty:N}\"", JsonSerializer.Serialize(Guid.Empty, _options));
|
||
|
}
|
||
|
|
||
|
[Fact]
|
||
|
public void Serialize_Valid_NoDash_Success()
|
||
|
{
|
||
|
var guid = new Guid("531797E9-9457-40E0-88BC-B1D6D38752FA");
|
||
|
var str = JsonSerializer.Serialize(guid, _options);
|
||
|
Assert.Equal($"\"{guid:N}\"", str);
|
||
4 years ago
|
}
|
||
4 years ago
|
|
||
|
[Fact]
|
||
|
public void Serialize_Nullable_Success()
|
||
|
{
|
||
|
Guid? guid = new Guid("531797E9-9457-40E0-88BC-B1D6D38752FA");
|
||
|
var str = JsonSerializer.Serialize(guid, _options);
|
||
|
Assert.Equal($"\"{guid:N}\"", str);
|
||
|
}
|
||
4 years ago
|
}
|
||
|
}
|