aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStepan <ste.martinek+git@gmail.com>2020-11-01 17:10:48 +0100
committerStepan <ste.martinek+git@gmail.com>2020-11-01 17:10:48 +0100
commitf39775dc3a813609454655c31dd5c6a1413cc890 (patch)
tree29a7415e8be89341e8b7c9a0a77e521f6ba44432
parente7a37bedfca159ab6a305833395aead07ccd872f (diff)
Written test to finish coverage for AudioBookListResolver & AudioBookResolver and corrected some logical erros / unhandled exception
-rw-r--r--Emby.Naming/AudioBook/AudioBookListResolver.cs20
-rw-r--r--Emby.Naming/AudioBook/AudioBookResolver.cs3
-rw-r--r--tests/Jellyfin.Naming.Tests/AudioBook/AudioBookListResolverTests.cs38
-rw-r--r--tests/Jellyfin.Naming.Tests/AudioBook/AudioBookResolverTests.cs21
4 files changed, 69 insertions, 13 deletions
diff --git a/Emby.Naming/AudioBook/AudioBookListResolver.cs b/Emby.Naming/AudioBook/AudioBookListResolver.cs
index 0d190c172..795065a6c 100644
--- a/Emby.Naming/AudioBook/AudioBookListResolver.cs
+++ b/Emby.Naming/AudioBook/AudioBookListResolver.cs
@@ -1,6 +1,8 @@
#pragma warning disable CS1591
+using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using Emby.Naming.Common;
using Emby.Naming.Video;
@@ -21,25 +23,27 @@ namespace Emby.Naming.AudioBook
{
var audioBookResolver = new AudioBookResolver(_options);
+ // File with empty fullname will be sorted out here
var audiobookFileInfos = files
.Select(i => audioBookResolver.Resolve(i.FullName))
.OfType<AudioBookFileInfo>()
.ToList();
- // Filter out all extras, otherwise they could cause stacks to not be resolved
- // See the unit test TestStackedWithTrailer
- var metadata = audiobookFileInfos
- .Select(i => new FileSystemMetadata { FullName = i.Path, IsDirectory = false });
-
var stackResult = new StackResolver(_options)
.ResolveAudioBooks(audiobookFileInfos);
foreach (var stack in stackResult)
{
- var stackFiles = stack.Files.Select(i => audioBookResolver.Resolve(i)).OfType<AudioBookFileInfo>().ToList();
+ var stackFiles = stack.Files
+ .Select(i => audioBookResolver.Resolve(i))
+ .OfType<AudioBookFileInfo>()
+ .ToList();
+
stackFiles.Sort();
- // TODO nullable discover if name can be empty
- var info = new AudioBookInfo(stack.Name ?? string.Empty) { Files = stackFiles };
+
+ // stack.Name can be empty when we have file without folder, but always have some files
+ var name = string.IsNullOrEmpty(stack.Name) ? stack.Files[0] : stack.Name;
+ var info = new AudioBookInfo(name) { Files = stackFiles };
yield return info;
}
diff --git a/Emby.Naming/AudioBook/AudioBookResolver.cs b/Emby.Naming/AudioBook/AudioBookResolver.cs
index c9e8c76cb..542d6fee5 100644
--- a/Emby.Naming/AudioBook/AudioBookResolver.cs
+++ b/Emby.Naming/AudioBook/AudioBookResolver.cs
@@ -21,7 +21,8 @@ namespace Emby.Naming.AudioBook
{
if (path.Length == 0)
{
- throw new ArgumentException("String can't be empty.", nameof(path));
+ // Return null to indicate this path will not be used, instead of stopping whole process with exception
+ return null;
}
var extension = Path.GetExtension(path);
diff --git a/tests/Jellyfin.Naming.Tests/AudioBook/AudioBookListResolverTests.cs b/tests/Jellyfin.Naming.Tests/AudioBook/AudioBookListResolverTests.cs
index 1084e20bd..d912b0e90 100644
--- a/tests/Jellyfin.Naming.Tests/AudioBook/AudioBookListResolverTests.cs
+++ b/tests/Jellyfin.Naming.Tests/AudioBook/AudioBookListResolverTests.cs
@@ -1,4 +1,5 @@
-using System.Linq;
+using System;
+using System.Linq;
using Emby.Naming.AudioBook;
using Emby.Naming.Common;
using MediaBrowser.Model.IO;
@@ -82,6 +83,41 @@ namespace Jellyfin.Naming.Tests.AudioBook
Assert.Single(result);
}
+ [Fact]
+ public void TestWithoutFolder()
+ {
+ var files = new[]
+ {
+ "Harry Potter and the Deathly Hallows trailer.mp3"
+ };
+
+ var resolver = GetResolver();
+
+ var result = resolver.Resolve(files.Select(i => new FileSystemMetadata
+ {
+ IsDirectory = false,
+ FullName = i
+ })).ToList();
+
+ Assert.Single(result);
+ }
+
+ [Fact]
+ public void TestEmpty()
+ {
+ var files = Array.Empty<string>();
+
+ var resolver = GetResolver();
+
+ var result = resolver.Resolve(files.Select(i => new FileSystemMetadata
+ {
+ IsDirectory = false,
+ FullName = i
+ })).ToList();
+
+ Assert.Empty(result);
+ }
+
private AudioBookListResolver GetResolver()
{
return new AudioBookListResolver(_namingOptions);
diff --git a/tests/Jellyfin.Naming.Tests/AudioBook/AudioBookResolverTests.cs b/tests/Jellyfin.Naming.Tests/AudioBook/AudioBookResolverTests.cs
index 2708d80bb..282da2b93 100644
--- a/tests/Jellyfin.Naming.Tests/AudioBook/AudioBookResolverTests.cs
+++ b/tests/Jellyfin.Naming.Tests/AudioBook/AudioBookResolverTests.cs
@@ -35,6 +35,11 @@ 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))]
public void Resolve_ValidFileName_Success(AudioBookFileInfo expectedResult)
@@ -46,13 +51,23 @@ namespace Jellyfin.Naming.Tests.AudioBook
Assert.Equal(result!.Container, expectedResult.Container);
Assert.Equal(result!.ChapterNumber, expectedResult.ChapterNumber);
Assert.Equal(result!.PartNumber, expectedResult.PartNumber);
- Assert.Equal(result!.IsDirectory, expectedResult.IsDirectory);
+ }
+
+ [Theory]
+ [MemberData(nameof(GetPathsWithInvalidExtensions))]
+ public void Resolve_InvalidExtension(string path)
+ {
+ var result = new AudioBookResolver(_namingOptions).Resolve(path);
+
+ Assert.Null(result);
}
[Fact]
- public void Resolve_EmptyFileName_ArgumentException()
+ public void Resolve_EmptyFileName()
{
- Assert.Throws<ArgumentException>(() => new AudioBookResolver(_namingOptions).Resolve(string.Empty));
+ var result = new AudioBookResolver(_namingOptions).Resolve(string.Empty);
+
+ Assert.Null(result);
}
}
}