mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-07-09 07:10:34 +02:00
Written test to finish coverage for AudioBookListResolver & AudioBookResolver and corrected some logical erros / unhandled exception
This commit is contained in:
parent
e7a37bedfc
commit
f39775dc3a
|
@ -1,6 +1,8 @@
|
||||||
#pragma warning disable CS1591
|
#pragma warning disable CS1591
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Emby.Naming.Common;
|
using Emby.Naming.Common;
|
||||||
using Emby.Naming.Video;
|
using Emby.Naming.Video;
|
||||||
|
@ -21,25 +23,27 @@ namespace Emby.Naming.AudioBook
|
||||||
{
|
{
|
||||||
var audioBookResolver = new AudioBookResolver(_options);
|
var audioBookResolver = new AudioBookResolver(_options);
|
||||||
|
|
||||||
|
// File with empty fullname will be sorted out here
|
||||||
var audiobookFileInfos = files
|
var audiobookFileInfos = files
|
||||||
.Select(i => audioBookResolver.Resolve(i.FullName))
|
.Select(i => audioBookResolver.Resolve(i.FullName))
|
||||||
.OfType<AudioBookFileInfo>()
|
.OfType<AudioBookFileInfo>()
|
||||||
.ToList();
|
.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)
|
var stackResult = new StackResolver(_options)
|
||||||
.ResolveAudioBooks(audiobookFileInfos);
|
.ResolveAudioBooks(audiobookFileInfos);
|
||||||
|
|
||||||
foreach (var stack in stackResult)
|
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();
|
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;
|
yield return info;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,8 @@ namespace Emby.Naming.AudioBook
|
||||||
{
|
{
|
||||||
if (path.Length == 0)
|
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);
|
var extension = Path.GetExtension(path);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Linq;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using Emby.Naming.AudioBook;
|
using Emby.Naming.AudioBook;
|
||||||
using Emby.Naming.Common;
|
using Emby.Naming.Common;
|
||||||
using MediaBrowser.Model.IO;
|
using MediaBrowser.Model.IO;
|
||||||
|
@ -82,6 +83,41 @@ namespace Jellyfin.Naming.Tests.AudioBook
|
||||||
Assert.Single(result);
|
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()
|
private AudioBookListResolver GetResolver()
|
||||||
{
|
{
|
||||||
return new AudioBookListResolver(_namingOptions);
|
return new AudioBookListResolver(_namingOptions);
|
||||||
|
|
|
@ -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]
|
[Theory]
|
||||||
[MemberData(nameof(GetResolveFileTestData))]
|
[MemberData(nameof(GetResolveFileTestData))]
|
||||||
public void Resolve_ValidFileName_Success(AudioBookFileInfo expectedResult)
|
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!.Container, expectedResult.Container);
|
||||||
Assert.Equal(result!.ChapterNumber, expectedResult.ChapterNumber);
|
Assert.Equal(result!.ChapterNumber, expectedResult.ChapterNumber);
|
||||||
Assert.Equal(result!.PartNumber, expectedResult.PartNumber);
|
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]
|
[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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue