From 7f12b273197204c49862623b6de6b1a573af2cd8 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 13 Feb 2021 22:48:29 +0100 Subject: [PATCH] Add nfo location tests --- .../Properties/AssemblyInfo.cs | 2 + .../Location/MovieNfoLocationTests.cs | 65 +++++++++++++++++++ .../Test Data/Imdb.nfo | 1 + .../Test Data/Tmdb.nfo | 1 + .../Test Data/Tvdb.nfo | 1 + 5 files changed, 70 insertions(+) create mode 100644 tests/Jellyfin.XbmcMetadata.Tests/Location/MovieNfoLocationTests.cs create mode 100644 tests/Jellyfin.XbmcMetadata.Tests/Test Data/Imdb.nfo create mode 100644 tests/Jellyfin.XbmcMetadata.Tests/Test Data/Tmdb.nfo create mode 100644 tests/Jellyfin.XbmcMetadata.Tests/Test Data/Tvdb.nfo diff --git a/MediaBrowser.XbmcMetadata/Properties/AssemblyInfo.cs b/MediaBrowser.XbmcMetadata/Properties/AssemblyInfo.cs index b3e2f2717..cfe06b940 100644 --- a/MediaBrowser.XbmcMetadata/Properties/AssemblyInfo.cs +++ b/MediaBrowser.XbmcMetadata/Properties/AssemblyInfo.cs @@ -1,5 +1,6 @@ using System.Reflection; using System.Resources; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following @@ -14,6 +15,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] [assembly: NeutralResourcesLanguage("en")] +[assembly: InternalsVisibleTo("Jellyfin.XbmcMetadata.Tests")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from diff --git a/tests/Jellyfin.XbmcMetadata.Tests/Location/MovieNfoLocationTests.cs b/tests/Jellyfin.XbmcMetadata.Tests/Location/MovieNfoLocationTests.cs new file mode 100644 index 000000000..357d61c0b --- /dev/null +++ b/tests/Jellyfin.XbmcMetadata.Tests/Location/MovieNfoLocationTests.cs @@ -0,0 +1,65 @@ +using System.Linq; +using MediaBrowser.Controller.Entities.Movies; +using MediaBrowser.Controller.Providers; +using MediaBrowser.Model.Entities; +using MediaBrowser.Model.System; +using MediaBrowser.XbmcMetadata.Savers; +using Xunit; + +namespace Jellyfin.XbmcMetadata.Tests.Location +{ + public class MovieNfoLocationTests + { + [Fact] + public static void Movie_MixedFolder_Success() + { + var movie = new Movie() { Path = "/media/movies/Avengers Endgame.mp4", IsInMixedFolder = true }; + + var paths = MovieNfoSaver.GetMovieSavePaths(new ItemInfo(movie)).ToArray(); + Assert.Single(paths); + Assert.Contains("/media/movies/Avengers Endgame.nfo", paths); + } + + [Fact] + public static void Movie_SeparateFolder_Success() + { + var movie = new Movie() { Path = "/media/movies/Avengers Endgame/Avengers Endgame.mp4" }; + var path1 = "/media/movies/Avengers Endgame/Avengers Endgame.nfo"; + var path2 = "/media/movies/Avengers Endgame/movie.nfo"; + + // uses ContainingFolderPath which uses Operating system specific paths + if (MediaBrowser.Common.System.OperatingSystem.Id == OperatingSystemId.Windows) + { + movie.Path = movie.Path.Replace('/', '\\'); + path1 = path1.Replace('/', '\\'); + path2 = path2.Replace('/', '\\'); + } + + var paths = MovieNfoSaver.GetMovieSavePaths(new ItemInfo(movie)).ToArray(); + Assert.Equal(2, paths.Length); + Assert.Contains(path1, paths); + Assert.Contains(path2, paths); + } + + [Fact] + public void Movie_DVD_Success() + { + var movie = new Movie() { Path = "/media/movies/Avengers Endgame", VideoType = VideoType.Dvd }; + var path1 = "/media/movies/Avengers Endgame/Avengers Endgame.nfo"; + var path2 = "/media/movies/Avengers Endgame/VIDEO_TS/VIDEO_TS.nfo"; + + // uses ContainingFolderPath which uses Operating system specific paths + if (MediaBrowser.Common.System.OperatingSystem.Id == OperatingSystemId.Windows) + { + movie.Path = movie.Path.Replace('/', '\\'); + path1 = path1.Replace('/', '\\'); + path2 = path2.Replace('/', '\\'); + } + + var paths = MovieNfoSaver.GetMovieSavePaths(new ItemInfo(movie)).ToArray(); + Assert.Equal(2, paths.Length); + Assert.Contains(path1, paths); + Assert.Contains(path2, paths); + } + } +} diff --git a/tests/Jellyfin.XbmcMetadata.Tests/Test Data/Imdb.nfo b/tests/Jellyfin.XbmcMetadata.Tests/Test Data/Imdb.nfo new file mode 100644 index 000000000..e30a1c660 --- /dev/null +++ b/tests/Jellyfin.XbmcMetadata.Tests/Test Data/Imdb.nfo @@ -0,0 +1 @@ +https://www.imdb.com/title/tt0944947/ diff --git a/tests/Jellyfin.XbmcMetadata.Tests/Test Data/Tmdb.nfo b/tests/Jellyfin.XbmcMetadata.Tests/Test Data/Tmdb.nfo new file mode 100644 index 000000000..15af71852 --- /dev/null +++ b/tests/Jellyfin.XbmcMetadata.Tests/Test Data/Tmdb.nfo @@ -0,0 +1 @@ +https://www.themoviedb.org/movie/30287-fallo diff --git a/tests/Jellyfin.XbmcMetadata.Tests/Test Data/Tvdb.nfo b/tests/Jellyfin.XbmcMetadata.Tests/Test Data/Tvdb.nfo new file mode 100644 index 000000000..9de69f8e1 --- /dev/null +++ b/tests/Jellyfin.XbmcMetadata.Tests/Test Data/Tvdb.nfo @@ -0,0 +1 @@ +https://www.thetvdb.com/?tab=series&id=121361