2021-06-19 16:02:33 +00:00
|
|
|
using System.Globalization;
|
2021-06-05 11:32:22 +00:00
|
|
|
using System.Text.Json;
|
|
|
|
using FsCheck;
|
|
|
|
using FsCheck.Xunit;
|
2021-06-19 16:02:33 +00:00
|
|
|
using Jellyfin.Extensions.Json.Converters;
|
2020-12-07 03:26:21 +00:00
|
|
|
using Xunit;
|
|
|
|
|
2021-06-19 16:02:33 +00:00
|
|
|
namespace Jellyfin.Extensions.Tests.Json.Converters
|
2020-12-07 03:26:21 +00:00
|
|
|
{
|
2021-06-05 11:32:22 +00:00
|
|
|
public class JsonBoolNumberTests
|
2020-12-07 03:26:21 +00:00
|
|
|
{
|
2021-06-05 11:32:22 +00:00
|
|
|
private readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions()
|
|
|
|
{
|
|
|
|
Converters =
|
|
|
|
{
|
|
|
|
new JsonBoolNumberConverter()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-12-07 03:26:21 +00:00
|
|
|
[Theory]
|
|
|
|
[InlineData("1", true)]
|
|
|
|
[InlineData("0", false)]
|
|
|
|
[InlineData("2", true)]
|
|
|
|
[InlineData("true", true)]
|
|
|
|
[InlineData("false", false)]
|
2021-06-05 11:32:22 +00:00
|
|
|
public void Deserialize_Number_Valid_Success(string input, bool? output)
|
2020-12-07 03:26:21 +00:00
|
|
|
{
|
2021-06-05 11:32:22 +00:00
|
|
|
var value = JsonSerializer.Deserialize<bool>(input, _jsonOptions);
|
2020-12-07 21:58:27 +00:00
|
|
|
Assert.Equal(value, output);
|
2020-12-07 03:26:21 +00:00
|
|
|
}
|
2020-12-08 14:18:25 +00:00
|
|
|
|
|
|
|
[Theory]
|
|
|
|
[InlineData(true, "true")]
|
|
|
|
[InlineData(false, "false")]
|
2021-06-05 11:32:22 +00:00
|
|
|
public void Serialize_Bool_Success(bool input, string output)
|
2020-12-08 14:18:25 +00:00
|
|
|
{
|
2021-06-05 11:32:22 +00:00
|
|
|
var value = JsonSerializer.Serialize(input, _jsonOptions);
|
2020-12-08 14:18:25 +00:00
|
|
|
Assert.Equal(value, output);
|
|
|
|
}
|
2021-06-05 11:32:22 +00:00
|
|
|
|
|
|
|
[Property]
|
|
|
|
public Property Deserialize_NonZeroInt_True(NonZeroInt input)
|
|
|
|
=> JsonSerializer.Deserialize<bool>(input.ToString(), _jsonOptions).ToProperty();
|
2020-12-07 03:26:21 +00:00
|
|
|
}
|
2021-06-05 11:32:22 +00:00
|
|
|
}
|