100% branch coverage for Jellyfin.Naming

This commit is contained in:
Bond_009
2021-01-21 15:45:54 +01:00
parent 215554bb41
commit 956ca0e5aa
5 changed files with 33 additions and 80 deletions

View File

@@ -15,13 +15,13 @@ namespace Emby.Naming.AudioBook
/// <param name="files">List of files composing the actual audiobook.</param>
/// <param name="extras">List of extra files.</param>
/// <param name="alternateVersions">Alternative version of files.</param>
public AudioBookInfo(string name, int? year, List<AudioBookFileInfo>? files, List<AudioBookFileInfo>? extras, List<AudioBookFileInfo>? alternateVersions)
public AudioBookInfo(string name, int? year, List<AudioBookFileInfo> files, List<AudioBookFileInfo> extras, List<AudioBookFileInfo> alternateVersions)
{
Name = name;
Year = year;
Files = files ?? new List<AudioBookFileInfo>();
Extras = extras ?? new List<AudioBookFileInfo>();
AlternateVersions = alternateVersions ?? new List<AudioBookFileInfo>();
Files = files;
Extras = extras;
AlternateVersions = alternateVersions;
}
/// <summary>

View File

@@ -185,8 +185,8 @@ namespace Emby.Naming.Video
if (!string.IsNullOrEmpty(folderName)
&& folderName.Length > 1
&& videos.All(i => i.Files.Count == 1
&& IsEligibleForMultiVersion(folderName, i.Files[0].Path))
&& HaveSameYear(videos))
&& IsEligibleForMultiVersion(folderName, i.Files[0].Path))
&& HaveSameYear(videos))
{
var ordered = videos.OrderBy(i => i.Name).ToList();
@@ -216,10 +216,9 @@ namespace Emby.Naming.Video
return videos.Select(i => i.Year ?? -1).Distinct().Count() < 2;
}
private bool IsEligibleForMultiVersion(string folderName, string? testFilename)
private bool IsEligibleForMultiVersion(string folderName, string testFilePath)
{
testFilename = Path.GetFileNameWithoutExtension(testFilename) ?? string.Empty;
string testFilename = Path.GetFileNameWithoutExtension(testFilePath);
if (testFilename.StartsWith(folderName, StringComparison.OrdinalIgnoreCase))
{
if (CleanStringParser.TryClean(testFilename, _options.CleanStringRegexes, out var cleanName))
@@ -233,8 +232,8 @@ namespace Emby.Naming.Video
}
return string.IsNullOrEmpty(testFilename)
|| testFilename[0].Equals('-')
|| testFilename[0].Equals('_')
|| testFilename[0] == '-'
|| testFilename[0] == '_'
|| string.IsNullOrWhiteSpace(Regex.Replace(testFilename, @"\[([^]]*)\]", string.Empty));
}

View File

@@ -125,7 +125,7 @@ namespace Emby.Naming.Video
/// <returns>True if is video file.</returns>
public bool IsVideoFile(string path)
{
var extension = Path.GetExtension(path) ?? string.Empty;
var extension = Path.GetExtension(path);
return _options.VideoFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase);
}
@@ -136,7 +136,7 @@ namespace Emby.Naming.Video
/// <returns>True if is video file stub.</returns>
public bool IsStubFile(string path)
{
var extension = Path.GetExtension(path) ?? string.Empty;
var extension = Path.GetExtension(path);
return _options.StubFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase);
}