using System.Text.Json; using System.Text.Json.Serialization; using Jellyfin.Extensions.Tests.Json.Models; using MediaBrowser.Model.Session; using Xunit; namespace Jellyfin.Extensions.Tests.Json.Converters { public class JsonCommaDelimitedIReadOnlyListTests { private readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions() { Converters = { new JsonStringEnumConverter() } }; [Fact] public void Deserialize_String_Valid_Success() { var desiredValue = new GenericBodyIReadOnlyListModel { Value = new[] { "a", "b", "c" } }; var value = JsonSerializer.Deserialize>(@"{ ""Value"": ""a,b,c"" }", _jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } [Fact] public void Deserialize_String_Space_Valid_Success() { var desiredValue = new GenericBodyIReadOnlyListModel { Value = new[] { "a", "b", "c" } }; var value = JsonSerializer.Deserialize>(@"{ ""Value"": ""a, b, c"" }", _jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } [Fact] public void Deserialize_GenericCommandType_Valid_Success() { var desiredValue = new GenericBodyIReadOnlyListModel { Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown } }; var value = JsonSerializer.Deserialize>(@"{ ""Value"": ""MoveUp,MoveDown"" }", _jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } [Fact] public void Deserialize_GenericCommandType_Space_Valid_Success() { var desiredValue = new GenericBodyIReadOnlyListModel { Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown } }; var value = JsonSerializer.Deserialize>(@"{ ""Value"": ""MoveUp, MoveDown"" }", _jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } [Fact] public void Deserialize_String_Array_Valid_Success() { var desiredValue = new GenericBodyIReadOnlyListModel { Value = new[] { "a", "b", "c" } }; var value = JsonSerializer.Deserialize>(@"{ ""Value"": [""a"",""b"",""c""] }", _jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } [Fact] public void Deserialize_GenericCommandType_Array_Valid_Success() { var desiredValue = new GenericBodyIReadOnlyListModel { Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown } }; var value = JsonSerializer.Deserialize>(@"{ ""Value"": [""MoveUp"", ""MoveDown""] }", _jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } } }