Files
wjones dbeec2e9f0 Refactor and modernize JSON converter test code
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
2026-02-22 10:31:23 -05:00

70 lines
2.2 KiB
C#

// <copyright file="JsonBoolNumberTests.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
namespace Jellyfin.Extensions.Tests.Json.Converters
{
using System.Text.Json;
using FsCheck;
using FsCheck.Fluent;
using FsCheck.Xunit;
using Jellyfin.Extensions.Json.Converters;
using Xunit;
/// <summary>
/// Tests for the JsonBoolNumberConverter.
/// </summary>
public class JsonBoolNumberTests
{
private readonly JsonSerializerOptions _jsonOptions = new()
{
Converters =
{
new JsonBoolNumberConverter(),
},
};
/// <summary>
/// Tests deserialization of numbers to boolean.
/// </summary>
/// <param name="input">The input string.</param>
/// <param name="output">The expected output.</param>
[Theory]
[InlineData("1", true)]
[InlineData("0", false)]
[InlineData("2", true)]
[InlineData("true", true)]
[InlineData("false", false)]
public void Deserialize_Number_Valid_Success(string input, bool? output)
{
bool value = JsonSerializer.Deserialize<bool>(input, this._jsonOptions);
Assert.Equal(value, output);
}
/// <summary>
/// Tests serialization of boolean values.
/// </summary>
/// <param name="input">The input boolean.</param>
/// <param name="output">The expected output.</param>
[Theory]
[InlineData(true, "true")]
[InlineData(false, "false")]
public void Serialize_Bool_Success(bool input, string output)
{
string value = JsonSerializer.Serialize(input, this._jsonOptions);
Assert.Equal(value, output);
}
/// <summary>
/// Property test that non-zero integers deserialize to true.
/// </summary>
/// <param name="input">The input non-zero integer.</param>
/// <returns>A property test result.</returns>
[Property]
public Property Deserialize_NonZeroInt_True(NonZeroInt input)
{
return JsonSerializer.Deserialize<bool>(input.ToString(), this._jsonOptions).ToProperty();
}
}
}