From 1d367712bb2ec87a1d36f9b23deb2c0ad5fa7279 Mon Sep 17 00:00:00 2001 From: Joe Rogers <1337joe@gmail.com> Date: Mon, 28 Feb 2022 10:00:23 -0700 Subject: [PATCH] Improve tests --- .../MediaInfo/MediaInfoResolverTests.cs | 42 +++++++++++++++---- .../Test Data/Video/My.Video.mkv | 0 2 files changed, 34 insertions(+), 8 deletions(-) delete mode 100644 tests/Jellyfin.Providers.Tests/Test Data/Video/My.Video.mkv diff --git a/tests/Jellyfin.Providers.Tests/MediaInfo/MediaInfoResolverTests.cs b/tests/Jellyfin.Providers.Tests/MediaInfo/MediaInfoResolverTests.cs index 9cc6e5e994..89deb39140 100644 --- a/tests/Jellyfin.Providers.Tests/MediaInfo/MediaInfoResolverTests.cs +++ b/tests/Jellyfin.Providers.Tests/MediaInfo/MediaInfoResolverTests.cs @@ -64,10 +64,8 @@ public class MediaInfoResolverTests _subtitleResolver = new SubtitleResolver(_localizationManager, mediaEncoder.Object, new NamingOptions()); } - [Theory] - [InlineData("https://url.com/My.Video.mkv")] - [InlineData("non-existent/path")] - public void GetExternalFiles_BadPaths_ReturnsNoSubtitles(string path) + [Fact] + public void GetExternalFiles_BadProtocol_ReturnsNoSubtitles() { // need a media source manager capable of returning something other than file protocol var mediaSourceManager = new Mock(); @@ -77,12 +75,41 @@ public class MediaInfoResolverTests var video = new Movie { - Path = path + Path = "https://url.com/My.Video.mkv" + }; + + Assert.Empty(_subtitleResolver.GetExternalFiles(video, Mock.Of(), false)); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public void GetExternalFiles_MissingDirectory_DirectoryNotQueried(bool metadataDirectory) + { + BaseItem.MediaSourceManager = Mock.Of(); + + var video = new Movie + { + Path = VideoDirectoryPath + "/My.Video.mkv" }; - var files = _subtitleResolver.GetExternalFiles(video, Mock.Of(), false); + string pathNotFoundRegex = metadataDirectory ? MetadataDirectoryRegex : VideoDirectoryRegex; + + var directoryService = new Mock(MockBehavior.Strict); + // any path other than test target exists and provides an empty listing + directoryService.Setup(ds => ds.PathExists(It.IsAny())) + .Returns(true); + directoryService.Setup(ds => ds.GetFilePaths(It.IsAny(), It.IsAny(), It.IsAny())) + .Returns(Array.Empty()); + + directoryService.Setup(ds => ds.PathExists(It.IsRegex(pathNotFoundRegex))) + .Returns(false); + + _subtitleResolver.GetExternalFiles(video, directoryService.Object, false); - Assert.Empty(files); + directoryService.Verify( + ds => ds.GetFilePaths(It.IsRegex(pathNotFoundRegex), It.IsAny(), It.IsAny()), + Times.Never); } [Theory] @@ -132,7 +159,6 @@ public class MediaInfoResolverTests [Theory] [InlineData("https://url.com/My.Video.mkv")] - [InlineData("non-existent/path")] [InlineData(VideoDirectoryPath)] // valid but no files found for this test public async void GetExternalStreams_BadPaths_ReturnsNoSubtitles(string path) { diff --git a/tests/Jellyfin.Providers.Tests/Test Data/Video/My.Video.mkv b/tests/Jellyfin.Providers.Tests/Test Data/Video/My.Video.mkv deleted file mode 100644 index e69de29bb2..0000000000