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.
39 lines
1.1 KiB
39 lines
1.1 KiB
3 years ago
|
using System.Text.Json;
|
||
|
using Jellyfin.Extensions.Json.Converters;
|
||
4 years ago
|
using Xunit;
|
||
|
|
||
3 years ago
|
namespace Jellyfin.Extensions.Tests.Json.Converters
|
||
4 years ago
|
{
|
||
|
public class JsonStringConverterTests
|
||
|
{
|
||
3 years ago
|
private readonly JsonSerializerOptions _jsonSerializerOptions = new ()
|
||
|
{
|
||
|
Converters =
|
||
4 years ago
|
{
|
||
3 years ago
|
new JsonStringConverter()
|
||
|
}
|
||
|
};
|
||
4 years ago
|
|
||
|
[Theory]
|
||
|
[InlineData("\"test\"", "test")]
|
||
|
[InlineData("123", "123")]
|
||
|
[InlineData("123.45", "123.45")]
|
||
|
[InlineData("true", "true")]
|
||
|
[InlineData("false", "false")]
|
||
|
public void Deserialize_String_Valid_Success(string input, string output)
|
||
|
{
|
||
|
var deserialized = JsonSerializer.Deserialize<string>(input, _jsonSerializerOptions);
|
||
|
Assert.Equal(deserialized, output);
|
||
|
}
|
||
|
|
||
|
[Fact]
|
||
|
public void Deserialize_Int32asInt32_Valid_Success()
|
||
|
{
|
||
|
const string? input = "123";
|
||
|
const int output = 123;
|
||
|
var deserialized = JsonSerializer.Deserialize<int>(input, _jsonSerializerOptions);
|
||
|
Assert.Equal(deserialized, output);
|
||
|
}
|
||
|
}
|
||
3 years ago
|
}
|