//
// Copyright (c) PlaceholderCompany. All rights reserved.
//
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;
///
/// Tests for the JsonBoolNumberConverter.
///
public class JsonBoolNumberTests
{
private readonly JsonSerializerOptions _jsonOptions = new()
{
Converters =
{
new JsonBoolNumberConverter(),
},
};
///
/// Tests deserialization of numbers to boolean.
///
/// The input string.
/// The expected output.
[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(input, this._jsonOptions);
Assert.Equal(value, output);
}
///
/// Tests serialization of boolean values.
///
/// The input boolean.
/// The expected output.
[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);
}
///
/// Property test that non-zero integers deserialize to true.
///
/// The input non-zero integer.
/// A property test result.
[Property]
public Property Deserialize_NonZeroInt_True(NonZeroInt input)
{
return JsonSerializer.Deserialize(input.ToString(), this._jsonOptions).ToProperty();
}
}
}