2020-12-07 03:26:21 +00:00
|
|
|
|
using System.Text.Json;
|
2020-12-07 21:58:27 +00:00
|
|
|
|
using MediaBrowser.Common.Json.Converters;
|
2020-12-07 03:26:21 +00:00
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace Jellyfin.Common.Tests.Json
|
|
|
|
|
{
|
|
|
|
|
public static class JsonBoolNumberTests
|
|
|
|
|
{
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("1", true)]
|
|
|
|
|
[InlineData("0", false)]
|
|
|
|
|
[InlineData("2", true)]
|
|
|
|
|
[InlineData("true", true)]
|
|
|
|
|
[InlineData("false", false)]
|
|
|
|
|
public static void Deserialize_Number_Valid_Success(string input, bool? output)
|
|
|
|
|
{
|
|
|
|
|
var options = new JsonSerializerOptions();
|
2020-12-07 21:58:27 +00:00
|
|
|
|
options.Converters.Add(new JsonBoolNumberConverter());
|
|
|
|
|
var value = JsonSerializer.Deserialize<bool>(input, options);
|
|
|
|
|
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")]
|
|
|
|
|
public static void Serialize_Bool_Success(bool input, string output)
|
|
|
|
|
{
|
|
|
|
|
var options = new JsonSerializerOptions();
|
|
|
|
|
options.Converters.Add(new JsonBoolNumberConverter());
|
|
|
|
|
var value = JsonSerializer.Serialize(input, options);
|
|
|
|
|
Assert.Equal(value, output);
|
|
|
|
|
}
|
2020-12-07 03:26:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|