You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.3 KiB
45 lines
1.3 KiB
3 years ago
|
using System.Text.Json;
|
||
|
using FsCheck;
|
||
|
using FsCheck.Xunit;
|
||
3 years ago
|
using Jellyfin.Extensions.Json.Converters;
|
||
4 years ago
|
using Xunit;
|
||
|
|
||
3 years ago
|
namespace Jellyfin.Extensions.Tests.Json.Converters
|
||
4 years ago
|
{
|
||
3 years ago
|
public class JsonBoolNumberTests
|
||
4 years ago
|
{
|
||
3 years ago
|
private readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions()
|
||
|
{
|
||
|
Converters =
|
||
|
{
|
||
|
new JsonBoolNumberConverter()
|
||
|
}
|
||
|
};
|
||
|
|
||
4 years ago
|
[Theory]
|
||
|
[InlineData("1", true)]
|
||
|
[InlineData("0", false)]
|
||
|
[InlineData("2", true)]
|
||
|
[InlineData("true", true)]
|
||
|
[InlineData("false", false)]
|
||
3 years ago
|
public void Deserialize_Number_Valid_Success(string input, bool? output)
|
||
4 years ago
|
{
|
||
3 years ago
|
var value = JsonSerializer.Deserialize<bool>(input, _jsonOptions);
|
||
4 years ago
|
Assert.Equal(value, output);
|
||
4 years ago
|
}
|
||
4 years ago
|
|
||
|
[Theory]
|
||
|
[InlineData(true, "true")]
|
||
|
[InlineData(false, "false")]
|
||
3 years ago
|
public void Serialize_Bool_Success(bool input, string output)
|
||
4 years ago
|
{
|
||
3 years ago
|
var value = JsonSerializer.Serialize(input, _jsonOptions);
|
||
4 years ago
|
Assert.Equal(value, output);
|
||
|
}
|
||
3 years ago
|
|
||
|
[Property]
|
||
|
public Property Deserialize_NonZeroInt_True(NonZeroInt input)
|
||
|
=> JsonSerializer.Deserialize<bool>(input.ToString(), _jsonOptions).ToProperty();
|
||
4 years ago
|
}
|
||
3 years ago
|
}
|