EpisodeResolverTest.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using Emby.Naming.Common;
  2. using Emby.Server.Implementations.Library.Resolvers.TV;
  3. using MediaBrowser.Controller;
  4. using MediaBrowser.Controller.Entities;
  5. using MediaBrowser.Controller.Entities.TV;
  6. using MediaBrowser.Controller.Library;
  7. using MediaBrowser.Controller.Providers;
  8. using MediaBrowser.Model.Entities;
  9. using MediaBrowser.Model.IO;
  10. using Moq;
  11. using Xunit;
  12. namespace Jellyfin.Server.Implementations.Tests.Library
  13. {
  14. public class EpisodeResolverTest
  15. {
  16. private static readonly NamingOptions _namingOptions = new();
  17. [Fact]
  18. public void Resolve_GivenVideoInExtrasFolder_DoesNotResolveToEpisode()
  19. {
  20. var parent = new Folder { Name = "extras" };
  21. var episodeResolver = new EpisodeResolver(_namingOptions);
  22. var itemResolveArgs = new ItemResolveArgs(
  23. Mock.Of<IServerApplicationPaths>(),
  24. Mock.Of<IDirectoryService>())
  25. {
  26. Parent = parent,
  27. CollectionType = CollectionType.TvShows,
  28. FileInfo = new FileSystemMetadata
  29. {
  30. FullName = "All My Children/Season 01/Extras/All My Children S01E01 - Behind The Scenes.mkv"
  31. }
  32. };
  33. Assert.Null(episodeResolver.Resolve(itemResolveArgs));
  34. }
  35. [Fact]
  36. public void Resolve_GivenVideoInExtrasSeriesFolder_ResolvesToEpisode()
  37. {
  38. var series = new Series { Name = "Extras" };
  39. // Have to create a mock because of moq proxies not being castable to a concrete implementation
  40. // https://github.com/jellyfin/jellyfin/blob/ab0cff8556403e123642dc9717ba778329554634/Emby.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs#L48
  41. var episodeResolver = new EpisodeResolverMock(_namingOptions);
  42. var itemResolveArgs = new ItemResolveArgs(
  43. Mock.Of<IServerApplicationPaths>(),
  44. Mock.Of<IDirectoryService>())
  45. {
  46. Parent = series,
  47. CollectionType = CollectionType.TvShows,
  48. FileInfo = new FileSystemMetadata
  49. {
  50. FullName = "Extras/Extras S01E01.mkv"
  51. }
  52. };
  53. Assert.NotNull(episodeResolver.Resolve(itemResolveArgs));
  54. }
  55. private class EpisodeResolverMock : EpisodeResolver
  56. {
  57. public EpisodeResolverMock(NamingOptions namingOptions) : base(namingOptions)
  58. {
  59. }
  60. protected override TVideoType ResolveVideo<TVideoType>(ItemResolveArgs args, bool parseName) => new();
  61. }
  62. }
  63. }