AudioBookResolverTests.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System.Collections.Generic;
  2. using Emby.Naming.AudioBook;
  3. using Emby.Naming.Common;
  4. using Xunit;
  5. namespace Jellyfin.Naming.Tests.AudioBook
  6. {
  7. public class AudioBookResolverTests
  8. {
  9. private readonly NamingOptions _namingOptions = new NamingOptions();
  10. public static TheoryData<AudioBookFileInfo> Resolve_ValidFileNameTestData()
  11. {
  12. var data = new TheoryData<AudioBookFileInfo>();
  13. data.Add(
  14. new AudioBookFileInfo(
  15. @"/server/AudioBooks/Larry Potter/Larry Potter.mp3",
  16. "mp3"));
  17. data.Add(
  18. new AudioBookFileInfo(
  19. @"/server/AudioBooks/Berry Potter/Chapter 1 .ogg",
  20. "ogg",
  21. chapterNumber: 1));
  22. data.Add(
  23. new AudioBookFileInfo(
  24. @"/server/AudioBooks/Nerry Potter/Part 3 - Chapter 2.mp3",
  25. "mp3",
  26. chapterNumber: 2,
  27. partNumber: 3));
  28. return data;
  29. }
  30. [Theory]
  31. [MemberData(nameof(Resolve_ValidFileNameTestData))]
  32. public void Resolve_ValidFileName_Success(AudioBookFileInfo expectedResult)
  33. {
  34. var result = new AudioBookResolver(_namingOptions).Resolve(expectedResult.Path);
  35. Assert.NotNull(result);
  36. Assert.Equal(result!.Path, expectedResult.Path);
  37. Assert.Equal(result!.Container, expectedResult.Container);
  38. Assert.Equal(result!.ChapterNumber, expectedResult.ChapterNumber);
  39. Assert.Equal(result!.PartNumber, expectedResult.PartNumber);
  40. }
  41. [Fact]
  42. public void Resolve_InvalidExtension()
  43. {
  44. var result = new AudioBookResolver(_namingOptions).Resolve(@"/server/AudioBooks/Larry Potter/Larry Potter.mp9");
  45. Assert.Null(result);
  46. }
  47. [Fact]
  48. public void Resolve_EmptyFileName()
  49. {
  50. var result = new AudioBookResolver(_namingOptions).Resolve(string.Empty);
  51. Assert.Null(result);
  52. }
  53. }
  54. }