mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-26 10:44:50 +03:00
Add number to bool json converter
(cherry picked from commit 0aad17554c)
Signed-off-by: Joshua M. Boniface <joshua@boniface.me>
23 lines
711 B
C#
23 lines
711 B
C#
using System.Text.Json;
|
|
using MediaBrowser.Common.Json.Converters;
|
|
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();
|
|
options.Converters.Add(new JsonBoolNumberConverter());
|
|
var value = JsonSerializer.Deserialize<bool>(input, options);
|
|
Assert.Equal(value, output);
|
|
}
|
|
}
|
|
} |