diff --git a/src/Jellyfin.CodeAnalysis/bin/Debug/netstandard2.0/Jellyfin.CodeAnalysis.dll b/src/Jellyfin.CodeAnalysis/bin/Debug/netstandard2.0/Jellyfin.CodeAnalysis.dll index 5f6f2076..144bd19b 100644 Binary files a/src/Jellyfin.CodeAnalysis/bin/Debug/netstandard2.0/Jellyfin.CodeAnalysis.dll and b/src/Jellyfin.CodeAnalysis/bin/Debug/netstandard2.0/Jellyfin.CodeAnalysis.dll differ diff --git a/src/Jellyfin.CodeAnalysis/bin/Debug/netstandard2.0/Jellyfin.CodeAnalysis.pdb b/src/Jellyfin.CodeAnalysis/bin/Debug/netstandard2.0/Jellyfin.CodeAnalysis.pdb index 3382da4f..1aa1db1c 100644 Binary files a/src/Jellyfin.CodeAnalysis/bin/Debug/netstandard2.0/Jellyfin.CodeAnalysis.pdb and b/src/Jellyfin.CodeAnalysis/bin/Debug/netstandard2.0/Jellyfin.CodeAnalysis.pdb differ diff --git a/src/Jellyfin.CodeAnalysis/obj/Debug/netstandard2.0/Jellyfin.CodeAnalysis.AssemblyInfo.cs b/src/Jellyfin.CodeAnalysis/obj/Debug/netstandard2.0/Jellyfin.CodeAnalysis.AssemblyInfo.cs index e7bcaae5..affd2ca4 100644 --- a/src/Jellyfin.CodeAnalysis/obj/Debug/netstandard2.0/Jellyfin.CodeAnalysis.AssemblyInfo.cs +++ b/src/Jellyfin.CodeAnalysis/obj/Debug/netstandard2.0/Jellyfin.CodeAnalysis.AssemblyInfo.cs @@ -14,7 +14,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("Jellyfin.CodeAnalysis")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+48569427a5cba735184e017148b7c71f665279bc")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+d5522c6fb3c7affc827cf2b509dadab833a237a4")] [assembly: System.Reflection.AssemblyProductAttribute("Jellyfin.CodeAnalysis")] [assembly: System.Reflection.AssemblyTitleAttribute("Jellyfin.CodeAnalysis")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/src/Jellyfin.CodeAnalysis/obj/Debug/netstandard2.0/Jellyfin.CodeAnalysis.AssemblyInfoInputs.cache b/src/Jellyfin.CodeAnalysis/obj/Debug/netstandard2.0/Jellyfin.CodeAnalysis.AssemblyInfoInputs.cache index fea0801d..36449d5b 100644 --- a/src/Jellyfin.CodeAnalysis/obj/Debug/netstandard2.0/Jellyfin.CodeAnalysis.AssemblyInfoInputs.cache +++ b/src/Jellyfin.CodeAnalysis/obj/Debug/netstandard2.0/Jellyfin.CodeAnalysis.AssemblyInfoInputs.cache @@ -1 +1 @@ -5afb18d45c1a1f35abd23adbc2ff716c2f51ec4673ea08b8765ec2e818a59a28 +9a6eadffef3683b1209238dc99619e9ba917f9a0f07b616fdd1f9e8cd1c88579 diff --git a/src/Jellyfin.CodeAnalysis/obj/Debug/netstandard2.0/Jellyfin.CodeAnalysis.dll b/src/Jellyfin.CodeAnalysis/obj/Debug/netstandard2.0/Jellyfin.CodeAnalysis.dll index 5f6f2076..144bd19b 100644 Binary files a/src/Jellyfin.CodeAnalysis/obj/Debug/netstandard2.0/Jellyfin.CodeAnalysis.dll and b/src/Jellyfin.CodeAnalysis/obj/Debug/netstandard2.0/Jellyfin.CodeAnalysis.dll differ diff --git a/src/Jellyfin.CodeAnalysis/obj/Debug/netstandard2.0/Jellyfin.CodeAnalysis.pdb b/src/Jellyfin.CodeAnalysis/obj/Debug/netstandard2.0/Jellyfin.CodeAnalysis.pdb index 3382da4f..1aa1db1c 100644 Binary files a/src/Jellyfin.CodeAnalysis/obj/Debug/netstandard2.0/Jellyfin.CodeAnalysis.pdb and b/src/Jellyfin.CodeAnalysis/obj/Debug/netstandard2.0/Jellyfin.CodeAnalysis.pdb differ diff --git a/tests/Jellyfin.Extensions.Tests/Jellyfin.Extensions.Tests.csproj b/tests/Jellyfin.Extensions.Tests/Jellyfin.Extensions.Tests.csproj index a1fa817d..f41cfe03 100644 --- a/tests/Jellyfin.Extensions.Tests/Jellyfin.Extensions.Tests.csproj +++ b/tests/Jellyfin.Extensions.Tests/Jellyfin.Extensions.Tests.csproj @@ -2,6 +2,8 @@ net11.0 + true + $(NoWarn);CS1591;CS1570;CS8600;SA1600;SA1309;SA1200 diff --git a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonBoolNumberTests.cs b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonBoolNumberTests.cs index 96520b28..ce9a2c84 100644 --- a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonBoolNumberTests.cs +++ b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonBoolNumberTests.cs @@ -62,6 +62,8 @@ namespace Jellyfin.Extensions.Tests.Json.Converters /// A property test result. [Property] public Property Deserialize_NonZeroInt_True(NonZeroInt input) - => JsonSerializer.Deserialize(input.ToString(), this._jsonOptions).ToProperty(); + { + return JsonSerializer.Deserialize(input.ToString(), this._jsonOptions).ToProperty(); + } } } diff --git a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonBoolStringTests.cs b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonBoolStringTests.cs index 94dff8e8..861f6459 100644 --- a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonBoolStringTests.cs +++ b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonBoolStringTests.cs @@ -23,7 +23,7 @@ namespace Jellyfin.Extensions.Tests.Json.Converters [InlineData(@"{ ""Value"": ""false"" }", false)] public void Deserialize_String_Valid_Success(string input, bool output) { - TestStruct s = JsonSerializer.Deserialize(input, _jsonOptions); + TestStruct s = JsonSerializer.Deserialize(input, this._jsonOptions); Assert.Equal(s.Value, output); } @@ -32,7 +32,7 @@ namespace Jellyfin.Extensions.Tests.Json.Converters [InlineData(false, "false")] public void Serialize_Bool_Success(bool input, string output) { - string value = JsonSerializer.Serialize(input, _jsonOptions); + string value = JsonSerializer.Serialize(input, this._jsonOptions); Assert.Equal(value, output); } diff --git a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedCollectionTests.cs b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedCollectionTests.cs index 72e6c7d8..c8a43402 100644 --- a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedCollectionTests.cs +++ b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedCollectionTests.cs @@ -7,16 +7,18 @@ namespace Jellyfin.Extensions.Tests.Json.Converters using System; using System.Collections.Generic; using System.Collections.Immutable; - using System.Linq; using System.Text.Json; using System.Text.Json.Serialization; using Jellyfin.Extensions.Tests.Json.Models; using MediaBrowser.Model.Session; using Xunit; + /// + /// Tests for JSON comma delimited collection converter. + /// public class JsonCommaDelimitedCollectionTests { - private readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions() + private readonly JsonSerializerOptions jsonOptions = new() { Converters = { @@ -24,203 +26,236 @@ namespace Jellyfin.Extensions.Tests.Json.Converters }, }; + /// + /// Tests that deserializing null string value succeeds. + /// [Fact] public void Deserialize_String_Null_Success() { - GenericBodyArrayModel>(@"{ ""Value"": null }", _jsonOptions); + GenericBodyArrayModel? value = JsonSerializer.Deserialize>(@"{ ""Value"": null }", this.jsonOptions); Assert.Null(value?.Value); } + /// + /// Tests that deserializing empty string succeeds. + /// [Fact] public void Deserialize_Empty_Success() { - GenericBodyArrayModel - { desiredValue = new GenericBodyArrayModel + GenericBodyArrayModel desiredValue = new() { - Value = Array.Empty(), + Value = [], }; - GenericBodyArrayModel>(@"{ ""Value"": """" }", _jsonOptions); + GenericBodyArrayModel? value = JsonSerializer.Deserialize>(@"{ ""Value"": """" }", this.jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } + /// + /// Tests that deserializing empty string to list throws exception. + /// [Fact] public void Deserialize_EmptyList_Success() { - GenericBodyListModel - { desiredValue = new GenericBodyListModel + GenericBodyListModel desiredValue = new() { Value = [], }; - Assert.Throws(() => JsonSerializer.Deserialize>(@"{ ""Value"": """" }", _jsonOptions)); + _ = Assert.Throws(() => JsonSerializer.Deserialize>(@"{ ""Value"": """" }", this.jsonOptions)); } + /// + /// Tests that deserializing empty string to IReadOnlyList succeeds. + /// [Fact] public void Deserialize_EmptyIReadOnlyList_Success() { - GenericBodyIReadOnlyListModel - { desiredValue = new GenericBodyIReadOnlyListModel + GenericBodyIReadOnlyListModel desiredValue = new() { Value = [], }; - GenericBodyIReadOnlyListModel>(@"{ ""Value"": """" }", _jsonOptions); + GenericBodyIReadOnlyListModel? value = JsonSerializer.Deserialize>(@"{ ""Value"": """" }", this.jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } + /// + /// Tests that deserializing comma-delimited string succeeds. + /// [Fact] public void Deserialize_String_Valid_Success() { - GenericBodyArrayModel - { desiredValue = new GenericBodyArrayModel + GenericBodyArrayModel desiredValue = new() { Value = ["a", "b", "c"], }; - GenericBodyArrayModel>(@"{ ""Value"": ""a,b,c"" }", _jsonOptions); + GenericBodyArrayModel? value = JsonSerializer.Deserialize>(@"{ ""Value"": ""a,b,c"" }", this.jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } + /// + /// Tests that deserializing comma-delimited string to list throws exception. + /// [Fact] public void Deserialize_StringList_Valid_Success() { - GenericBodyListModel - { desiredValue = new GenericBodyListModel + GenericBodyListModel desiredValue = new() { Value = ["a", "b", "c"], }; - Assert.Throws(() => JsonSerializer.Deserialize>(@"{ ""Value"": ""a,b,c"" }", _jsonOptions)); + _ = Assert.Throws(() => JsonSerializer.Deserialize>(@"{ ""Value"": ""a,b,c"" }", this.jsonOptions)); } + /// + /// Tests that deserializing comma-delimited string with spaces succeeds. + /// [Fact] public void Deserialize_String_Space_Valid_Success() { - GenericBodyArrayModel - { desiredValue = new GenericBodyArrayModel + GenericBodyArrayModel desiredValue = new() { Value = ["a", "b", "c"], }; - GenericBodyArrayModel>(@"{ ""Value"": ""a, b, c"" }", _jsonOptions); + GenericBodyArrayModel? value = JsonSerializer.Deserialize>(@"{ ""Value"": ""a, b, c"" }", this.jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } + /// + /// Tests that deserializing comma-delimited enum string succeeds. + /// [Fact] public void Deserialize_GenericCommandType_Valid_Success() { - GenericBodyArrayModel - { desiredValue = new GenericBodyArrayModel + GenericBodyArrayModel desiredValue = new() { Value = [GeneralCommandType.MoveUp, GeneralCommandType.MoveDown], }; - GenericBodyArrayModel>(@"{ ""Value"": ""MoveUp,MoveDown"" }", _jsonOptions); + GenericBodyArrayModel? value = JsonSerializer.Deserialize>(@"{ ""Value"": ""MoveUp,MoveDown"" }", this.jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } + /// + /// Tests that deserializing comma-delimited enum string with empty entry succeeds. + /// [Fact] public void Deserialize_GenericCommandType_EmptyEntry_Success() { - GenericBodyArrayModel - { desiredValue = new GenericBodyArrayModel + GenericBodyArrayModel desiredValue = new() { Value = [GeneralCommandType.MoveUp, GeneralCommandType.MoveDown], }; - GenericBodyArrayModel>(@"{ ""Value"": ""MoveUp,,MoveDown"" }", _jsonOptions); + GenericBodyArrayModel? value = JsonSerializer.Deserialize>(@"{ ""Value"": ""MoveUp,,MoveDown"" }", this.jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } + /// + /// Tests that deserializing comma-delimited enum string with invalid value succeeds. + /// [Fact] public void Deserialize_GenericCommandType_Invalid_Success() { - GenericBodyArrayModel - { desiredValue = new GenericBodyArrayModel + GenericBodyArrayModel desiredValue = new() { Value = [GeneralCommandType.MoveUp, GeneralCommandType.MoveDown], }; - GenericBodyArrayModel>(@"{ ""Value"": ""MoveUp,TotallyNotAValidCommand,MoveDown"" }", _jsonOptions); + GenericBodyArrayModel? value = JsonSerializer.Deserialize>(@"{ ""Value"": ""MoveUp,TotallyNotAValidCommand,MoveDown"" }", this.jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } + /// + /// Tests that deserializing comma-delimited enum string with spaces succeeds. + /// [Fact] public void Deserialize_GenericCommandType_Space_Valid_Success() { - GenericBodyArrayModel - { desiredValue = new GenericBodyArrayModel + GenericBodyArrayModel desiredValue = new() { Value = [GeneralCommandType.MoveUp, GeneralCommandType.MoveDown], }; - GenericBodyArrayModel>(@"{ ""Value"": ""MoveUp, MoveDown"" }", _jsonOptions); + GenericBodyArrayModel? value = JsonSerializer.Deserialize>(@"{ ""Value"": ""MoveUp, MoveDown"" }", this.jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } + /// + /// Tests that deserializing JSON array of strings succeeds. + /// [Fact] public void Deserialize_String_Array_Valid_Success() { - GenericBodyArrayModel - { desiredValue = new GenericBodyArrayModel + GenericBodyArrayModel desiredValue = new() { Value = ["a", "b", "c"], }; - GenericBodyArrayModel>(@"{ ""Value"": [""a"",""b"",""c""] }", _jsonOptions); + GenericBodyArrayModel? value = JsonSerializer.Deserialize>(@"{ ""Value"": [""a"",""b"",""c""] }", this.jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } + /// + /// Tests that deserializing JSON array of enums succeeds. + /// [Fact] public void Deserialize_GenericCommandType_Array_Valid_Success() { - GenericBodyArrayModel - { desiredValue = new GenericBodyArrayModel + GenericBodyArrayModel desiredValue = new() { Value = [GeneralCommandType.MoveUp, GeneralCommandType.MoveDown], }; - GenericBodyArrayModel>(@"{ ""Value"": [""MoveUp"", ""MoveDown""] }", _jsonOptions); + GenericBodyArrayModel? value = JsonSerializer.Deserialize>(@"{ ""Value"": [""MoveUp"", ""MoveDown""] }", this.jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } + /// + /// Tests that serializing readonly collection succeeds. + /// [Fact] public void Serialize_GenericCommandType_ReadOnlyArray_Valid_Success() { - GenericBodyIReadOnlyCollectionModel - { valueToSerialize = new GenericBodyIReadOnlyCollectionModel + GenericBodyIReadOnlyCollectionModel valueToSerialize = new() { Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown }.AsReadOnly(), }; - string value = JsonSerializer.Serialize>(valueToSerialize, _jsonOptions); + string value = JsonSerializer.Serialize>(valueToSerialize, this.jsonOptions); Assert.Equal(@"{""Value"":[""MoveUp"",""MoveDown""]}", value); } + /// + /// Tests that serializing immutable array succeeds. + /// [Fact] public void Serialize_GenericCommandType_ImmutableArrayArray_Valid_Success() { - GenericBodyIReadOnlyCollectionModel - { valueToSerialize = new GenericBodyIReadOnlyCollectionModel + GenericBodyIReadOnlyCollectionModel valueToSerialize = new() { - Value = ImmutableArray.Create(new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown }), + Value = ImmutableArray.Create([GeneralCommandType.MoveUp, GeneralCommandType.MoveDown]), }; - string value = JsonSerializer.Serialize>(valueToSerialize, _jsonOptions); + string value = JsonSerializer.Serialize>(valueToSerialize, this.jsonOptions); Assert.Equal(@"{""Value"":[""MoveUp"",""MoveDown""]}", value); } + /// + /// Tests that serializing list succeeds. + /// [Fact] public void Serialize_GenericCommandType_List_Valid_Success() { - GenericBodyIReadOnlyListModel - { valueToSerialize = new GenericBodyIReadOnlyListModel + GenericBodyIReadOnlyListModel valueToSerialize = new() { - Value = new List { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown }, + Value = [GeneralCommandType.MoveUp, GeneralCommandType.MoveDown], }; - string value = JsonSerializer.Serialize>(valueToSerialize, _jsonOptions); + string value = JsonSerializer.Serialize>(valueToSerialize, this.jsonOptions); Assert.Equal(@"{""Value"":[""MoveUp"",""MoveDown""]}", value); } } diff --git a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedIReadOnlyListTests.cs b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedIReadOnlyListTests.cs index 2927977b..6e32f867 100644 --- a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedIReadOnlyListTests.cs +++ b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedIReadOnlyListTests.cs @@ -4,16 +4,18 @@ namespace Jellyfin.Extensions.Tests.Json.Converters { - using System.Collections.Generic; using System.Text.Json; using System.Text.Json.Serialization; using Jellyfin.Extensions.Tests.Json.Models; using MediaBrowser.Model.Session; using Xunit; + /// + /// Tests for JSON comma delimited IReadOnlyList converter. + /// public class JsonCommaDelimitedIReadOnlyListTests { - private readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions() + private readonly JsonSerializerOptions jsonOptions = new() { Converters = { @@ -21,94 +23,108 @@ namespace Jellyfin.Extensions.Tests.Json.Converters }, }; + /// + /// Tests that deserializing comma-delimited string succeeds. + /// [Fact] public void Deserialize_String_Valid_Success() { - GenericBodyIReadOnlyListModel - { desiredValue = new GenericBodyIReadOnlyListModel + GenericBodyIReadOnlyListModel desiredValue = new() { - Value = new[] { "a", "b", "c" }, + Value = ["a", "b", "c"], }; - GenericBodyIReadOnlyListModel>(@"{ ""Value"": ""a,b,c"" }", _jsonOptions); + GenericBodyIReadOnlyListModel? value = JsonSerializer.Deserialize>(@"{ ""Value"": ""a,b,c"" }", this.jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } + /// + /// Tests that deserializing comma-delimited string with spaces succeeds. + /// [Fact] public void Deserialize_String_Space_Valid_Success() { - GenericBodyIReadOnlyListModel - { desiredValue = new GenericBodyIReadOnlyListModel + GenericBodyIReadOnlyListModel desiredValue = new() { - Value = new[] { "a", "b", "c" }, + Value = ["a", "b", "c"], }; - GenericBodyIReadOnlyListModel>(@"{ ""Value"": ""a, b, c"" }", _jsonOptions); + GenericBodyIReadOnlyListModel? value = JsonSerializer.Deserialize>(@"{ ""Value"": ""a, b, c"" }", this.jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } + /// + /// Tests that deserializing comma-delimited enum string succeeds. + /// [Fact] public void Deserialize_GenericCommandType_Valid_Success() { - GenericBodyIReadOnlyListModel - { desiredValue = new GenericBodyIReadOnlyListModel + GenericBodyIReadOnlyListModel desiredValue = new() { - Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown }, + Value = [GeneralCommandType.MoveUp, GeneralCommandType.MoveDown], }; - GenericBodyIReadOnlyListModel>(@"{ ""Value"": ""MoveUp,MoveDown"" }", _jsonOptions); + GenericBodyIReadOnlyListModel? value = JsonSerializer.Deserialize>(@"{ ""Value"": ""MoveUp,MoveDown"" }", this.jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } + /// + /// Tests that deserializing comma-delimited enum string with spaces succeeds. + /// [Fact] public void Deserialize_GenericCommandType_Space_Valid_Success() { - GenericBodyIReadOnlyListModel - { desiredValue = new GenericBodyIReadOnlyListModel + GenericBodyIReadOnlyListModel desiredValue = new() { - Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown }, + Value = [GeneralCommandType.MoveUp, GeneralCommandType.MoveDown], }; - GenericBodyIReadOnlyListModel>(@"{ ""Value"": ""MoveUp, MoveDown"" }", _jsonOptions); + GenericBodyIReadOnlyListModel? value = JsonSerializer.Deserialize>(@"{ ""Value"": ""MoveUp, MoveDown"" }", this.jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } + /// + /// Tests that deserializing JSON array of strings succeeds. + /// [Fact] public void Deserialize_String_Array_Valid_Success() { - GenericBodyIReadOnlyListModel - { desiredValue = new GenericBodyIReadOnlyListModel + GenericBodyIReadOnlyListModel desiredValue = new() { - Value = new[] { "a", "b", "c" }, + Value = ["a", "b", "c"], }; - GenericBodyIReadOnlyListModel>(@"{ ""Value"": [""a"",""b"",""c""] }", _jsonOptions); + GenericBodyIReadOnlyListModel? value = JsonSerializer.Deserialize>(@"{ ""Value"": [""a"",""b"",""c""] }", this.jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } + /// + /// Tests that deserializing JSON array of enums succeeds. + /// [Fact] public void Deserialize_GenericCommandType_Array_Valid_Success() { - GenericBodyIReadOnlyListModel - { desiredValue = new GenericBodyIReadOnlyListModel + GenericBodyIReadOnlyListModel desiredValue = new() { - Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown }, + Value = [GeneralCommandType.MoveUp, GeneralCommandType.MoveDown], }; - GenericBodyIReadOnlyListModel>(@"{ ""Value"": [""MoveUp"", ""MoveDown""] }", _jsonOptions); + GenericBodyIReadOnlyListModel? value = JsonSerializer.Deserialize>(@"{ ""Value"": [""MoveUp"", ""MoveDown""] }", this.jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } + /// + /// Tests that serializing IReadOnlyList succeeds. + /// [Fact] public void Serialize_GenericCommandType_IReadOnlyList_Valid_Success() { - GenericBodyIReadOnlyListModel - { valueToSerialize = new GenericBodyIReadOnlyListModel + GenericBodyIReadOnlyListModel valueToSerialize = new() { - Value = new List { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown }, + Value = [GeneralCommandType.MoveUp, GeneralCommandType.MoveDown], }; - string value = JsonSerializer.Serialize>(valueToSerialize, _jsonOptions); + string value = JsonSerializer.Serialize>(valueToSerialize, this.jsonOptions); Assert.Equal(@"{""Value"":[""MoveUp"",""MoveDown""]}", value); } } diff --git a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonDefaultStringEnumConverterTests.cs b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonDefaultStringEnumConverterTests.cs index dacbf126..140a6e2f 100644 --- a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonDefaultStringEnumConverterTests.cs +++ b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonDefaultStringEnumConverterTests.cs @@ -2,115 +2,116 @@ // Copyright (c) PlaceholderCompany. All rights reserved. // -namespace Jellyfin.Extensions.Tests.Json.Converters; - -using System.Text.Json; -using Jellyfin.Data.Enums; -using Jellyfin.Extensions.Json.Converters; -using Xunit; - -public class JsonDefaultStringEnumConverterTests +namespace Jellyfin.Extensions.Tests.Json.Converters { - private readonly JsonSerializerOptions _jsonOptions = new() { Converters = { new JsonDefaultStringEnumConverterFactory() } }; + using System.Text.Json; + using Jellyfin.Data.Enums; + using Jellyfin.Extensions.Json.Converters; + using Xunit; - /// - /// Test to ensure that `null` and empty string are deserialized to the default value. - /// - /// The input string. - /// The expected enum value. - [Theory] - [InlineData("\"\"", MediaStreamProtocol.http)] - [InlineData("\"Http\"", MediaStreamProtocol.http)] - [InlineData("\"Hls\"", MediaStreamProtocol.hls)] - public void Deserialize_Enum_Direct(string input, MediaStreamProtocol output) + public class JsonDefaultStringEnumConverterTests { - MediaStreamProtocol value = JsonSerializer.Deserialize(input, _jsonOptions); - Assert.Equal(output, value); - } + private readonly JsonSerializerOptions _jsonOptions = new() { Converters = { new JsonDefaultStringEnumConverterFactory() } }; - /// - /// Test to ensure that `null` and empty string are deserialized to the default value. - /// - /// The input string. - /// The expected enum value. - [Theory] - [InlineData(null, MediaStreamProtocol.http)] - [InlineData("\"\"", MediaStreamProtocol.http)] - [InlineData("\"Http\"", MediaStreamProtocol.http)] - [InlineData("\"Hls\"", MediaStreamProtocol.hls)] - public void Deserialize_Enum(string? input, MediaStreamProtocol output) - { - input ??= "null"; - var json = $"{{ \"EnumValue\": {input} }}"; - TestClass value = JsonSerializer.Deserialize(json, _jsonOptions); - Assert.NotNull(value); - Assert.Equal(output, value.EnumValue); - } + /// + /// Test to ensure that `null` and empty string are deserialized to the default value. + /// + /// The input string. + /// The expected enum value. + [Theory] + [InlineData("\"\"", MediaStreamProtocol.http)] + [InlineData("\"Http\"", MediaStreamProtocol.http)] + [InlineData("\"Hls\"", MediaStreamProtocol.hls)] + public void Deserialize_Enum_Direct(string input, MediaStreamProtocol output) + { + MediaStreamProtocol value = JsonSerializer.Deserialize(input, this._jsonOptions); + Assert.Equal(output, value); + } - /// - /// Test to ensure that empty string is deserialized to the default value, - /// and `null` is deserialized to `null`. - /// - /// The input string. - /// The expected enum value. - [Theory] - [InlineData(null, null)] - [InlineData("\"\"", MediaStreamProtocol.http)] - [InlineData("\"Http\"", MediaStreamProtocol.http)] - [InlineData("\"Hls\"", MediaStreamProtocol.hls)] - public void Deserialize_Enum_Nullable(string? input, MediaStreamProtocol? output) - { - input ??= "null"; - var json = $"{{ \"EnumValue\": {input} }}"; - NullTestClass value = JsonSerializer.Deserialize(json, _jsonOptions); - Assert.NotNull(value); - Assert.Equal(output, value.EnumValue); - } + /// + /// Test to ensure that `null` and empty string are deserialized to the default value. + /// + /// The input string. + /// The expected enum value. + [Theory] + [InlineData(null, MediaStreamProtocol.http)] + [InlineData("\"\"", MediaStreamProtocol.http)] + [InlineData("\"Http\"", MediaStreamProtocol.http)] + [InlineData("\"Hls\"", MediaStreamProtocol.hls)] + public void Deserialize_Enum(string? input, MediaStreamProtocol output) + { + input ??= "null"; + string json = $"{{ \"EnumValue\": {input} }}"; + TestClass value = JsonSerializer.Deserialize(json, this._jsonOptions); + Assert.NotNull(value); + Assert.Equal(output, value.EnumValue); + } - /// - /// Ensures that the roundtrip serialization & deserialization is successful. - /// - /// Input enum. - /// Output enum. - [Theory] - [InlineData(MediaStreamProtocol.http, MediaStreamProtocol.http)] - [InlineData(MediaStreamProtocol.hls, MediaStreamProtocol.hls)] - public void Enum_RoundTrip(MediaStreamProtocol input, MediaStreamProtocol output) - { - var inputObj = new TestClass { EnumValue = input }; + /// + /// Test to ensure that empty string is deserialized to the default value, + /// and `null` is deserialized to `null`. + /// + /// The input string. + /// The expected enum value. + [Theory] + [InlineData(null, null)] + [InlineData("\"\"", MediaStreamProtocol.http)] + [InlineData("\"Http\"", MediaStreamProtocol.http)] + [InlineData("\"Hls\"", MediaStreamProtocol.hls)] + public void Deserialize_Enum_Nullable(string? input, MediaStreamProtocol? output) + { + input ??= "null"; + string json = $"{{ \"EnumValue\": {input} }}"; + NullTestClass value = JsonSerializer.Deserialize(json, this._jsonOptions); + Assert.NotNull(value); + Assert.Equal(output, value.EnumValue); + } - var outputObj = JsonSerializer.Deserialize(JsonSerializer.Serialize(inputObj, _jsonOptions), _jsonOptions); + /// + /// Ensures that the roundtrip serialization & deserialization is successful. + /// + /// Input enum. + /// Output enum. + [Theory] + [InlineData(MediaStreamProtocol.http, MediaStreamProtocol.http)] + [InlineData(MediaStreamProtocol.hls, MediaStreamProtocol.hls)] + public void Enum_RoundTrip(MediaStreamProtocol input, MediaStreamProtocol output) + { + TestClass inputObj = new() { EnumValue = input }; - Assert.NotNull(outputObj); - Assert.Equal(output, outputObj.EnumValue); - } + TestClass? outputObj = JsonSerializer.Deserialize(JsonSerializer.Serialize(inputObj, this._jsonOptions), this._jsonOptions); - /// - /// Ensures that the roundtrip serialization & deserialization is successful, including null. - /// - /// Input enum. - /// Output enum. - [Theory] - [InlineData(MediaStreamProtocol.http, MediaStreamProtocol.http)] - [InlineData(MediaStreamProtocol.hls, MediaStreamProtocol.hls)] - [InlineData(null, null)] - public void Enum_RoundTrip_Nullable(MediaStreamProtocol? input, MediaStreamProtocol? output) - { - var inputObj = new NullTestClass { EnumValue = input }; + Assert.NotNull(outputObj); + Assert.Equal(output, outputObj.EnumValue); + } - var outputObj = JsonSerializer.Deserialize(JsonSerializer.Serialize(inputObj, _jsonOptions), _jsonOptions); + /// + /// Ensures that the roundtrip serialization & deserialization is successful, including null. + /// + /// Input enum. + /// Output enum. + [Theory] + [InlineData(MediaStreamProtocol.http, MediaStreamProtocol.http)] + [InlineData(MediaStreamProtocol.hls, MediaStreamProtocol.hls)] + [InlineData(null, null)] + public void Enum_RoundTrip_Nullable(MediaStreamProtocol? input, MediaStreamProtocol? output) + { + NullTestClass inputObj = new() { EnumValue = input }; - Assert.NotNull(outputObj); - Assert.Equal(output, outputObj.EnumValue); - } + NullTestClass? outputObj = JsonSerializer.Deserialize(JsonSerializer.Serialize(inputObj, this._jsonOptions), this._jsonOptions); - private sealed class TestClass - { - public MediaStreamProtocol EnumValue { get; set; } - } + Assert.NotNull(outputObj); + Assert.Equal(output, outputObj.EnumValue); + } - private sealed class NullTestClass - { - public MediaStreamProtocol? EnumValue { get; set; } + private sealed class TestClass + { + public MediaStreamProtocol EnumValue { get; set; } + } + + private sealed class NullTestClass + { + public MediaStreamProtocol? EnumValue { get; set; } + } } } diff --git a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonFlagEnumTests.cs b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonFlagEnumTests.cs index 3c32ceaa..4ada0f44 100644 --- a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonFlagEnumTests.cs +++ b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonFlagEnumTests.cs @@ -2,31 +2,32 @@ // Copyright (c) PlaceholderCompany. All rights reserved. // -namespace Jellyfin.Extensions.Tests.Json.Converters; - -using System.Text.Json; -using Jellyfin.Extensions.Json.Converters; -using MediaBrowser.Model.Session; -using Xunit; - -public class JsonFlagEnumTests +namespace Jellyfin.Extensions.Tests.Json.Converters { - private readonly JsonSerializerOptions _jsonOptions = new() + using System.Text.Json; + using Jellyfin.Extensions.Json.Converters; + using MediaBrowser.Model.Session; + using Xunit; + + public class JsonFlagEnumTests { - Converters = + private readonly JsonSerializerOptions _jsonOptions = new() { - new JsonFlagEnumConverter(), - }, - }; + Converters = + { + new JsonFlagEnumConverter(), + }, + }; - [Theory] - [InlineData(TranscodeReason.AudioIsExternal | TranscodeReason.ContainerNotSupported, "[\"ContainerNotSupported\",\"AudioIsExternal\"]")] - [InlineData(TranscodeReason.AudioIsExternal | TranscodeReason.ContainerNotSupported | TranscodeReason.VideoBitDepthNotSupported, "[\"ContainerNotSupported\",\"AudioIsExternal\",\"VideoBitDepthNotSupported\"]")] - [InlineData((TranscodeReason)0, "[]")] - public void Serialize_Transcode_Reason(TranscodeReason transcodeReason, string output) - { - var result = JsonSerializer.Serialize(transcodeReason, _jsonOptions); + [Theory] + [InlineData(TranscodeReason.AudioIsExternal | TranscodeReason.ContainerNotSupported, "[\"ContainerNotSupported\",\"AudioIsExternal\"]")] + [InlineData(TranscodeReason.AudioIsExternal | TranscodeReason.ContainerNotSupported | TranscodeReason.VideoBitDepthNotSupported, "[\"ContainerNotSupported\",\"AudioIsExternal\",\"VideoBitDepthNotSupported\"]")] + [InlineData((TranscodeReason)0, "[]")] + public void Serialize_Transcode_Reason(TranscodeReason transcodeReason, string output) + { + string result = JsonSerializer.Serialize(transcodeReason, this._jsonOptions); - Assert.Equal(output, result); + Assert.Equal(output, result); + } } } diff --git a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonGuidConverterTests.cs b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonGuidConverterTests.cs index 8b0b21bf..a88a4b1a 100644 --- a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonGuidConverterTests.cs +++ b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonGuidConverterTests.cs @@ -15,49 +15,49 @@ namespace Jellyfin.Extensions.Tests.Json.Converters public JsonGuidConverterTests() { - _options = new JsonSerializerOptions(); - _options.Converters.Add(new JsonGuidConverter()); + this._options = new JsonSerializerOptions(); + this._options.Converters.Add(new JsonGuidConverter()); } [Fact] public void Deserialize_Valid_Success() { - Guid value = JsonSerializer.Deserialize(@"""a852a27afe324084ae66db579ee3ee18""", _options); - Assert.Equal(new Guid("a852a27afe324084ae66db579ee3ee18"), value); + Guid value = JsonSerializer.Deserialize(@"""a852a27afe324084ae66db579ee3ee18""", this._options); + Assert.Equal(new("a852a27afe324084ae66db579ee3ee18"), value); } [Fact] public void Deserialize_ValidDashed_Success() { - Guid value = JsonSerializer.Deserialize(@"""e9b2dcaa-529c-426e-9433-5e9981f27f2e""", _options); - Assert.Equal(new Guid("e9b2dcaa-529c-426e-9433-5e9981f27f2e"), value); + Guid value = JsonSerializer.Deserialize(@"""e9b2dcaa-529c-426e-9433-5e9981f27f2e""", this._options); + Assert.Equal(new("e9b2dcaa-529c-426e-9433-5e9981f27f2e"), value); } [Fact] public void Roundtrip_Valid_Success() { - Guid guid = new Guid("a852a27afe324084ae66db579ee3ee18"); - string value = JsonSerializer.Serialize(guid, _options); - Assert.Equal(guid, JsonSerializer.Deserialize(value, _options)); + Guid guid = new("a852a27afe324084ae66db579ee3ee18"); + string value = JsonSerializer.Serialize(guid, this._options); + Assert.Equal(guid, JsonSerializer.Deserialize(value, this._options)); } [Fact] public void Deserialize_Null_EmptyGuid() { - Assert.Equal(Guid.Empty, JsonSerializer.Deserialize("null", _options)); + Assert.Equal(Guid.Empty, JsonSerializer.Deserialize("null", this._options)); } [Fact] public void Serialize_EmptyGuid_EmptyGuid() { - Assert.Equal($"\"{Guid.Empty:N}\"", JsonSerializer.Serialize(Guid.Empty, _options)); + Assert.Equal($"\"{Guid.Empty:N}\"", JsonSerializer.Serialize(Guid.Empty, this._options)); } [Fact] public void Serialize_Valid_NoDash_Success() { - var guid = new Guid("531797E9-9457-40E0-88BC-B1D6D38752FA"); - var str = JsonSerializer.Serialize(guid, _options); + Guid guid = new("531797E9-9457-40E0-88BC-B1D6D38752FA"); + string str = JsonSerializer.Serialize(guid, this._options); Assert.Equal($"\"{guid:N}\"", str); } @@ -65,7 +65,7 @@ namespace Jellyfin.Extensions.Tests.Json.Converters public void Serialize_Nullable_Success() { Guid? guid = new Guid("531797E9-9457-40E0-88BC-B1D6D38752FA"); - var str = JsonSerializer.Serialize(guid, _options); + string str = JsonSerializer.Serialize(guid, this._options); Assert.Equal($"\"{guid:N}\"", str); } } diff --git a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonNullableGuidConverterTests.cs b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonNullableGuidConverterTests.cs index 5aa64406..43d30fb8 100644 --- a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonNullableGuidConverterTests.cs +++ b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonNullableGuidConverterTests.cs @@ -15,69 +15,69 @@ namespace Jellyfin.Extensions.Tests.Json.Converters public JsonNullableGuidConverterTests() { - _options = new JsonSerializerOptions(); - _options.Converters.Add(new JsonNullableGuidConverter()); + this._options = new JsonSerializerOptions(); + this._options.Converters.Add(new JsonNullableGuidConverter()); } [Fact] public void Deserialize_Valid_Success() { - Guid? value = JsonSerializer.Deserialize(@"""a852a27afe324084ae66db579ee3ee18""", _options); - Assert.Equal(new Guid("a852a27afe324084ae66db579ee3ee18"), value); + Guid? value = JsonSerializer.Deserialize(@"""a852a27afe324084ae66db579ee3ee18""", this._options); + Assert.Equal(new("a852a27afe324084ae66db579ee3ee18"), value); } [Fact] public void Deserialize_ValidDashed_Success() { - Guid? value = JsonSerializer.Deserialize(@"""e9b2dcaa-529c-426e-9433-5e9981f27f2e""", _options); - Assert.Equal(new Guid("e9b2dcaa-529c-426e-9433-5e9981f27f2e"), value); + Guid? value = JsonSerializer.Deserialize(@"""e9b2dcaa-529c-426e-9433-5e9981f27f2e""", this._options); + Assert.Equal(new("e9b2dcaa-529c-426e-9433-5e9981f27f2e"), value); } [Fact] public void Roundtrip_Valid_Success() { - Guid guid = new Guid("a852a27afe324084ae66db579ee3ee18"); - string value = JsonSerializer.Serialize(guid, _options); - Assert.Equal(guid, JsonSerializer.Deserialize(value, _options)); + Guid guid = new("a852a27afe324084ae66db579ee3ee18"); + string value = JsonSerializer.Serialize(guid, this._options); + Assert.Equal(guid, JsonSerializer.Deserialize(value, this._options)); } [Fact] public void Deserialize_Null_Null() { - Assert.Null(JsonSerializer.Deserialize("null", _options)); + Assert.Null(JsonSerializer.Deserialize("null", this._options)); } [Fact] public void Deserialize_EmptyGuid_EmptyGuid() { - Assert.Equal(Guid.Empty, JsonSerializer.Deserialize(@"""00000000-0000-0000-0000-000000000000""", _options)); + Assert.Equal(Guid.Empty, JsonSerializer.Deserialize(@"""00000000-0000-0000-0000-000000000000""", this._options)); } [Fact] public void Serialize_EmptyGuid_Null() { - Assert.Equal("null", JsonSerializer.Serialize((Guid?)Guid.Empty, _options)); + Assert.Equal("null", JsonSerializer.Serialize((Guid?)Guid.Empty, this._options)); } [Fact] public void Serialize_Null_Null() { - Assert.Equal("null", JsonSerializer.Serialize((Guid?)null, _options)); + Assert.Equal("null", JsonSerializer.Serialize((Guid?)null, this._options)); } [Fact] public void Serialize_Valid_NoDash_Success() { - var guid = (Guid?)new Guid("531797E9-9457-40E0-88BC-B1D6D38752FA"); - var str = JsonSerializer.Serialize(guid, _options); + Guid? guid = new("531797E9-9457-40E0-88BC-B1D6D38752FA"); + string str = JsonSerializer.Serialize(guid, this._options); Assert.Equal($"\"{guid:N}\"", str); } [Fact] public void Serialize_Nullable_Success() { - Guid? guid = new Guid("531797E9-9457-40E0-88BC-B1D6D38752FA"); - var str = JsonSerializer.Serialize(guid, _options); + Guid? guid = new("531797E9-9457-40E0-88BC-B1D6D38752FA"); + string str = JsonSerializer.Serialize(guid, this._options); Assert.Equal($"\"{guid:N}\"", str); } } diff --git a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonStringConverterTests.cs b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonStringConverterTests.cs index 1397ce20..38f3984f 100644 --- a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonStringConverterTests.cs +++ b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonStringConverterTests.cs @@ -26,7 +26,7 @@ namespace Jellyfin.Extensions.Tests.Json.Converters [InlineData("false", "false")] public void Deserialize_String_Valid_Success(string input, string output) { - var deserialized = JsonSerializer.Deserialize(input, _jsonSerializerOptions); + string? deserialized = JsonSerializer.Deserialize(input, this._jsonSerializerOptions); Assert.Equal(deserialized, output); } @@ -35,7 +35,7 @@ namespace Jellyfin.Extensions.Tests.Json.Converters { const string? input = "123"; const int output = 123; - var deserialized = JsonSerializer.Deserialize(input, _jsonSerializerOptions); + int deserialized = JsonSerializer.Deserialize(input, this._jsonSerializerOptions); Assert.Equal(output, deserialized); } } diff --git a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonVersionConverterTests.cs b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonVersionConverterTests.cs index d8686c47..1f1045a9 100644 --- a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonVersionConverterTests.cs +++ b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonVersionConverterTests.cs @@ -15,25 +15,25 @@ namespace Jellyfin.Extensions.Tests.Json.Converters public JsonVersionConverterTests() { - _options = new JsonSerializerOptions(); - _options.Converters.Add(new JsonVersionConverter()); + this._options = new JsonSerializerOptions(); + this._options.Converters.Add(new JsonVersionConverter()); } [Fact] public void Deserialize_Version_Success() { - var input = "\"1.025.222\""; - var output = new Version(1, 25, 222); - var deserializedInput = JsonSerializer.Deserialize(input, _options); + string input = "\"1.025.222\""; + Version output = new(1, 25, 222); + Version? deserializedInput = JsonSerializer.Deserialize(input, this._options); Assert.Equal(output, deserializedInput); } [Fact] public void Serialize_Version_Success() { - var input = new Version(1, 09, 59); - var output = "\"1.9.59\""; - var serializedInput = JsonSerializer.Serialize(input, _options); + Version input = new(1, 09, 59); + string output = "\"1.9.59\""; + string serializedInput = JsonSerializer.Serialize(input, this._options); Assert.Equal(output, serializedInput); } }