jellyfin/tests/Jellyfin.Common.Tests/Json/JsonBoolNumberTests.cs

46 lines
1.3 KiB
C#
Raw Normal View History

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