diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/Jellyfin.Common.Tests/Json/JsonBoolNumberTests.cs | 23 | ||||
| -rw-r--r-- | tests/Jellyfin.Common.Tests/Models/BoolTypeModel.cs | 17 |
2 files changed, 40 insertions, 0 deletions
diff --git a/tests/Jellyfin.Common.Tests/Json/JsonBoolNumberTests.cs b/tests/Jellyfin.Common.Tests/Json/JsonBoolNumberTests.cs new file mode 100644 index 000000000..1cae5b849 --- /dev/null +++ b/tests/Jellyfin.Common.Tests/Json/JsonBoolNumberTests.cs @@ -0,0 +1,23 @@ +using System.Text.Json; +using Jellyfin.Common.Tests.Models; +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 inputJson = $"{{ \"Value\": {input} }}"; + var options = new JsonSerializerOptions(); + var value = JsonSerializer.Deserialize<BoolTypeModel>(inputJson, options); + Assert.Equal(value?.Value, output); + } + } +}
\ No newline at end of file diff --git a/tests/Jellyfin.Common.Tests/Models/BoolTypeModel.cs b/tests/Jellyfin.Common.Tests/Models/BoolTypeModel.cs new file mode 100644 index 000000000..feb952efc --- /dev/null +++ b/tests/Jellyfin.Common.Tests/Models/BoolTypeModel.cs @@ -0,0 +1,17 @@ +using System.Text.Json.Serialization; +using MediaBrowser.Common.Json.Converters; + +namespace Jellyfin.Common.Tests.Models +{ + /// <summary> + /// The bool type model. + /// </summary> + public class BoolTypeModel + { + /// <summary> + /// Gets or sets a value indicating whether the value is true or false. + /// </summary> + [JsonConverter(typeof(JsonBoolNumberConverter))] + public bool Value { get; set; } + } +}
\ No newline at end of file |
