2020-11-01 09:47:31 +00:00
|
|
|
using System;
|
2020-10-12 18:09:15 +00:00
|
|
|
using System.Collections.Generic;
|
2020-09-08 23:57:09 +00:00
|
|
|
using Emby.Naming.AudioBook;
|
|
|
|
using Emby.Naming.Common;
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
namespace Jellyfin.Naming.Tests.AudioBook
|
|
|
|
{
|
|
|
|
public class AudioBookResolverTests
|
|
|
|
{
|
|
|
|
private readonly NamingOptions _namingOptions = new NamingOptions();
|
|
|
|
|
|
|
|
public static IEnumerable<object[]> GetResolveFileTestData()
|
|
|
|
{
|
|
|
|
yield return new object[]
|
|
|
|
{
|
2020-11-01 09:47:31 +00:00
|
|
|
new AudioBookFileInfo(
|
|
|
|
@"/server/AudioBooks/Larry Potter/Larry Potter.mp3",
|
|
|
|
"mp3")
|
2020-09-08 23:57:09 +00:00
|
|
|
};
|
|
|
|
yield return new object[]
|
|
|
|
{
|
2020-11-01 09:47:31 +00:00
|
|
|
new AudioBookFileInfo(
|
|
|
|
@"/server/AudioBooks/Berry Potter/Chapter 1 .ogg",
|
|
|
|
"ogg",
|
|
|
|
chapterNumber: 1)
|
2020-09-08 23:57:09 +00:00
|
|
|
};
|
|
|
|
yield return new object[]
|
|
|
|
{
|
2020-11-01 09:47:31 +00:00
|
|
|
new AudioBookFileInfo(
|
|
|
|
@"/server/AudioBooks/Nerry Potter/Part 3 - Chapter 2.mp3",
|
|
|
|
"mp3",
|
|
|
|
chapterNumber: 2,
|
|
|
|
partNumber: 3)
|
2020-09-08 23:57:09 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-01 16:10:48 +00:00
|
|
|
public static IEnumerable<object[]> GetPathsWithInvalidExtensions()
|
|
|
|
{
|
|
|
|
yield return new object[] { @"/server/AudioBooks/Larry Potter/Larry Potter.mp9" };
|
|
|
|
}
|
|
|
|
|
2020-09-08 23:57:09 +00:00
|
|
|
[Theory]
|
|
|
|
[MemberData(nameof(GetResolveFileTestData))]
|
2020-10-12 18:09:15 +00:00
|
|
|
public void Resolve_ValidFileName_Success(AudioBookFileInfo expectedResult)
|
2020-09-08 23:57:09 +00:00
|
|
|
{
|
|
|
|
var result = new AudioBookResolver(_namingOptions).Resolve(expectedResult.Path);
|
|
|
|
|
|
|
|
Assert.NotNull(result);
|
2020-10-12 18:09:15 +00:00
|
|
|
Assert.Equal(result!.Path, expectedResult.Path);
|
|
|
|
Assert.Equal(result!.Container, expectedResult.Container);
|
|
|
|
Assert.Equal(result!.ChapterNumber, expectedResult.ChapterNumber);
|
|
|
|
Assert.Equal(result!.PartNumber, expectedResult.PartNumber);
|
2020-11-01 16:10:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
[MemberData(nameof(GetPathsWithInvalidExtensions))]
|
|
|
|
public void Resolve_InvalidExtension(string path)
|
|
|
|
{
|
|
|
|
var result = new AudioBookResolver(_namingOptions).Resolve(path);
|
|
|
|
|
|
|
|
Assert.Null(result);
|
2020-10-12 18:09:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
2020-11-01 16:10:48 +00:00
|
|
|
public void Resolve_EmptyFileName()
|
2020-10-12 18:09:15 +00:00
|
|
|
{
|
2020-11-01 16:10:48 +00:00
|
|
|
var result = new AudioBookResolver(_namingOptions).Resolve(string.Empty);
|
|
|
|
|
|
|
|
Assert.Null(result);
|
2020-09-08 23:57:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|