diff options
| author | Bond-009 <bond.009@outlook.com> | 2021-03-20 00:48:41 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-20 00:48:41 +0100 |
| commit | 1a0ce16f4d18b9a7850b52b299b4e6da15d40c53 (patch) | |
| tree | e1ffeef3bd01f07e2b70e6e6b30f6e10175c243d /tests/Jellyfin.Common.Tests | |
| parent | 9360fecb316973181a120027f70b311b219740cd (diff) | |
| parent | 37b1b31a46e818cb5d229ebf11d7db7895c3b964 (diff) | |
Merge pull request #5504 from crobibero/json-string-converter
Diffstat (limited to 'tests/Jellyfin.Common.Tests')
| -rw-r--r-- | tests/Jellyfin.Common.Tests/Json/JsonStringConverterTests.cs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/Jellyfin.Common.Tests/Json/JsonStringConverterTests.cs b/tests/Jellyfin.Common.Tests/Json/JsonStringConverterTests.cs new file mode 100644 index 000000000..fd77694b3 --- /dev/null +++ b/tests/Jellyfin.Common.Tests/Json/JsonStringConverterTests.cs @@ -0,0 +1,39 @@ +using System.Text.Json; +using MediaBrowser.Common.Json.Converters; +using Xunit; + +namespace Jellyfin.Common.Tests.Json +{ + public class JsonStringConverterTests + { + private readonly JsonSerializerOptions _jsonSerializerOptions + = new () + { + Converters = + { + new JsonStringConverter() + } + }; + + [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); + } + } +}
\ No newline at end of file |
