Bläddra i källkod

Taken suggestions from code review and created test for ExtraRuleType.Regex instead of throwing exception there.

Stepan 4 år sedan
förälder
incheckning
3bca1181b3

+ 3 - 2
Emby.Naming/AudioBook/AudioBookListResolver.cs

@@ -73,6 +73,7 @@ namespace Emby.Naming.AudioBook
 
             var haveChaptersOrPages = stackFiles.Any(x => x.ChapterNumber != null || x.PartNumber != null);
             var groupedBy = stackFiles.GroupBy(file => new { file.ChapterNumber, file.PartNumber });
+            var nameWithReplacedDots = nameParserResult.Name.Replace(" ", ".");
 
             foreach (var group in groupedBy)
             {
@@ -86,9 +87,9 @@ namespace Emby.Naming.AudioBook
                         foreach (var audioFile in group)
                         {
                             var name = Path.GetFileNameWithoutExtension(audioFile.Path);
-                            if (name == "audiobook" ||
+                            if (name.Equals("audiobook") ||
                                 name.Contains(nameParserResult.Name, StringComparison.OrdinalIgnoreCase) ||
-                                name.Contains(nameParserResult.Name.Replace(" ", "."), StringComparison.OrdinalIgnoreCase))
+                                name.Contains(nameWithReplacedDots, StringComparison.OrdinalIgnoreCase))
                             {
                                 alt.Add(audioFile);
                             }

+ 1 - 9
Emby.Naming/Video/ExtraResolver.cs

@@ -1,6 +1,7 @@
 using System;
 using System.IO;
 using System.Linq;
+using System.Text.RegularExpressions;
 using Emby.Naming.Audio;
 using Emby.Naming.Common;
 
@@ -52,11 +53,6 @@ namespace Emby.Naming.Video
                     return result;
                 }
             }
-            else
-            {
-                // Currently unreachable code if new rule.MediaType is desired add if clause with proper tests
-                throw new InvalidOperationException();
-            }
 
             if (rule.RuleType == ExtraRuleType.Filename)
             {
@@ -80,9 +76,6 @@ namespace Emby.Naming.Video
             }
             else if (rule.RuleType == ExtraRuleType.Regex)
             {
-                // Currently unreachable code if new rule.MediaType is desired add if clause with proper tests
-                throw new InvalidOperationException();
-                /*
                 var filename = Path.GetFileName(path);
 
                 var regex = new Regex(rule.Token, RegexOptions.IgnoreCase);
@@ -92,7 +85,6 @@ namespace Emby.Naming.Video
                     result.ExtraType = rule.ExtraType;
                     result.Rule = rule;
                 }
-                */
             }
             else if (rule.RuleType == ExtraRuleType.DirectoryName)
             {

+ 2 - 2
Emby.Naming/Video/VideoListResolver.cs

@@ -230,8 +230,8 @@ namespace Emby.Naming.Video
 
                 testFilename = testFilename.Substring(folderName.Length).Trim();
                 return string.IsNullOrEmpty(testFilename)
-                   || testFilename[0] == '-'
-                   || testFilename[0].Equals( '_')
+                   || testFilename[0].Equals('-')
+                   || testFilename[0].Equals('_')
                    || string.IsNullOrWhiteSpace(Regex.Replace(testFilename, @"\[([^]]*)\]", string.Empty));
             }
 

+ 3 - 1
tests/Jellyfin.Naming.Tests/Video/CleanDateTimeTests.cs

@@ -1,4 +1,4 @@
-using System.IO;
+using System.IO;
 using Emby.Naming.Common;
 using Emby.Naming.Video;
 using Xunit;
@@ -51,6 +51,8 @@ namespace Jellyfin.Naming.Tests.Video
         [InlineData("My Movie 2013-12-09", "My Movie 2013-12-09", null)]
         [InlineData("My Movie 20131209", "My Movie 20131209", null)]
         [InlineData("My Movie 2013-12-09 2013", "My Movie 2013-12-09", 2013)]
+        [InlineData(null, null, null)]
+        [InlineData("", "", null)]
         public void CleanDateTimeTest(string input, string expectedName, int? expectedYear)
         {
             input = Path.GetFileName(input);

+ 5 - 9
tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs

@@ -95,18 +95,14 @@ namespace Jellyfin.Naming.Tests.Video
             }
         }
 
-        [Fact]
-        public void TestExtraInfo_InvalidRuleMediaType()
-        {
-            var options = new NamingOptions { VideoExtraRules = new[] { new ExtraRule(ExtraType.Unknown, ExtraRuleType.DirectoryName, " ", MediaType.Photo) } };
-            Assert.Throws<InvalidOperationException>(() => GetExtraTypeParser(options).GetExtraInfo("sample.jpg"));
-        }
-
         [Fact]
         public void TestExtraInfo_InvalidRuleType()
         {
-            var options = new NamingOptions { VideoExtraRules = new[] { new ExtraRule(ExtraType.Unknown, ExtraRuleType.Regex, " ", MediaType.Video) } };
-            Assert.Throws<InvalidOperationException>(() => GetExtraTypeParser(options).GetExtraInfo("sample.mp4"));
+            var rule = new ExtraRule(ExtraType.Unknown, ExtraRuleType.Regex, @"([eE]x(tra)?\.\w+)", MediaType.Video);
+            var options = new NamingOptions { VideoExtraRules = new[] { rule } };
+            var res = GetExtraTypeParser(options).GetExtraInfo("extra.mp4");
+
+            Assert.Equal(rule, res.Rule);
         }
 
         [Fact]