dbeec2e9f0
Refactor test code in Jellyfin.Extensions.Tests for clarity and consistency: - Use explicit object initializers and collection expressions - Standardize field naming and use of this. - Add/improve XML doc comments for test methods - Use new(...) syntax for Guid/Version instantiation - Convert file-scoped to block-scoped namespaces in key tests - Nest test classes and use instance methods in enum tests - Enable XML docs and suppress select warnings in csproj - No changes to test or converter logic; style and maintainability only
73 lines
2.4 KiB
C#
73 lines
2.4 KiB
C#
// <copyright file="JsonGuidConverterTests.cs" company="PlaceholderCompany">
|
|
// Copyright (c) PlaceholderCompany. All rights reserved.
|
|
// </copyright>
|
|
|
|
namespace Jellyfin.Extensions.Tests.Json.Converters
|
|
{
|
|
using System;
|
|
using System.Text.Json;
|
|
using Jellyfin.Extensions.Json.Converters;
|
|
using Xunit;
|
|
|
|
public class JsonGuidConverterTests
|
|
{
|
|
private readonly JsonSerializerOptions _options;
|
|
|
|
public JsonGuidConverterTests()
|
|
{
|
|
this._options = new JsonSerializerOptions();
|
|
this._options.Converters.Add(new JsonGuidConverter());
|
|
}
|
|
|
|
[Fact]
|
|
public void Deserialize_Valid_Success()
|
|
{
|
|
Guid value = JsonSerializer.Deserialize<Guid>(@"""a852a27afe324084ae66db579ee3ee18""", this._options);
|
|
Assert.Equal(new("a852a27afe324084ae66db579ee3ee18"), value);
|
|
}
|
|
|
|
[Fact]
|
|
public void Deserialize_ValidDashed_Success()
|
|
{
|
|
Guid value = JsonSerializer.Deserialize<Guid>(@"""e9b2dcaa-529c-426e-9433-5e9981f27f2e""", this._options);
|
|
Assert.Equal(new("e9b2dcaa-529c-426e-9433-5e9981f27f2e"), value);
|
|
}
|
|
|
|
[Fact]
|
|
public void Roundtrip_Valid_Success()
|
|
{
|
|
Guid guid = new("a852a27afe324084ae66db579ee3ee18");
|
|
string value = JsonSerializer.Serialize(guid, this._options);
|
|
Assert.Equal(guid, JsonSerializer.Deserialize<Guid>(value, this._options));
|
|
}
|
|
|
|
[Fact]
|
|
public void Deserialize_Null_EmptyGuid()
|
|
{
|
|
Assert.Equal(Guid.Empty, JsonSerializer.Deserialize<Guid>("null", this._options));
|
|
}
|
|
|
|
[Fact]
|
|
public void Serialize_EmptyGuid_EmptyGuid()
|
|
{
|
|
Assert.Equal($"\"{Guid.Empty:N}\"", JsonSerializer.Serialize(Guid.Empty, this._options));
|
|
}
|
|
|
|
[Fact]
|
|
public void Serialize_Valid_NoDash_Success()
|
|
{
|
|
Guid guid = new("531797E9-9457-40E0-88BC-B1D6D38752FA");
|
|
string str = JsonSerializer.Serialize(guid, this._options);
|
|
Assert.Equal($"\"{guid:N}\"", str);
|
|
}
|
|
|
|
[Fact]
|
|
public void Serialize_Nullable_Success()
|
|
{
|
|
Guid? guid = new Guid("531797E9-9457-40E0-88BC-B1D6D38752FA");
|
|
string str = JsonSerializer.Serialize(guid, this._options);
|
|
Assert.Equal($"\"{guid:N}\"", str);
|
|
}
|
|
}
|
|
}
|