浏览代码

Simplify Resolve_InvalidExtension Test and created tests for Alternative Versions parsing & Year Extraction for audiobooks

Stepan 4 年之前
父节点
当前提交
50a2ef9d8a

+ 58 - 0
tests/Jellyfin.Naming.Tests/AudioBook/AudioBookListResolverTests.cs

@@ -43,6 +43,64 @@ namespace Jellyfin.Naming.Tests.AudioBook
             Assert.Equal("Batman", result[1].Name);
         }
 
+        [Fact]
+        public void TestAlternativeVersions()
+        {
+            var files = new[]
+            {
+                "Harry Potter and the Deathly Hallows/Chapter 1.ogg",
+                "Harry Potter and the Deathly Hallows/Chapter 1.mp3",
+
+                "Deadpool.ogg",
+                "Deadpool.mp3",
+
+                "Batman/Chapter 1.mp3"
+            };
+
+            var resolver = GetResolver();
+
+            var result = resolver.Resolve(files.Select(i => new FileSystemMetadata
+            {
+                IsDirectory = false,
+                FullName = i
+            })).ToList();
+
+            Assert.Equal(3, result[0].Files.Count);
+            Assert.NotEmpty(result[0].AlternateVersions);
+            Assert.NotEmpty(result[1].AlternateVersions);
+            Assert.Empty(result[2].AlternateVersions);
+        }
+
+        [Fact]
+        public void TestYearExtraction()
+        {
+            var files = new[]
+            {
+                "Harry Potter and the Deathly Hallows (2007)/Chapter 1.ogg",
+                "Harry Potter and the Deathly Hallows (2007)/Chapter 2.mp3",
+
+                "Batman (2020).ogg",
+
+                "Batman(2021).mp3",
+
+                "Batman.mp3"
+            };
+
+            var resolver = GetResolver();
+
+            var result = resolver.Resolve(files.Select(i => new FileSystemMetadata
+            {
+                IsDirectory = false,
+                FullName = i
+            })).ToList();
+
+            Assert.Equal(3, result[0].Files.Count);
+            Assert.Equal(2007, result[0].Year);
+            Assert.Equal(2020, result[1].Year);
+            Assert.Equal(2021, result[2].Year);
+            Assert.Null(result[2].Year);
+        }
+
         [Fact]
         public void TestWithMetadata()
         {

+ 3 - 8
tests/Jellyfin.Naming.Tests/AudioBook/AudioBookResolverTests.cs

@@ -35,10 +35,6 @@ namespace Jellyfin.Naming.Tests.AudioBook
             };
         }
 
-        public static IEnumerable<object[]> GetPathsWithInvalidExtensions()
-        {
-            yield return new object[] { @"/server/AudioBooks/Larry Potter/Larry Potter.mp9" };
-        }
 
         [Theory]
         [MemberData(nameof(GetResolveFileTestData))]
@@ -53,11 +49,10 @@ namespace Jellyfin.Naming.Tests.AudioBook
             Assert.Equal(result!.PartNumber, expectedResult.PartNumber);
         }
 
-        [Theory]
-        [MemberData(nameof(GetPathsWithInvalidExtensions))]
-        public void Resolve_InvalidExtension(string path)
+        [Fact]
+        public void Resolve_InvalidExtension()
         {
-            var result = new AudioBookResolver(_namingOptions).Resolve(path);
+            var result = new AudioBookResolver(_namingOptions).Resolve(@"/server/AudioBooks/Larry Potter/Larry Potter.mp9");
 
             Assert.Null(result);
         }