浏览代码

Use TheoryData instead of MemberData and ClassData

ianjazz246 3 年之前
父节点
当前提交
19b8bcaec4

+ 13 - 18
tests/Jellyfin.Api.Tests/Controllers/DynamicHlsControllerTests.cs

@@ -19,33 +19,28 @@ namespace Jellyfin.Api.Tests.Controllers
             }
         }
 
-        public static IEnumerable<object[]> GetSegmentLengths_Success_TestData()
+        public static TheoryData<long, int, double[]> GetSegmentLengths_Success_TestData()
         {
-            yield return new object[] { 0, 6, Array.Empty<double>() };
-            yield return new object[]
-            {
+            var data = new TheoryData<long, int, double[]>();
+            data.Add(0, 6, Array.Empty<double>());
+            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;
         }
     }
 }

+ 13 - 13
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<object[]> GetOrderBy_Success_TestData()
+        public static TheoryData<IReadOnlyList<string>, IReadOnlyList<SortOrder>, (string, SortOrder)[]> GetOrderBy_Success_TestData()
         {
-            yield return new object[]
-            {
+            var data = new TheoryData<IReadOnlyList<string>, IReadOnlyList<SortOrder>, (string, SortOrder)[]>();
+
+            data.Add(
                 Array.Empty<string>(),
                 Array.Empty<SortOrder>(),
-                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]

+ 19 - 35
tests/Jellyfin.Common.Tests/Cryptography/PasswordHashTests.cs

@@ -19,18 +19,16 @@ namespace Jellyfin.Common.Tests.Cryptography
             Assert.Throws<ArgumentException>(() => new PasswordHash(string.Empty, Array.Empty<byte>()));
         }
 
-        public static IEnumerable<object[]> Parse_Valid_TestData()
+        public static TheoryData<string, PasswordHash> Parse_Valid_TestData()
         {
+            var data = new TheoryData<string, PasswordHash>();
             // Id
-            yield return new object[]
-            {
+            data.Add(
                 "$PBKDF2",
-                new PasswordHash("PBKDF2", Array.Empty<byte>())
-            };
+                new PasswordHash("PBKDF2", Array.Empty<byte>()));
 
             // 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<string, string>()
                     {
                         { "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<byte>(),
-                    new Dictionary<string, string>())
-            };
+                    new Dictionary<string, string>()));
 
             // Id + salt + hash
-            yield return new object[]
-            {
+            data.Add(
                 "$PBKDF2$69F420$62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D",
                 new PasswordHash(
                     "PBKDF2",
                     Convert.FromHexString("62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D"),
                     Convert.FromHexString("69F420"),
-                    new Dictionary<string, string>())
-            };
+                    new Dictionary<string, string>()));
 
             // 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<string, string>()
                     {
                         { "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]

+ 29 - 9
tests/Jellyfin.Extensions.Tests/CopyToExtensionsTests.cs

@@ -6,10 +6,17 @@ namespace Jellyfin.Extensions.Tests
 {
     public static class CopyToExtensionsTests
     {
-        public static IEnumerable<object[]> CopyTo_Valid_Correct_TestData()
+        public static TheoryData<IReadOnlyList<int>, IList<int>, int, IList<int>> 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<IReadOnlyList<int>, IList<int>, int, IList<int>>();
+
+            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<object[]> CopyTo_Invalid_ThrowsArgumentOutOfRangeException_TestData()
+        public static TheoryData<IReadOnlyList<int>, IList<int>, 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<int>(), 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<IReadOnlyList<int>, IList<int>, 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<int>(), 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]

+ 12 - 14
tests/Jellyfin.MediaEncoding.Tests/EncoderValidatorTests.cs

@@ -34,23 +34,21 @@ namespace Jellyfin.MediaEncoding.Tests
             Assert.Equal(valid, _encoderValidator.ValidateVersionInternal(versionOutput));
         }
 
-        private class GetFFmpegVersionTestData : IEnumerable<object?[]>
+        private class GetFFmpegVersionTestData : TheoryData<string, Version?>
         {
-            public IEnumerator<object?[]> 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();
         }
     }
 }

+ 7 - 5
tests/Jellyfin.MediaEncoding.Tests/Subtitles/SsaParserTests.cs

@@ -38,10 +38,11 @@ namespace Jellyfin.MediaEncoding.Subtitles.Tests
             }
         }
 
-        public static IEnumerable<object[]> Parse_MultipleDialogues_TestData()
+        public static TheoryData<string, IReadOnlyList<SubtitleTrackEvent>> Parse_MultipleDialogues_TestData()
         {
-            yield return new object[]
-            {
+            var data = new TheoryData<string, IReadOnlyList<SubtitleTrackEvent>>();
+
+            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]

+ 48 - 53
tests/Jellyfin.Model.Tests/Entities/MediaStreamTests.cs

@@ -6,12 +6,11 @@ namespace Jellyfin.Model.Tests.Entities
 {
     public class MediaStreamTests
     {
-        public static IEnumerable<object[]> Get_DisplayTitle_TestData()
+        public static TheoryData<MediaStream, string> Get_DisplayTitle_TestData()
         {
-            return new List<object[]>
-            {
-                new object[]
-                {
+            var data = new TheoryData<MediaStream, string>();
+
+            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]

+ 13 - 13
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<object[]> Resolve_ValidFileNameTestData()
+        public static TheoryData<AudioBookFileInfo> Resolve_ValidFileNameTestData()
         {
-            yield return new object[]
-            {
+            var data = new TheoryData<AudioBookFileInfo>();
+
+            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]

+ 51 - 65
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<object[]> ResolveFile_ValidFileNameTestData()
+        public static TheoryData<VideoFileInfo> ResolveFile_ValidFileNameTestData()
         {
-            yield return new object[]
-            {
+            var data = new TheoryData<VideoFileInfo>();
+            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]

+ 8 - 6
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<object[]> AddExternalSubtitleStreams_GivenMixedFilenames_ReturnsValidSubtitles_TestData()
+        public static TheoryData<List<MediaStream>, string, int, string[], MediaStream[]> AddExternalSubtitleStreams_GivenMixedFilenames_ReturnsValidSubtitles_TestData()
         {
+            var data = new TheoryData<List<MediaStream>, string, int, string[], MediaStream[]>();
+
             var index = 0;
-            yield return new object[]
-            {
+            data.Add(
                 new List<MediaStream>(),
                 "/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]

+ 44 - 56
tests/Jellyfin.Server.Implementations.Tests/Data/SqliteItemRepositoryTests.cs

@@ -32,10 +32,11 @@ namespace Jellyfin.Server.Implementations.Tests.Data
             _sqliteItemRepository = _fixture.Create<SqliteItemRepository>();
         }
 
-        public static IEnumerable<object[]> ItemImageInfoFromValueString_Valid_TestData()
+        public static TheoryData<string, ItemImageInfo> ItemImageInfoFromValueString_Valid_TestData()
         {
-            yield return new object[]
-            {
+            var data = new TheoryData<string, ItemImageInfo>();
+
+            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<object[]> DeserializeImages_Valid_TestData()
+        public static TheoryData<string, ItemImageInfo[]> DeserializeImages_Valid_TestData()
         {
-            yield return new object[]
-            {
+            var data = new TheoryData<string, ItemImageInfo[]>();
+            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<object[]> DeserializeImages_ValidAndInvalid_TestData()
+        public static TheoryData<string, ItemImageInfo[]> DeserializeImages_ValidAndInvalid_TestData()
         {
-            yield return new object[]
-            {
+            var data = new TheoryData<string, ItemImageInfo[]>();
+            data.Add(
                 string.Empty,
-                Array.Empty<ItemImageInfo>()
-            };
+                Array.Empty<ItemImageInfo>());
 
-            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<ItemImageInfo>()
-            };
+                Array.Empty<ItemImageInfo>());
+
+            return data;
         }
 
         [Theory]
@@ -242,30 +232,27 @@ namespace Jellyfin.Server.Implementations.Tests.Data
             Assert.Equal(expected, _sqliteItemRepository.SerializeImages(value));
         }
 
-        public static IEnumerable<object[]> DeserializeProviderIds_Valid_TestData()
+        public static TheoryData<string, Dictionary<string, string>> DeserializeProviderIds_Valid_TestData()
         {
-            yield return new object[]
-            {
+            var data = new TheoryData<string, Dictionary<string, string>>();
+
+            data.Add(
                 "Imdb=tt0119567",
                 new Dictionary<string, string>()
                 {
                     { "Imdb", "tt0119567" },
-                }
-            };
+                });
 
-            yield return new object[]
-            {
+            data.Add(
                 "Imdb=tt0119567|Tmdb=330|TmdbCollection=328",
                 new Dictionary<string, string>()
                 {
                     { "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<string, string>()
                 {
@@ -274,8 +261,9 @@ namespace Jellyfin.Server.Implementations.Tests.Data
                     { "AudioDbArtist", "111352" },
                     { "AudioDbAlbum", "2116560" },
                     { "MusicBrainzAlbumArtist", "20244d07-534f-4eff-b4d4-930878889970" },
-                }
-            };
+                });
+
+            return data;
         }
 
         [Theory]

+ 21 - 37
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<object[]> GetRecordingName_Success_TestData()
+        public static TheoryData<string, TimerInfo> GetRecordingName_Success_TestData()
         {
-            yield return new object[]
-            {
+            var data = new TheoryData<string, TimerInfo>();
+
+            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]

+ 61 - 91
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<ArgumentNullException>(() => 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<object?[]>
+        private class EpisodeBadData : TheoryData<BaseItem?, BaseItem?>
         {
-            public IEnumerator<object?[]> 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<object?[]>
+        private class EpisodeTestData : TheoryData<BaseItem, BaseItem, int>
         {
-            public IEnumerator<object?[]> 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();
         }
     }
 }