AudioBookResolverTests.cs 2.1 KB

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