From c5393b25798098aa079c185971b7ac28e5f5b994 Mon Sep 17 00:00:00 2001 From: ianjazz246 Date: Fri, 10 Sep 2021 20:11:16 -0700 Subject: [PATCH 1/3] Use TheoryData in UrlDecodeQueryFeatureTest --- .../UrlDecodeQueryFeatureTests.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/Jellyfin.Server.Tests/UrlDecodeQueryFeatureTests.cs b/tests/Jellyfin.Server.Tests/UrlDecodeQueryFeatureTests.cs index 419afb2dc4..39af21920d 100644 --- a/tests/Jellyfin.Server.Tests/UrlDecodeQueryFeatureTests.cs +++ b/tests/Jellyfin.Server.Tests/UrlDecodeQueryFeatureTests.cs @@ -10,11 +10,18 @@ namespace Jellyfin.Server.Tests { public static class UrlDecodeQueryFeatureTests { + public static TheoryData EmptyValueTest_TestData() + { + var data = new TheoryData(); + data.Add("e0a72cb2a2c7", "e0a72cb2a2c7"); // isn't encoded + data.Add("random+test", "random test"); // encoded + data.Add("random%20test", "random test"); // encoded + data.Add("++", " "); // encoded + return data; + } + [Theory] - [InlineData("e0a72cb2a2c7", "e0a72cb2a2c7")] // isn't encoded - [InlineData("random+test", "random test")] // encoded - [InlineData("random%20test", "random test")] // encoded - [InlineData("++", " ")] // encoded + [MemberData(nameof(EmptyValueTest_TestData))] public static void EmptyValueTest(string query, string key) { var dict = new Dictionary From 3313efce195a66b0363ea7224d70056fdda14ab6 Mon Sep 17 00:00:00 2001 From: ianjazz246 Date: Sat, 11 Sep 2021 13:29:58 -0700 Subject: [PATCH 2/3] Revert "Use TheoryData in UrlDecodeQueryFeatureTest" This reverts commit c5393b25798098aa079c185971b7ac28e5f5b994. --- .../UrlDecodeQueryFeatureTests.cs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/tests/Jellyfin.Server.Tests/UrlDecodeQueryFeatureTests.cs b/tests/Jellyfin.Server.Tests/UrlDecodeQueryFeatureTests.cs index 39af21920d..419afb2dc4 100644 --- a/tests/Jellyfin.Server.Tests/UrlDecodeQueryFeatureTests.cs +++ b/tests/Jellyfin.Server.Tests/UrlDecodeQueryFeatureTests.cs @@ -10,18 +10,11 @@ namespace Jellyfin.Server.Tests { public static class UrlDecodeQueryFeatureTests { - public static TheoryData EmptyValueTest_TestData() - { - var data = new TheoryData(); - data.Add("e0a72cb2a2c7", "e0a72cb2a2c7"); // isn't encoded - data.Add("random+test", "random test"); // encoded - data.Add("random%20test", "random test"); // encoded - data.Add("++", " "); // encoded - return data; - } - [Theory] - [MemberData(nameof(EmptyValueTest_TestData))] + [InlineData("e0a72cb2a2c7", "e0a72cb2a2c7")] // isn't encoded + [InlineData("random+test", "random test")] // encoded + [InlineData("random%20test", "random test")] // encoded + [InlineData("++", " ")] // encoded public static void EmptyValueTest(string query, string key) { var dict = new Dictionary From 19b8bcaec43835c698a35975a748c2129c1413aa Mon Sep 17 00:00:00 2001 From: ianjazz246 Date: Sat, 11 Sep 2021 13:31:24 -0700 Subject: [PATCH 3/3] Use TheoryData instead of MemberData and ClassData --- .../Controllers/DynamicHlsControllerTests.cs | 31 ++-- .../Helpers/RequestHelpersTests.cs | 26 +-- .../Cryptography/PasswordHashTests.cs | 54 +++---- .../CopyToExtensionsTests.cs | 38 +++-- .../EncoderValidatorTests.cs | 26 ++- .../Subtitles/SsaParserTests.cs | 12 +- .../Entities/MediaStreamTests.cs | 101 ++++++------ .../AudioBook/AudioBookResolverTests.cs | 26 +-- .../Video/VideoResolverTests.cs | 116 ++++++------- .../MediaInfo/SubtitleResolverTests.cs | 14 +- .../Data/SqliteItemRepositoryTests.cs | 100 +++++------- .../LiveTv/RecordingHelperTests.cs | 58 +++---- .../Sorting/AiredEpisodeOrderComparerTests.cs | 152 +++++++----------- 13 files changed, 339 insertions(+), 415 deletions(-) diff --git a/tests/Jellyfin.Api.Tests/Controllers/DynamicHlsControllerTests.cs b/tests/Jellyfin.Api.Tests/Controllers/DynamicHlsControllerTests.cs index 59a6b52d15..4f413d9652 100644 --- a/tests/Jellyfin.Api.Tests/Controllers/DynamicHlsControllerTests.cs +++ b/tests/Jellyfin.Api.Tests/Controllers/DynamicHlsControllerTests.cs @@ -19,33 +19,28 @@ namespace Jellyfin.Api.Tests.Controllers } } - public static IEnumerable GetSegmentLengths_Success_TestData() + public static TheoryData GetSegmentLengths_Success_TestData() { - yield return new object[] { 0, 6, Array.Empty() }; - yield return new object[] - { + var data = new TheoryData(); + data.Add(0, 6, Array.Empty()); + data.Add( TimeSpan.FromSeconds(3).Ticks, 6, - new double[] { 3 } - }; - yield return new object[] - { + new double[] { 3 }); + data.Add( TimeSpan.FromSeconds(6).Ticks, 6, - new double[] { 6 } - }; - yield return new object[] - { + new double[] { 6 }); + data.Add( TimeSpan.FromSeconds(3.3333333).Ticks, 6, - new double[] { 3.3333333 } - }; - yield return new object[] - { + new double[] { 3.3333333 }); + data.Add( TimeSpan.FromSeconds(9.3333333).Ticks, 6, - new double[] { 6, 3.3333333 } - }; + new double[] { 6, 3.3333333 }); + + return data; } } } diff --git a/tests/Jellyfin.Api.Tests/Helpers/RequestHelpersTests.cs b/tests/Jellyfin.Api.Tests/Helpers/RequestHelpersTests.cs index 97e441b1dc..4ba7e1d2ff 100644 --- a/tests/Jellyfin.Api.Tests/Helpers/RequestHelpersTests.cs +++ b/tests/Jellyfin.Api.Tests/Helpers/RequestHelpersTests.cs @@ -15,16 +15,16 @@ namespace Jellyfin.Api.Tests.Helpers Assert.Equal(expected, RequestHelpers.GetOrderBy(sortBy, requestedSortOrder)); } - public static IEnumerable GetOrderBy_Success_TestData() + public static TheoryData, IReadOnlyList, (string, SortOrder)[]> GetOrderBy_Success_TestData() { - yield return new object[] - { + var data = new TheoryData, IReadOnlyList, (string, SortOrder)[]>(); + + data.Add( Array.Empty(), Array.Empty(), - Array.Empty<(string, SortOrder)>() - }; - yield return new object[] - { + Array.Empty<(string, SortOrder)>()); + + data.Add( new string[] { "IsFavoriteOrLiked", @@ -35,10 +35,9 @@ namespace Jellyfin.Api.Tests.Helpers { ("IsFavoriteOrLiked", SortOrder.Ascending), ("Random", SortOrder.Ascending), - } - }; - yield return new object[] - { + }); + + data.Add( new string[] { "SortName", @@ -52,8 +51,9 @@ namespace Jellyfin.Api.Tests.Helpers { ("SortName", SortOrder.Descending), ("ProductionYear", SortOrder.Descending), - } - }; + }); + + return data; } [Fact] diff --git a/tests/Jellyfin.Common.Tests/Cryptography/PasswordHashTests.cs b/tests/Jellyfin.Common.Tests/Cryptography/PasswordHashTests.cs index 18d3f97638..bfece97b6b 100644 --- a/tests/Jellyfin.Common.Tests/Cryptography/PasswordHashTests.cs +++ b/tests/Jellyfin.Common.Tests/Cryptography/PasswordHashTests.cs @@ -19,18 +19,16 @@ namespace Jellyfin.Common.Tests.Cryptography Assert.Throws(() => new PasswordHash(string.Empty, Array.Empty())); } - public static IEnumerable Parse_Valid_TestData() + public static TheoryData Parse_Valid_TestData() { + var data = new TheoryData(); // Id - yield return new object[] - { + data.Add( "$PBKDF2", - new PasswordHash("PBKDF2", Array.Empty()) - }; + new PasswordHash("PBKDF2", Array.Empty())); // Id + parameter - yield return new object[] - { + data.Add( "$PBKDF2$iterations=1000", new PasswordHash( "PBKDF2", @@ -39,12 +37,10 @@ namespace Jellyfin.Common.Tests.Cryptography new Dictionary() { { "iterations", "1000" }, - }) - }; + })); // Id + parameters - yield return new object[] - { + data.Add( "$PBKDF2$iterations=1000,m=120", new PasswordHash( "PBKDF2", @@ -54,34 +50,28 @@ namespace Jellyfin.Common.Tests.Cryptography { { "iterations", "1000" }, { "m", "120" } - }) - }; + })); // Id + hash - yield return new object[] - { + data.Add( "$PBKDF2$62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D", new PasswordHash( "PBKDF2", Convert.FromHexString("62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D"), Array.Empty(), - new Dictionary()) - }; + new Dictionary())); // Id + salt + hash - yield return new object[] - { + data.Add( "$PBKDF2$69F420$62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D", new PasswordHash( "PBKDF2", Convert.FromHexString("62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D"), Convert.FromHexString("69F420"), - new Dictionary()) - }; + new Dictionary())); // Id + parameter + hash - yield return new object[] - { + data.Add( "$PBKDF2$iterations=1000$62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D", new PasswordHash( "PBKDF2", @@ -90,12 +80,9 @@ namespace Jellyfin.Common.Tests.Cryptography new Dictionary() { { "iterations", "1000" } - }) - }; - + })); // Id + parameters + hash - yield return new object[] - { + data.Add( "$PBKDF2$iterations=1000,m=120$62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D", new PasswordHash( "PBKDF2", @@ -105,12 +92,9 @@ namespace Jellyfin.Common.Tests.Cryptography { { "iterations", "1000" }, { "m", "120" } - }) - }; - + })); // Id + parameters + salt + hash - yield return new object[] - { + data.Add( "$PBKDF2$iterations=1000,m=120$69F420$62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D", new PasswordHash( "PBKDF2", @@ -120,8 +104,8 @@ namespace Jellyfin.Common.Tests.Cryptography { { "iterations", "1000" }, { "m", "120" } - }) - }; + })); + return data; } [Theory] diff --git a/tests/Jellyfin.Extensions.Tests/CopyToExtensionsTests.cs b/tests/Jellyfin.Extensions.Tests/CopyToExtensionsTests.cs index 6fdca46944..d46beedd99 100644 --- a/tests/Jellyfin.Extensions.Tests/CopyToExtensionsTests.cs +++ b/tests/Jellyfin.Extensions.Tests/CopyToExtensionsTests.cs @@ -6,10 +6,17 @@ namespace Jellyfin.Extensions.Tests { public static class CopyToExtensionsTests { - public static IEnumerable CopyTo_Valid_Correct_TestData() + public static TheoryData, IList, int, IList> CopyTo_Valid_Correct_TestData() { - yield return new object[] { new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0, 0, 0, 0, 0, 0 }, 0, new[] { 0, 1, 2, 3, 4, 5 } }; - yield return new object[] { new[] { 0, 1, 2 }, new[] { 5, 4, 3, 2, 1, 0 }, 2, new[] { 5, 4, 0, 1, 2, 0 } }; + var data = new TheoryData, IList, int, IList>(); + + data.Add( + new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0, 0, 0, 0, 0, 0 }, 0, new[] { 0, 1, 2, 3, 4, 5 }); + + data.Add( + new[] { 0, 1, 2 }, new[] { 5, 4, 3, 2, 1, 0 }, 2, new[] { 5, 4, 0, 1, 2, 0 } ); + + return data; } [Theory] @@ -20,13 +27,26 @@ namespace Jellyfin.Extensions.Tests Assert.Equal(expected, destination); } - public static IEnumerable CopyTo_Invalid_ThrowsArgumentOutOfRangeException_TestData() + public static TheoryData, IList, int> CopyTo_Invalid_ThrowsArgumentOutOfRangeException_TestData() { - yield return new object[] { new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0, 0, 0, 0, 0, 0 }, -1 }; - yield return new object[] { new[] { 0, 1, 2 }, new[] { 5, 4, 3, 2, 1, 0 }, 6 }; - yield return new object[] { new[] { 0, 1, 2 }, Array.Empty(), 0 }; - yield return new object[] { new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0 }, 0 }; - yield return new object[] { new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0, 0, 0, 0, 0, 0 }, 1 }; + var data = new TheoryData, IList, int>(); + + data.Add( + new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0, 0, 0, 0, 0, 0 }, -1 ); + + data.Add( + new[] { 0, 1, 2 }, new[] { 5, 4, 3, 2, 1, 0 }, 6 ); + + data.Add( + new[] { 0, 1, 2 }, Array.Empty(), 0 ); + + data.Add( + new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0 }, 0 ); + + data.Add( + new[] { 0, 1, 2, 3, 4, 5 }, new[] { 0, 0, 0, 0, 0, 0 }, 1 ); + + return data; } [Theory] diff --git a/tests/Jellyfin.MediaEncoding.Tests/EncoderValidatorTests.cs b/tests/Jellyfin.MediaEncoding.Tests/EncoderValidatorTests.cs index d1854a3c86..ce1ed86fa6 100644 --- a/tests/Jellyfin.MediaEncoding.Tests/EncoderValidatorTests.cs +++ b/tests/Jellyfin.MediaEncoding.Tests/EncoderValidatorTests.cs @@ -34,23 +34,21 @@ namespace Jellyfin.MediaEncoding.Tests Assert.Equal(valid, _encoderValidator.ValidateVersionInternal(versionOutput)); } - private class GetFFmpegVersionTestData : IEnumerable + private class GetFFmpegVersionTestData : TheoryData { - public IEnumerator GetEnumerator() + public GetFFmpegVersionTestData() { - yield return new object?[] { EncoderValidatorTestsData.FFmpegV44Output, new Version(4, 4) }; - yield return new object?[] { EncoderValidatorTestsData.FFmpegV432Output, new Version(4, 3, 2) }; - yield return new object?[] { EncoderValidatorTestsData.FFmpegV431Output, new Version(4, 3, 1) }; - yield return new object?[] { EncoderValidatorTestsData.FFmpegV43Output, new Version(4, 3) }; - yield return new object?[] { EncoderValidatorTestsData.FFmpegV421Output, new Version(4, 2, 1) }; - yield return new object?[] { EncoderValidatorTestsData.FFmpegV42Output, new Version(4, 2) }; - yield return new object?[] { EncoderValidatorTestsData.FFmpegV414Output, new Version(4, 1, 4) }; - yield return new object?[] { EncoderValidatorTestsData.FFmpegV404Output, new Version(4, 0, 4) }; - yield return new object?[] { EncoderValidatorTestsData.FFmpegGitUnknownOutput2, new Version(4, 0) }; - yield return new object?[] { EncoderValidatorTestsData.FFmpegGitUnknownOutput, null }; + Add(EncoderValidatorTestsData.FFmpegV44Output, new Version(4, 4)); + Add(EncoderValidatorTestsData.FFmpegV432Output, new Version(4, 3, 2)); + Add(EncoderValidatorTestsData.FFmpegV431Output, new Version(4, 3, 1)); + Add(EncoderValidatorTestsData.FFmpegV43Output, new Version(4, 3)); + Add(EncoderValidatorTestsData.FFmpegV421Output, new Version(4, 2, 1)); + Add(EncoderValidatorTestsData.FFmpegV42Output, new Version(4, 2)); + Add(EncoderValidatorTestsData.FFmpegV414Output, new Version(4, 1, 4)); + Add(EncoderValidatorTestsData.FFmpegV404Output, new Version(4, 0, 4)); + Add(EncoderValidatorTestsData.FFmpegGitUnknownOutput2, new Version(4, 0)); + Add(EncoderValidatorTestsData.FFmpegGitUnknownOutput, null); } - - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } } } diff --git a/tests/Jellyfin.MediaEncoding.Tests/Subtitles/SsaParserTests.cs b/tests/Jellyfin.MediaEncoding.Tests/Subtitles/SsaParserTests.cs index 5db80c3001..56649db8f8 100644 --- a/tests/Jellyfin.MediaEncoding.Tests/Subtitles/SsaParserTests.cs +++ b/tests/Jellyfin.MediaEncoding.Tests/Subtitles/SsaParserTests.cs @@ -38,10 +38,11 @@ namespace Jellyfin.MediaEncoding.Subtitles.Tests } } - public static IEnumerable Parse_MultipleDialogues_TestData() + public static TheoryData> Parse_MultipleDialogues_TestData() { - yield return new object[] - { + var data = new TheoryData>(); + + data.Add( @"[Events] Format: Layer, Start, End, Text Dialogue: ,0:00:01.18,0:00:01.85,dialogue1 @@ -65,8 +66,9 @@ namespace Jellyfin.MediaEncoding.Subtitles.Tests StartPositionTicks = 31800000, EndPositionTicks = 38500000 } - } - }; + }); + + return data; } [Fact] diff --git a/tests/Jellyfin.Model.Tests/Entities/MediaStreamTests.cs b/tests/Jellyfin.Model.Tests/Entities/MediaStreamTests.cs index ce9ecea6a9..7017b58b97 100644 --- a/tests/Jellyfin.Model.Tests/Entities/MediaStreamTests.cs +++ b/tests/Jellyfin.Model.Tests/Entities/MediaStreamTests.cs @@ -6,12 +6,11 @@ namespace Jellyfin.Model.Tests.Entities { public class MediaStreamTests { - public static IEnumerable Get_DisplayTitle_TestData() + public static TheoryData Get_DisplayTitle_TestData() { - return new List - { - new object[] - { + var data = new TheoryData(); + + data.Add( new MediaStream { Type = MediaStreamType.Subtitle, @@ -21,61 +20,57 @@ namespace Jellyfin.Model.Tests.Entities IsDefault = false, Codec = "ASS" }, - "English - Und - ASS" - }, - new object[] + "English - Und - ASS"); + + data.Add( + new MediaStream { - new MediaStream - { - Type = MediaStreamType.Subtitle, - Title = "English", - Language = string.Empty, - IsForced = false, - IsDefault = false, - Codec = string.Empty - }, - "English - Und" + Type = MediaStreamType.Subtitle, + Title = "English", + Language = string.Empty, + IsForced = false, + IsDefault = false, + Codec = string.Empty }, - new object[] + "English - Und"); + + data.Add( + new MediaStream { - new MediaStream - { - Type = MediaStreamType.Subtitle, - Title = "English", - Language = "EN", - IsForced = false, - IsDefault = false, - Codec = string.Empty - }, - "English" + Type = MediaStreamType.Subtitle, + Title = "English", + Language = "EN", + IsForced = false, + IsDefault = false, + Codec = string.Empty }, - new object[] + "English"); + + data.Add( + new MediaStream { - new MediaStream - { - Type = MediaStreamType.Subtitle, - Title = "English", - Language = "EN", - IsForced = true, - IsDefault = true, - Codec = "SRT" - }, - "English - Default - Forced - SRT" + Type = MediaStreamType.Subtitle, + Title = "English", + Language = "EN", + IsForced = true, + IsDefault = true, + Codec = "SRT" }, - new object[] + "English - Default - Forced - SRT"); + + data.Add( + new MediaStream { - new MediaStream - { - Type = MediaStreamType.Subtitle, - Title = null, - Language = null, - IsForced = false, - IsDefault = false, - Codec = null - }, - "Und" - } - }; + Type = MediaStreamType.Subtitle, + Title = null, + Language = null, + IsForced = false, + IsDefault = false, + Codec = null + }, + "Und"); + + return data; } [Theory] diff --git a/tests/Jellyfin.Naming.Tests/AudioBook/AudioBookResolverTests.cs b/tests/Jellyfin.Naming.Tests/AudioBook/AudioBookResolverTests.cs index 53b35c2d6c..664136d8d2 100644 --- a/tests/Jellyfin.Naming.Tests/AudioBook/AudioBookResolverTests.cs +++ b/tests/Jellyfin.Naming.Tests/AudioBook/AudioBookResolverTests.cs @@ -9,29 +9,29 @@ namespace Jellyfin.Naming.Tests.AudioBook { private readonly NamingOptions _namingOptions = new NamingOptions(); - public static IEnumerable Resolve_ValidFileNameTestData() + public static TheoryData Resolve_ValidFileNameTestData() { - yield return new object[] - { + var data = new TheoryData(); + + data.Add( new AudioBookFileInfo( @"/server/AudioBooks/Larry Potter/Larry Potter.mp3", - "mp3") - }; - yield return new object[] - { + "mp3")); + + data.Add( new AudioBookFileInfo( @"/server/AudioBooks/Berry Potter/Chapter 1 .ogg", "ogg", - chapterNumber: 1) - }; - yield return new object[] - { + chapterNumber: 1)); + + data.Add( new AudioBookFileInfo( @"/server/AudioBooks/Nerry Potter/Part 3 - Chapter 2.mp3", "mp3", chapterNumber: 2, - partNumber: 3) - }; + partNumber: 3)); + + return data; } [Theory] diff --git a/tests/Jellyfin.Naming.Tests/Video/VideoResolverTests.cs b/tests/Jellyfin.Naming.Tests/Video/VideoResolverTests.cs index ac5a7a21e6..420147dcb6 100644 --- a/tests/Jellyfin.Naming.Tests/Video/VideoResolverTests.cs +++ b/tests/Jellyfin.Naming.Tests/Video/VideoResolverTests.cs @@ -11,148 +11,134 @@ namespace Jellyfin.Naming.Tests.Video { private static NamingOptions _namingOptions = new NamingOptions(); - public static IEnumerable ResolveFile_ValidFileNameTestData() + public static TheoryData ResolveFile_ValidFileNameTestData() { - yield return new object[] - { + var data = new TheoryData(); + data.Add( new VideoFileInfo( path: @"/server/Movies/7 Psychos.mkv/7 Psychos.mkv", container: "mkv", - name: "7 Psychos") - }; - yield return new object[] - { + name: "7 Psychos")); + + data.Add( new VideoFileInfo( path: @"/server/Movies/3 days to kill (2005)/3 days to kill (2005).mkv", container: "mkv", name: "3 days to kill", - year: 2005) - }; - yield return new object[] - { + year: 2005)); + + data.Add( new VideoFileInfo( path: @"/server/Movies/American Psycho/American.Psycho.mkv", container: "mkv", - name: "American.Psycho") - }; - yield return new object[] - { + name: "American.Psycho")); + + data.Add( new VideoFileInfo( path: @"/server/Movies/brave (2007)/brave (2006).3d.sbs.mkv", container: "mkv", name: "brave", year: 2006, is3D: true, - format3D: "sbs") - }; - yield return new object[] - { + format3D: "sbs")); + + data.Add( new VideoFileInfo( path: @"/server/Movies/300 (2007)/300 (2006).3d1.sbas.mkv", container: "mkv", name: "300", - year: 2006) - }; - yield return new object[] - { + year: 2006)); + + data.Add( new VideoFileInfo( path: @"/server/Movies/300 (2007)/300 (2006).3d.sbs.mkv", container: "mkv", name: "300", year: 2006, is3D: true, - format3D: "sbs") - }; - yield return new object[] - { + format3D: "sbs")); + + data.Add( new VideoFileInfo( path: @"/server/Movies/brave (2007)/brave (2006)-trailer.bluray.disc", container: "disc", name: "brave", year: 2006, isStub: true, - stubType: "bluray") - }; - yield return new object[] - { + stubType: "bluray")); + + data.Add( new VideoFileInfo( path: @"/server/Movies/300 (2007)/300 (2006)-trailer.bluray.disc", container: "disc", name: "300", year: 2006, isStub: true, - stubType: "bluray") - }; - yield return new object[] - { + stubType: "bluray")); + + data.Add( new VideoFileInfo( path: @"/server/Movies/Brave (2007)/Brave (2006).bluray.disc", container: "disc", name: "Brave", year: 2006, isStub: true, - stubType: "bluray") - }; - yield return new object[] - { + stubType: "bluray")); + + data.Add( new VideoFileInfo( path: @"/server/Movies/300 (2007)/300 (2006).bluray.disc", container: "disc", name: "300", year: 2006, isStub: true, - stubType: "bluray") - }; - yield return new object[] - { + stubType: "bluray")); + + data.Add( new VideoFileInfo( path: @"/server/Movies/300 (2007)/300 (2006)-trailer.mkv", container: "mkv", name: "300", year: 2006, - extraType: ExtraType.Trailer) - }; - yield return new object[] - { + extraType: ExtraType.Trailer)); + + data.Add( new VideoFileInfo( path: @"/server/Movies/Brave (2007)/Brave (2006)-trailer.mkv", container: "mkv", name: "Brave", year: 2006, - extraType: ExtraType.Trailer) - }; - yield return new object[] - { + extraType: ExtraType.Trailer)); + + data.Add( new VideoFileInfo( path: @"/server/Movies/300 (2007)/300 (2006).mkv", container: "mkv", name: "300", - year: 2006) - }; - yield return new object[] - { + year: 2006)); + + data.Add( new VideoFileInfo( path: @"/server/Movies/Bad Boys (1995)/Bad Boys (1995).mkv", container: "mkv", name: "Bad Boys", - year: 1995) - }; - yield return new object[] - { + year: 1995)); + + data.Add( new VideoFileInfo( path: @"/server/Movies/Brave (2007)/Brave (2006).mkv", container: "mkv", name: "Brave", - year: 2006) - }; - yield return new object[] - { + year: 2006)); + + data.Add( new VideoFileInfo( path: @"/server/Movies/Rain Man 1988 REMASTERED 1080p BluRay x264 AAC - JEFF/Rain Man 1988 REMASTERED 1080p BluRay x264 AAC - JEFF.mp4", container: "mp4", name: "Rain Man", - year: 1988) - }; + year: 1988)); + + return data; } [Theory] diff --git a/tests/Jellyfin.Providers.Tests/MediaInfo/SubtitleResolverTests.cs b/tests/Jellyfin.Providers.Tests/MediaInfo/SubtitleResolverTests.cs index b160e676e4..c289a71129 100644 --- a/tests/Jellyfin.Providers.Tests/MediaInfo/SubtitleResolverTests.cs +++ b/tests/Jellyfin.Providers.Tests/MediaInfo/SubtitleResolverTests.cs @@ -1,4 +1,4 @@ -#pragma warning disable CA1002 // Do not expose generic lists +#pragma warning disable CA1002 // Do not expose generic lists using System.Collections.Generic; using MediaBrowser.Model.Entities; @@ -11,11 +11,12 @@ namespace Jellyfin.Providers.Tests.MediaInfo { public class SubtitleResolverTests { - public static IEnumerable AddExternalSubtitleStreams_GivenMixedFilenames_ReturnsValidSubtitles_TestData() + public static TheoryData, string, int, string[], MediaStream[]> AddExternalSubtitleStreams_GivenMixedFilenames_ReturnsValidSubtitles_TestData() { + var data = new TheoryData, string, int, string[], MediaStream[]>(); + var index = 0; - yield return new object[] - { + data.Add( new List(), "/video/My.Video.mkv", index, @@ -52,8 +53,9 @@ namespace Jellyfin.Providers.Tests.MediaInfo CreateMediaStream("/video/My.Video.default.forced.en.srt", "srt", "en", index++, isForced: true, isDefault: true), CreateMediaStream("/video/My.Video.en.default.forced.srt", "srt", "en", index++, isForced: true, isDefault: true), CreateMediaStream("/video/My.Video.With.Additional.Garbage.en.srt", "srt", "en", index), - } - }; + }); + + return data; } [Theory] diff --git a/tests/Jellyfin.Server.Implementations.Tests/Data/SqliteItemRepositoryTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Data/SqliteItemRepositoryTests.cs index a6e1dfe8f6..6337dea412 100644 --- a/tests/Jellyfin.Server.Implementations.Tests/Data/SqliteItemRepositoryTests.cs +++ b/tests/Jellyfin.Server.Implementations.Tests/Data/SqliteItemRepositoryTests.cs @@ -32,10 +32,11 @@ namespace Jellyfin.Server.Implementations.Tests.Data _sqliteItemRepository = _fixture.Create(); } - public static IEnumerable ItemImageInfoFromValueString_Valid_TestData() + public static TheoryData ItemImageInfoFromValueString_Valid_TestData() { - yield return new object[] - { + var data = new TheoryData(); + + data.Add( "/mnt/series/Family Guy/Season 1/Family Guy - S01E01-thumb.jpg*637452096478512963*Primary*1920*1080*WjQbtJtSO8nhNZ%L_Io#R/oaS6o}-;adXAoIn7j[%hW9s:WGw[nN", new ItemImageInfo { @@ -45,41 +46,33 @@ namespace Jellyfin.Server.Implementations.Tests.Data Width = 1920, Height = 1080, BlurHash = "WjQbtJtSO8nhNZ%L_Io#R*oaS6o}-;adXAoIn7j[%hW9s:WGw[nN" - } - }; + }); - yield return new object[] - { + data.Add( "https://image.tmdb.org/t/p/original/zhB5CHEgqqh4wnEqDNJLfWXJlcL.jpg*0*Primary*0*0", new ItemImageInfo { Path = "https://image.tmdb.org/t/p/original/zhB5CHEgqqh4wnEqDNJLfWXJlcL.jpg", Type = ImageType.Primary, - } - }; + }); - yield return new object[] - { + data.Add( "https://image.tmdb.org/t/p/original/zhB5CHEgqqh4wnEqDNJLfWXJlcL.jpg*0*Primary", new ItemImageInfo { Path = "https://image.tmdb.org/t/p/original/zhB5CHEgqqh4wnEqDNJLfWXJlcL.jpg", Type = ImageType.Primary, - } - }; + }); - yield return new object[] - { + data.Add( "https://image.tmdb.org/t/p/original/zhB5CHEgqqh4wnEqDNJLfWXJlcL.jpg*0*Primary*600", new ItemImageInfo { Path = "https://image.tmdb.org/t/p/original/zhB5CHEgqqh4wnEqDNJLfWXJlcL.jpg", Type = ImageType.Primary, - } - }; + }); - yield return new object[] - { + data.Add( "%MetadataPath%/library/68/68578562b96c80a7ebd530848801f645/poster.jpg*637264380567586027*Primary*600*336", new ItemImageInfo { @@ -88,8 +81,9 @@ namespace Jellyfin.Server.Implementations.Tests.Data DateModified = new DateTime(637264380567586027, DateTimeKind.Utc), Width = 600, Height = 336 - } - }; + }); + + return data; } [Theory] @@ -117,10 +111,10 @@ namespace Jellyfin.Server.Implementations.Tests.Data Assert.Null(_sqliteItemRepository.ItemImageInfoFromValueString(value)); } - public static IEnumerable DeserializeImages_Valid_TestData() + public static TheoryData DeserializeImages_Valid_TestData() { - yield return new object[] - { + var data = new TheoryData(); + data.Add( "/mnt/series/Family Guy/Season 1/Family Guy - S01E01-thumb.jpg*637452096478512963*Primary*1920*1080*WjQbtJtSO8nhNZ%L_Io#R/oaS6o}-;adXAoIn7j[%hW9s:WGw[nN", new ItemImageInfo[] { @@ -133,11 +127,9 @@ namespace Jellyfin.Server.Implementations.Tests.Data Height = 1080, BlurHash = "WjQbtJtSO8nhNZ%L_Io#R*oaS6o}-;adXAoIn7j[%hW9s:WGw[nN" } - } - }; + }); - yield return new object[] - { + data.Add( "%MetadataPath%/library/2a/2a27372f1e9bc757b1db99721bbeae1e/poster.jpg*637261226720645297*Primary*0*0|%MetadataPath%/library/2a/2a27372f1e9bc757b1db99721bbeae1e/logo.png*637261226720805297*Logo*0*0|%MetadataPath%/library/2a/2a27372f1e9bc757b1db99721bbeae1e/landscape.jpg*637261226721285297*Thumb*0*0|%MetadataPath%/library/2a/2a27372f1e9bc757b1db99721bbeae1e/backdrop.jpg*637261226721685297*Backdrop*0*0", new ItemImageInfo[] { @@ -165,20 +157,19 @@ namespace Jellyfin.Server.Implementations.Tests.Data Type = ImageType.Backdrop, DateModified = new DateTime(637261226721685297, DateTimeKind.Utc), } - } - }; + }); + + return data; } - public static IEnumerable DeserializeImages_ValidAndInvalid_TestData() + public static TheoryData DeserializeImages_ValidAndInvalid_TestData() { - yield return new object[] - { + var data = new TheoryData(); + data.Add( string.Empty, - Array.Empty() - }; + Array.Empty()); - yield return new object[] - { + data.Add( "/mnt/series/Family Guy/Season 1/Family Guy - S01E01-thumb.jpg*637452096478512963*Primary*1920*1080*WjQbtJtSO8nhNZ%L_Io#R/oaS6o}-;adXAoIn7j[%hW9s:WGw[nN|test|1234||ss", new ItemImageInfo[] { @@ -191,14 +182,13 @@ namespace Jellyfin.Server.Implementations.Tests.Data Height = 1080, BlurHash = "WjQbtJtSO8nhNZ%L_Io#R*oaS6o}-;adXAoIn7j[%hW9s:WGw[nN" } - } - }; + }); - yield return new object[] - { + data.Add( "|", - Array.Empty() - }; + Array.Empty()); + + return data; } [Theory] @@ -242,30 +232,27 @@ namespace Jellyfin.Server.Implementations.Tests.Data Assert.Equal(expected, _sqliteItemRepository.SerializeImages(value)); } - public static IEnumerable DeserializeProviderIds_Valid_TestData() + public static TheoryData> DeserializeProviderIds_Valid_TestData() { - yield return new object[] - { + var data = new TheoryData>(); + + data.Add( "Imdb=tt0119567", new Dictionary() { { "Imdb", "tt0119567" }, - } - }; + }); - yield return new object[] - { + data.Add( "Imdb=tt0119567|Tmdb=330|TmdbCollection=328", new Dictionary() { { "Imdb", "tt0119567" }, { "Tmdb", "330" }, { "TmdbCollection", "328" }, - } - }; + }); - yield return new object[] - { + data.Add( "MusicBrainzAlbum=9d363e43-f24f-4b39-bc5a-7ef305c677c7|MusicBrainzReleaseGroup=63eba062-847c-3b73-8b0f-6baf27bba6fa|AudioDbArtist=111352|AudioDbAlbum=2116560|MusicBrainzAlbumArtist=20244d07-534f-4eff-b4d4-930878889970", new Dictionary() { @@ -274,8 +261,9 @@ namespace Jellyfin.Server.Implementations.Tests.Data { "AudioDbArtist", "111352" }, { "AudioDbAlbum", "2116560" }, { "MusicBrainzAlbumArtist", "20244d07-534f-4eff-b4d4-930878889970" }, - } - }; + }); + + return data; } [Theory] diff --git a/tests/Jellyfin.Server.Implementations.Tests/LiveTv/RecordingHelperTests.cs b/tests/Jellyfin.Server.Implementations.Tests/LiveTv/RecordingHelperTests.cs index e8b93b437b..bc16e14987 100644 --- a/tests/Jellyfin.Server.Implementations.Tests/LiveTv/RecordingHelperTests.cs +++ b/tests/Jellyfin.Server.Implementations.Tests/LiveTv/RecordingHelperTests.cs @@ -8,43 +8,36 @@ namespace Jellyfin.Server.Implementations.Tests.LiveTv { public static class RecordingHelperTests { - public static IEnumerable GetRecordingName_Success_TestData() + public static TheoryData GetRecordingName_Success_TestData() { - yield return new object[] - { + var data = new TheoryData(); + + data.Add( "The Incredibles 2020_04_20_21_06_00", new TimerInfo { Name = "The Incredibles", StartDate = new DateTime(2020, 4, 20, 21, 6, 0, DateTimeKind.Local), IsMovie = true - } - }; + }); - yield return new object[] - { + data.Add( "The Incredibles (2004)", new TimerInfo { Name = "The Incredibles", IsMovie = true, ProductionYear = 2004 - } - }; - - yield return new object[] - { + }); + data.Add( "The Big Bang Theory 2020_04_20_21_06_00", new TimerInfo { Name = "The Big Bang Theory", StartDate = new DateTime(2020, 4, 20, 21, 6, 0, DateTimeKind.Local), IsProgramSeries = true, - } - }; - - yield return new object[] - { + }); + data.Add( "The Big Bang Theory S12E10", new TimerInfo { @@ -52,11 +45,8 @@ namespace Jellyfin.Server.Implementations.Tests.LiveTv IsProgramSeries = true, SeasonNumber = 12, EpisodeNumber = 10 - } - }; - - yield return new object[] - { + }); + data.Add( "The Big Bang Theory S12E10 The VCR Illumination", new TimerInfo { @@ -65,22 +55,17 @@ namespace Jellyfin.Server.Implementations.Tests.LiveTv SeasonNumber = 12, EpisodeNumber = 10, EpisodeTitle = "The VCR Illumination" - } - }; - - yield return new object[] - { + }); + data.Add( "The Big Bang Theory 2018-12-06", new TimerInfo { Name = "The Big Bang Theory", IsProgramSeries = true, OriginalAirDate = new DateTime(2018, 12, 6) - } - }; + }); - yield return new object[] - { + data.Add( "The Big Bang Theory 2018-12-06 - The VCR Illumination", new TimerInfo { @@ -88,11 +73,9 @@ namespace Jellyfin.Server.Implementations.Tests.LiveTv IsProgramSeries = true, OriginalAirDate = new DateTime(2018, 12, 6), EpisodeTitle = "The VCR Illumination" - } - }; + }); - yield return new object[] - { + data.Add( "The Big Bang Theory 2018_12_06_21_06_00 - The VCR Illumination", new TimerInfo { @@ -101,8 +84,9 @@ namespace Jellyfin.Server.Implementations.Tests.LiveTv IsProgramSeries = true, OriginalAirDate = new DateTime(2018, 12, 6), EpisodeTitle = "The VCR Illumination" - } - }; + }); + + return data; } [Theory] diff --git a/tests/Jellyfin.Server.Implementations.Tests/Sorting/AiredEpisodeOrderComparerTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Sorting/AiredEpisodeOrderComparerTests.cs index d9b206f663..829be4cdb7 100644 --- a/tests/Jellyfin.Server.Implementations.Tests/Sorting/AiredEpisodeOrderComparerTests.cs +++ b/tests/Jellyfin.Server.Implementations.Tests/Sorting/AiredEpisodeOrderComparerTests.cs @@ -13,7 +13,7 @@ namespace Jellyfin.Server.Implementations.Tests.Sorting { [Theory] [ClassData(typeof(EpisodeBadData))] - public void Compare_GivenNull_ThrowsArgumentNullException(BaseItem x, BaseItem y) + public void Compare_GivenNull_ThrowsArgumentNullException(BaseItem? x, BaseItem? y) { var cmp = new AiredEpisodeOrderComparer(); Assert.Throws(() => cmp.Compare(x, y)); @@ -29,152 +29,122 @@ namespace Jellyfin.Server.Implementations.Tests.Sorting Assert.Equal(-expected, cmp.Compare(y, x)); } - private class EpisodeBadData : IEnumerable + private class EpisodeBadData : TheoryData { - public IEnumerator GetEnumerator() + public EpisodeBadData() { - yield return new object?[] { null, new Episode() }; - yield return new object?[] { new Episode(), null }; + Add(null, new Episode()); + Add(new Episode(), null); } - - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } - private class EpisodeTestData : IEnumerable + private class EpisodeTestData : TheoryData { - public IEnumerator GetEnumerator() + public EpisodeTestData() { - yield return new object?[] - { + Add( new Movie(), new Movie(), - 0 - }; - yield return new object?[] - { + 0); + + Add( new Movie(), new Episode(), - 1 - }; + 1); + // Good cases - yield return new object?[] - { + Add( new Episode(), new Episode(), - 0 - }; - yield return new object?[] - { + 0); + + Add( new Episode { ParentIndexNumber = 1, IndexNumber = 1 }, new Episode { ParentIndexNumber = 1, IndexNumber = 1 }, - 0 - }; - yield return new object?[] - { + 0); + + Add( new Episode { ParentIndexNumber = 1, IndexNumber = 2 }, new Episode { ParentIndexNumber = 1, IndexNumber = 1 }, - 1 - }; - yield return new object?[] - { + 1); + + Add( new Episode { ParentIndexNumber = 2, IndexNumber = 1 }, new Episode { ParentIndexNumber = 1, IndexNumber = 1 }, - 1 - }; + 1); + // Good Specials - yield return new object?[] - { + Add( new Episode { ParentIndexNumber = 0, IndexNumber = 1 }, new Episode { ParentIndexNumber = 0, IndexNumber = 1 }, - 0 - }; - yield return new object?[] - { + 0); + + Add( new Episode { ParentIndexNumber = 0, IndexNumber = 2 }, new Episode { ParentIndexNumber = 0, IndexNumber = 1 }, - 1 - }; + 1); // Specials to Episodes - yield return new object?[] - { + Add( new Episode { ParentIndexNumber = 1, IndexNumber = 1 }, new Episode { ParentIndexNumber = 0, IndexNumber = 1 }, - 1 - }; - yield return new object?[] - { + 1); + + Add( new Episode { ParentIndexNumber = 1, IndexNumber = 1 }, new Episode { ParentIndexNumber = 0, IndexNumber = 2 }, - 1 - }; - yield return new object?[] - { + 1); + + Add( new Episode { ParentIndexNumber = 1, IndexNumber = 2 }, new Episode { ParentIndexNumber = 0, IndexNumber = 1 }, - 1 - }; + 1); - yield return new object?[] - { + Add( new Episode { ParentIndexNumber = 1, IndexNumber = 2 }, new Episode { ParentIndexNumber = 0, IndexNumber = 1 }, - 1 - }; - yield return new object?[] - { + 1); + + Add( new Episode { ParentIndexNumber = 1, IndexNumber = 1 }, new Episode { ParentIndexNumber = 0, IndexNumber = 2 }, - 1 - }; + 1); - yield return new object?[] - { + Add( new Episode { ParentIndexNumber = 0, IndexNumber = 1, AirsAfterSeasonNumber = 1 }, new Episode { ParentIndexNumber = 1, IndexNumber = 1 }, - 1 - }; - yield return new object?[] - { + 1); + + Add( new Episode { ParentIndexNumber = 3, IndexNumber = 1 }, new Episode { ParentIndexNumber = 0, IndexNumber = 1, AirsAfterSeasonNumber = 1 }, - 1 - }; + 1); - yield return new object?[] - { + Add( new Episode { ParentIndexNumber = 3, IndexNumber = 1 }, new Episode { ParentIndexNumber = 0, IndexNumber = 1, AirsAfterSeasonNumber = 1, AirsBeforeEpisodeNumber = 2 }, - 1 - }; + 1); - yield return new object?[] - { + Add( new Episode { ParentIndexNumber = 1, IndexNumber = 1 }, new Episode { ParentIndexNumber = 0, IndexNumber = 1, AirsBeforeSeasonNumber = 1 }, - 1 - }; - yield return new object?[] - { + 1); + + Add( new Episode { ParentIndexNumber = 1, IndexNumber = 2 }, new Episode { ParentIndexNumber = 0, IndexNumber = 1, AirsBeforeSeasonNumber = 1, AirsBeforeEpisodeNumber = 2 }, - 1 - }; - yield return new object?[] - { + 1); + + Add( new Episode { ParentIndexNumber = 1 }, new Episode { ParentIndexNumber = 0, IndexNumber = 1, AirsBeforeSeasonNumber = 1, AirsBeforeEpisodeNumber = 2 }, - 0 - }; - yield return new object?[] - { + 0); + + Add( new Episode { ParentIndexNumber = 1, IndexNumber = 3 }, new Episode { ParentIndexNumber = 0, IndexNumber = 1, AirsBeforeSeasonNumber = 1, AirsBeforeEpisodeNumber = 2 }, - 1 - }; + 1); } - - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } } }