From 0fd36a5bf1fc87ebbfd5b74585f0c080995c1688 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Tue, 14 Nov 2023 19:12:17 +0100 Subject: [PATCH] Fix warnings in test projects --- .../Controllers/UserControllerTests.cs | 2 +- .../JsonCommaDelimitedArrayTests.cs | 65 +++++++++---------- .../JsonCommaDelimitedIReadOnlyListTests.cs | 43 ++++++------ .../NetworkParseTests.cs | 1 + .../Manager/ItemImageProviderTests.cs | 14 ++-- .../Sorting/AiredEpisodeOrderComparerTests.cs | 11 ++-- .../Sorting/IndexNumberComparerTests.cs | 2 +- .../Sorting/ParentIndexNumberComparerTests.cs | 2 +- .../ParseNetworkTests.cs | 3 +- 9 files changed, 68 insertions(+), 75 deletions(-) diff --git a/tests/Jellyfin.Api.Tests/Controllers/UserControllerTests.cs b/tests/Jellyfin.Api.Tests/Controllers/UserControllerTests.cs index 3f965d0ff0..c7331c7181 100644 --- a/tests/Jellyfin.Api.Tests/Controllers/UserControllerTests.cs +++ b/tests/Jellyfin.Api.Tests/Controllers/UserControllerTests.cs @@ -109,7 +109,7 @@ public class UserControllerTests v.ErrorMessage.Contains("required", StringComparison.CurrentCultureIgnoreCase)); } - private IList Validate(object model) + private List Validate(object model) { var result = new List(); var context = new ValidationContext(model, null, null); diff --git a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedArrayTests.cs b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedArrayTests.cs index f2ca2ff081..61105b42b2 100644 --- a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedArrayTests.cs +++ b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedArrayTests.cs @@ -7,135 +7,128 @@ using Xunit; namespace Jellyfin.Extensions.Tests.Json.Converters { - public static class JsonCommaDelimitedArrayTests + public class JsonCommaDelimitedArrayTests { + private readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions() + { + Converters = + { + new JsonStringEnumConverter() + } + }; + [Fact] - public static void Deserialize_String_Null_Success() + public void Deserialize_String_Null_Success() { - var options = new JsonSerializerOptions(); - var value = JsonSerializer.Deserialize>(@"{ ""Value"": null }", options); + var value = JsonSerializer.Deserialize>(@"{ ""Value"": null }", _jsonOptions); Assert.Null(value?.Value); } [Fact] - public static void Deserialize_Empty_Success() + public void Deserialize_Empty_Success() { var desiredValue = new GenericBodyArrayModel { Value = Array.Empty() }; - var options = new JsonSerializerOptions(); - var value = JsonSerializer.Deserialize>(@"{ ""Value"": """" }", options); + var value = JsonSerializer.Deserialize>(@"{ ""Value"": """" }", _jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } [Fact] - public static void Deserialize_String_Valid_Success() + public void Deserialize_String_Valid_Success() { var desiredValue = new GenericBodyArrayModel { Value = new[] { "a", "b", "c" } }; - var options = new JsonSerializerOptions(); - var value = JsonSerializer.Deserialize>(@"{ ""Value"": ""a,b,c"" }", options); + var value = JsonSerializer.Deserialize>(@"{ ""Value"": ""a,b,c"" }", _jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } [Fact] - public static void Deserialize_String_Space_Valid_Success() + public void Deserialize_String_Space_Valid_Success() { var desiredValue = new GenericBodyArrayModel { Value = new[] { "a", "b", "c" } }; - var options = new JsonSerializerOptions(); - var value = JsonSerializer.Deserialize>(@"{ ""Value"": ""a, b, c"" }", options); + var value = JsonSerializer.Deserialize>(@"{ ""Value"": ""a, b, c"" }", _jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } [Fact] - public static void Deserialize_GenericCommandType_Valid_Success() + public void Deserialize_GenericCommandType_Valid_Success() { var desiredValue = new GenericBodyArrayModel { Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown } }; - var options = new JsonSerializerOptions(); - options.Converters.Add(new JsonStringEnumConverter()); - var value = JsonSerializer.Deserialize>(@"{ ""Value"": ""MoveUp,MoveDown"" }", options); + var value = JsonSerializer.Deserialize>(@"{ ""Value"": ""MoveUp,MoveDown"" }", _jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } [Fact] - public static void Deserialize_GenericCommandType_EmptyEntry_Success() + public void Deserialize_GenericCommandType_EmptyEntry_Success() { var desiredValue = new GenericBodyArrayModel { Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown } }; - var options = new JsonSerializerOptions(); - options.Converters.Add(new JsonStringEnumConverter()); - var value = JsonSerializer.Deserialize>(@"{ ""Value"": ""MoveUp,,MoveDown"" }", options); + var value = JsonSerializer.Deserialize>(@"{ ""Value"": ""MoveUp,,MoveDown"" }", _jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } [Fact] - public static void Deserialize_GenericCommandType_Invalid_Success() + public void Deserialize_GenericCommandType_Invalid_Success() { var desiredValue = new GenericBodyArrayModel { Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown } }; - var options = new JsonSerializerOptions(); - options.Converters.Add(new JsonStringEnumConverter()); - var value = JsonSerializer.Deserialize>(@"{ ""Value"": ""MoveUp,TotallyNotAVallidCommand,MoveDown"" }", options); + var value = JsonSerializer.Deserialize>(@"{ ""Value"": ""MoveUp,TotallyNotAVallidCommand,MoveDown"" }", _jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } [Fact] - public static void Deserialize_GenericCommandType_Space_Valid_Success() + public void Deserialize_GenericCommandType_Space_Valid_Success() { var desiredValue = new GenericBodyArrayModel { Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown } }; - var options = new JsonSerializerOptions(); - options.Converters.Add(new JsonStringEnumConverter()); - var value = JsonSerializer.Deserialize>(@"{ ""Value"": ""MoveUp, MoveDown"" }", options); + var value = JsonSerializer.Deserialize>(@"{ ""Value"": ""MoveUp, MoveDown"" }", _jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } [Fact] - public static void Deserialize_String_Array_Valid_Success() + public void Deserialize_String_Array_Valid_Success() { var desiredValue = new GenericBodyArrayModel { Value = new[] { "a", "b", "c" } }; - var options = new JsonSerializerOptions(); - var value = JsonSerializer.Deserialize>(@"{ ""Value"": [""a"",""b"",""c""] }", options); + var value = JsonSerializer.Deserialize>(@"{ ""Value"": [""a"",""b"",""c""] }", _jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } [Fact] - public static void Deserialize_GenericCommandType_Array_Valid_Success() + public void Deserialize_GenericCommandType_Array_Valid_Success() { var desiredValue = new GenericBodyArrayModel { Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown } }; - var options = new JsonSerializerOptions(); - options.Converters.Add(new JsonStringEnumConverter()); - var value = JsonSerializer.Deserialize>(@"{ ""Value"": [""MoveUp"", ""MoveDown""] }", options); + var value = JsonSerializer.Deserialize>(@"{ ""Value"": [""MoveUp"", ""MoveDown""] }", _jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } } diff --git a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedIReadOnlyListTests.cs b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedIReadOnlyListTests.cs index 92886dcd28..9b977b9a5d 100644 --- a/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedIReadOnlyListTests.cs +++ b/tests/Jellyfin.Extensions.Tests/Json/Converters/JsonCommaDelimitedIReadOnlyListTests.cs @@ -6,86 +6,85 @@ using Xunit; namespace Jellyfin.Extensions.Tests.Json.Converters { - public static class JsonCommaDelimitedIReadOnlyListTests + public class JsonCommaDelimitedIReadOnlyListTests { + private readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions() + { + Converters = + { + new JsonStringEnumConverter() + } + }; + [Fact] - public static void Deserialize_String_Valid_Success() + public void Deserialize_String_Valid_Success() { var desiredValue = new GenericBodyIReadOnlyListModel { Value = new[] { "a", "b", "c" } }; - var options = new JsonSerializerOptions(); - var value = JsonSerializer.Deserialize>(@"{ ""Value"": ""a,b,c"" }", options); + var value = JsonSerializer.Deserialize>(@"{ ""Value"": ""a,b,c"" }", _jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } [Fact] - public static void Deserialize_String_Space_Valid_Success() + public void Deserialize_String_Space_Valid_Success() { var desiredValue = new GenericBodyIReadOnlyListModel { Value = new[] { "a", "b", "c" } }; - var options = new JsonSerializerOptions(); - var value = JsonSerializer.Deserialize>(@"{ ""Value"": ""a, b, c"" }", options); + var value = JsonSerializer.Deserialize>(@"{ ""Value"": ""a, b, c"" }", _jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } [Fact] - public static void Deserialize_GenericCommandType_Valid_Success() + public void Deserialize_GenericCommandType_Valid_Success() { var desiredValue = new GenericBodyIReadOnlyListModel { Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown } }; - var options = new JsonSerializerOptions(); - options.Converters.Add(new JsonStringEnumConverter()); - var value = JsonSerializer.Deserialize>(@"{ ""Value"": ""MoveUp,MoveDown"" }", options); + var value = JsonSerializer.Deserialize>(@"{ ""Value"": ""MoveUp,MoveDown"" }", _jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } [Fact] - public static void Deserialize_GenericCommandType_Space_Valid_Success() + public void Deserialize_GenericCommandType_Space_Valid_Success() { var desiredValue = new GenericBodyIReadOnlyListModel { Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown } }; - var options = new JsonSerializerOptions(); - options.Converters.Add(new JsonStringEnumConverter()); - var value = JsonSerializer.Deserialize>(@"{ ""Value"": ""MoveUp, MoveDown"" }", options); + var value = JsonSerializer.Deserialize>(@"{ ""Value"": ""MoveUp, MoveDown"" }", _jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } [Fact] - public static void Deserialize_String_Array_Valid_Success() + public void Deserialize_String_Array_Valid_Success() { var desiredValue = new GenericBodyIReadOnlyListModel { Value = new[] { "a", "b", "c" } }; - var options = new JsonSerializerOptions(); - var value = JsonSerializer.Deserialize>(@"{ ""Value"": [""a"",""b"",""c""] }", options); + var value = JsonSerializer.Deserialize>(@"{ ""Value"": [""a"",""b"",""c""] }", _jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } [Fact] - public static void Deserialize_GenericCommandType_Array_Valid_Success() + public void Deserialize_GenericCommandType_Array_Valid_Success() { var desiredValue = new GenericBodyIReadOnlyListModel { Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown } }; - var options = new JsonSerializerOptions(); - options.Converters.Add(new JsonStringEnumConverter()); - var value = JsonSerializer.Deserialize>(@"{ ""Value"": [""MoveUp"", ""MoveDown""] }", options); + var value = JsonSerializer.Deserialize>(@"{ ""Value"": [""MoveUp"", ""MoveDown""] }", _jsonOptions); Assert.Equal(desiredValue.Value, value?.Value); } } diff --git a/tests/Jellyfin.Networking.Tests/NetworkParseTests.cs b/tests/Jellyfin.Networking.Tests/NetworkParseTests.cs index 93514a5017..19aaa5ef8f 100644 --- a/tests/Jellyfin.Networking.Tests/NetworkParseTests.cs +++ b/tests/Jellyfin.Networking.Tests/NetworkParseTests.cs @@ -10,6 +10,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging.Abstractions; using Moq; using Xunit; +using IConfigurationManager = MediaBrowser.Common.Configuration.IConfigurationManager; namespace Jellyfin.Networking.Tests { diff --git a/tests/Jellyfin.Providers.Tests/Manager/ItemImageProviderTests.cs b/tests/Jellyfin.Providers.Tests/Manager/ItemImageProviderTests.cs index d5ab6ab4be..be5a401b1a 100644 --- a/tests/Jellyfin.Providers.Tests/Manager/ItemImageProviderTests.cs +++ b/tests/Jellyfin.Providers.Tests/Manager/ItemImageProviderTests.cs @@ -27,7 +27,7 @@ namespace Jellyfin.Providers.Tests.Manager { public partial class ItemImageProviderTests { - private const string TestDataImagePath = "Test Data/Images/blank{0}.jpg"; + private static readonly CompositeFormat _testDataImagePath = CompositeFormat.Parse("Test Data/Images/blank{0}.jpg"); [GeneratedRegex("[0-9]+")] private static partial Regex NumbersRegex(); @@ -275,7 +275,7 @@ namespace Jellyfin.Providers.Tests.Manager { HasImage = true, Format = ImageFormat.Jpg, - Path = responseHasPath ? string.Format(CultureInfo.InvariantCulture, TestDataImagePath, 0) : null, + Path = responseHasPath ? string.Format(CultureInfo.InvariantCulture, _testDataImagePath, 0) : null, Protocol = protocol }; @@ -563,21 +563,21 @@ namespace Jellyfin.Providers.Tests.Manager mockFileSystem.Setup(fs => fs.GetFilePaths(It.IsAny(), It.IsAny())) .Returns(new[] { - string.Format(CultureInfo.InvariantCulture, TestDataImagePath, 0), - string.Format(CultureInfo.InvariantCulture, TestDataImagePath, 1) + string.Format(CultureInfo.InvariantCulture, _testDataImagePath, 0), + string.Format(CultureInfo.InvariantCulture, _testDataImagePath, 1) }); return new ItemImageProvider(new NullLogger(), providerManager, mockFileSystem.Object); } - private static BaseItem GetItemWithImages(ImageType type, int count, bool validPaths) + private static Video GetItemWithImages(ImageType type, int count, bool validPaths) { // Has to exist for querying DateModified time on file, results stored but not checked so not populating BaseItem.FileSystem ??= Mock.Of(); var item = new Video(); - var path = validPaths ? TestDataImagePath : "invalid path {0}"; + var path = validPaths ? _testDataImagePath.Format : "invalid path {0}"; for (int i = 0; i < count; i++) { item.SetImagePath(type, i, new FileSystemMetadata @@ -604,7 +604,7 @@ namespace Jellyfin.Providers.Tests.Manager /// private static LocalImageInfo[] GetImages(ImageType type, int count, bool validPaths) { - var path = validPaths ? TestDataImagePath : "invalid path {0}"; + var path = validPaths ? _testDataImagePath.Format : "invalid path {0}"; var images = new LocalImageInfo[count]; for (int i = 0; i < count; i++) { diff --git a/tests/Jellyfin.Server.Implementations.Tests/Sorting/AiredEpisodeOrderComparerTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Sorting/AiredEpisodeOrderComparerTests.cs index 1dd49b2cfa..ad85bdb6e1 100644 --- a/tests/Jellyfin.Server.Implementations.Tests/Sorting/AiredEpisodeOrderComparerTests.cs +++ b/tests/Jellyfin.Server.Implementations.Tests/Sorting/AiredEpisodeOrderComparerTests.cs @@ -9,22 +9,21 @@ namespace Jellyfin.Server.Implementations.Tests.Sorting { public class AiredEpisodeOrderComparerTests { + private readonly AiredEpisodeOrderComparer _cmp = new AiredEpisodeOrderComparer(); + [Theory] [ClassData(typeof(EpisodeBadData))] public void Compare_GivenNull_ThrowsArgumentNullException(BaseItem? x, BaseItem? y) { - var cmp = new AiredEpisodeOrderComparer(); - Assert.Throws(() => cmp.Compare(x, y)); + Assert.Throws(() => _cmp.Compare(x, y)); } [Theory] [ClassData(typeof(EpisodeTestData))] public void AiredEpisodeOrderCompareTest(BaseItem x, BaseItem y, int expected) { - var cmp = new AiredEpisodeOrderComparer(); - - Assert.Equal(expected, cmp.Compare(x, y)); - Assert.Equal(-expected, cmp.Compare(y, x)); + Assert.Equal(expected, _cmp.Compare(x, y)); + Assert.Equal(-expected, _cmp.Compare(y, x)); } private sealed class EpisodeBadData : TheoryData diff --git a/tests/Jellyfin.Server.Implementations.Tests/Sorting/IndexNumberComparerTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Sorting/IndexNumberComparerTests.cs index 18588bd67a..52f71ef4a3 100644 --- a/tests/Jellyfin.Server.Implementations.Tests/Sorting/IndexNumberComparerTests.cs +++ b/tests/Jellyfin.Server.Implementations.Tests/Sorting/IndexNumberComparerTests.cs @@ -9,7 +9,7 @@ namespace Jellyfin.Server.Implementations.Tests.Sorting; public class IndexNumberComparerTests { - private readonly IBaseItemComparer _cmp = new IndexNumberComparer(); + private readonly IndexNumberComparer _cmp = new IndexNumberComparer(); public static TheoryData Compare_GivenNull_ThrowsArgumentNullException_TestData() => new() diff --git a/tests/Jellyfin.Server.Implementations.Tests/Sorting/ParentIndexNumberComparerTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Sorting/ParentIndexNumberComparerTests.cs index 261092e019..bedd187ebb 100644 --- a/tests/Jellyfin.Server.Implementations.Tests/Sorting/ParentIndexNumberComparerTests.cs +++ b/tests/Jellyfin.Server.Implementations.Tests/Sorting/ParentIndexNumberComparerTests.cs @@ -9,7 +9,7 @@ namespace Jellyfin.Server.Implementations.Tests.Sorting; public class ParentIndexNumberComparerTests { - private readonly IBaseItemComparer _cmp = new ParentIndexNumberComparer(); + private readonly ParentIndexNumberComparer _cmp = new ParentIndexNumberComparer(); public static TheoryData Compare_GivenNull_ThrowsArgumentNullException_TestData() => new() diff --git a/tests/Jellyfin.Server.Tests/ParseNetworkTests.cs b/tests/Jellyfin.Server.Tests/ParseNetworkTests.cs index 8d464d4e75..44d9ce13c0 100644 --- a/tests/Jellyfin.Server.Tests/ParseNetworkTests.cs +++ b/tests/Jellyfin.Server.Tests/ParseNetworkTests.cs @@ -10,6 +10,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging.Abstractions; using Moq; using Xunit; +using IConfigurationManager = MediaBrowser.Common.Configuration.IConfigurationManager; namespace Jellyfin.Server.Tests { @@ -98,7 +99,7 @@ namespace Jellyfin.Server.Tests Assert.Equal(knownNetworks.Length, options.KnownNetworks.Count); foreach (var item in knownNetworks) { - Assert.NotNull(options.KnownNetworks.FirstOrDefault(x => x.BaseAddress.Equals(item.BaseAddress) && x.PrefixLength == item.PrefixLength)); + Assert.NotNull(options.KnownNetworks.FirstOrDefault(x => x.Prefix.Equals(item.BaseAddress) && x.PrefixLength == item.PrefixLength)); } }