parent
c8ab4f8c68
commit
dd5bc41eda
@ -0,0 +1,245 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using FizzWare.NBuilder;
|
||||||
|
using Moq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Common.Disk;
|
||||||
|
using NzbDrone.Common.Extensions;
|
||||||
|
using NzbDrone.Core.Configuration;
|
||||||
|
using NzbDrone.Core.Extras;
|
||||||
|
using NzbDrone.Core.Extras.Files;
|
||||||
|
using NzbDrone.Core.MediaFiles;
|
||||||
|
using NzbDrone.Core.Movies;
|
||||||
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.Extras
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class ExtraServiceFixture : CoreTest<ExtraService>
|
||||||
|
{
|
||||||
|
private Movie _movie;
|
||||||
|
private MovieFile _movieFile;
|
||||||
|
private LocalMovie _localMovie;
|
||||||
|
|
||||||
|
private string _movieFolder;
|
||||||
|
private string _releaseFolder;
|
||||||
|
|
||||||
|
private Mock<IManageExtraFiles> _subtitleService;
|
||||||
|
private Mock<IManageExtraFiles> _otherExtraService;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
_movieFolder = @"C:\Test\Movies\Movie Title".AsOsAgnostic();
|
||||||
|
_releaseFolder = @"C:\Test\Unsorted TV\Movie.Title.2022".AsOsAgnostic();
|
||||||
|
|
||||||
|
_movie = Builder<Movie>.CreateNew()
|
||||||
|
.With(s => s.Path = _movieFolder)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
_movieFile = Builder<MovieFile>.CreateNew()
|
||||||
|
.With(f => f.Path = Path.Combine(_movie.Path, "Movie Title - 2022.mkv").AsOsAgnostic())
|
||||||
|
.With(f => f.RelativePath = @"Movie Title - 2022.mkv".AsOsAgnostic())
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
_localMovie = Builder<LocalMovie>.CreateNew()
|
||||||
|
.With(l => l.Movie = _movie)
|
||||||
|
.With(l => l.Path = Path.Combine(_releaseFolder, "Movie.Title.2022.mkv").AsOsAgnostic())
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
_subtitleService = new Mock<IManageExtraFiles>();
|
||||||
|
_subtitleService.SetupGet(s => s.Order).Returns(0);
|
||||||
|
_subtitleService.Setup(s => s.CanImportFile(It.IsAny<LocalMovie>(), It.IsAny<MovieFile>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()))
|
||||||
|
.Returns(false);
|
||||||
|
_subtitleService.Setup(s => s.CanImportFile(It.IsAny<LocalMovie>(), It.IsAny<MovieFile>(), It.IsAny<string>(), ".srt", It.IsAny<bool>()))
|
||||||
|
.Returns(true);
|
||||||
|
|
||||||
|
_otherExtraService = new Mock<IManageExtraFiles>();
|
||||||
|
_otherExtraService.SetupGet(s => s.Order).Returns(1);
|
||||||
|
_otherExtraService.Setup(s => s.CanImportFile(It.IsAny<LocalMovie>(), It.IsAny<MovieFile>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()))
|
||||||
|
.Returns(true);
|
||||||
|
|
||||||
|
Mocker.SetConstant<IEnumerable<IManageExtraFiles>>(new[]
|
||||||
|
{
|
||||||
|
_subtitleService.Object,
|
||||||
|
_otherExtraService.Object
|
||||||
|
});
|
||||||
|
|
||||||
|
Mocker.GetMock<IDiskProvider>().Setup(s => s.FolderExists(It.IsAny<string>()))
|
||||||
|
.Returns(false);
|
||||||
|
|
||||||
|
Mocker.GetMock<IDiskProvider>().Setup(s => s.GetParentFolder(It.IsAny<string>()))
|
||||||
|
.Returns((string path) => Directory.GetParent(path).FullName);
|
||||||
|
|
||||||
|
WithExistingFolder(_movie.Path);
|
||||||
|
WithExistingFile(_movieFile.Path);
|
||||||
|
WithExistingFile(_localMovie.Path);
|
||||||
|
|
||||||
|
Mocker.GetMock<IConfigService>().Setup(v => v.ImportExtraFiles).Returns(true);
|
||||||
|
Mocker.GetMock<IConfigService>().Setup(v => v.ExtraFileExtensions).Returns("nfo,srt");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WithExistingFolder(string path, bool exists = true)
|
||||||
|
{
|
||||||
|
var dir = Path.GetDirectoryName(path);
|
||||||
|
|
||||||
|
if (exists && dir.IsNotNullOrWhiteSpace())
|
||||||
|
{
|
||||||
|
WithExistingFolder(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
Mocker.GetMock<IDiskProvider>().Setup(v => v.FolderExists(path)).Returns(exists);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WithExistingFile(string path, bool exists = true, int size = 1000)
|
||||||
|
{
|
||||||
|
var dir = Path.GetDirectoryName(path);
|
||||||
|
|
||||||
|
if (exists && dir.IsNotNullOrWhiteSpace())
|
||||||
|
{
|
||||||
|
WithExistingFolder(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
Mocker.GetMock<IDiskProvider>().Setup(v => v.FileExists(path)).Returns(exists);
|
||||||
|
Mocker.GetMock<IDiskProvider>().Setup(v => v.GetFileSize(path)).Returns(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WithExistingFiles(List<string> files)
|
||||||
|
{
|
||||||
|
foreach (string file in files)
|
||||||
|
{
|
||||||
|
WithExistingFile(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
Mocker.GetMock<IDiskProvider>().Setup(s => s.GetFiles(_releaseFolder, It.IsAny<SearchOption>()))
|
||||||
|
.Returns(files.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_not_pass_file_if_import_disabled()
|
||||||
|
{
|
||||||
|
Mocker.GetMock<IConfigService>().Setup(v => v.ImportExtraFiles).Returns(false);
|
||||||
|
|
||||||
|
var nfofile = Path.Combine(_releaseFolder, "Movie.Title.2022.nfo").AsOsAgnostic();
|
||||||
|
|
||||||
|
var files = new List<string>
|
||||||
|
{
|
||||||
|
_localMovie.Path,
|
||||||
|
nfofile
|
||||||
|
};
|
||||||
|
|
||||||
|
WithExistingFiles(files);
|
||||||
|
|
||||||
|
Subject.ImportMovie(_localMovie, _movieFile, true);
|
||||||
|
|
||||||
|
_subtitleService.Verify(v => v.CanImportFile(_localMovie, _movieFile, It.IsAny<string>(), It.IsAny<string>(), true), Times.Never());
|
||||||
|
_otherExtraService.Verify(v => v.CanImportFile(_localMovie, _movieFile, It.IsAny<string>(), It.IsAny<string>(), true), Times.Never());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
[TestCase("Movie Title - 2022.sub")]
|
||||||
|
[TestCase("Movie Title - 2022.ass")]
|
||||||
|
public void should_not_pass_unwanted_file(string filePath)
|
||||||
|
{
|
||||||
|
Mocker.GetMock<IConfigService>().Setup(v => v.ImportExtraFiles).Returns(false);
|
||||||
|
|
||||||
|
var nfofile = Path.Combine(_releaseFolder, filePath).AsOsAgnostic();
|
||||||
|
|
||||||
|
var files = new List<string>
|
||||||
|
{
|
||||||
|
_localMovie.Path,
|
||||||
|
nfofile
|
||||||
|
};
|
||||||
|
|
||||||
|
WithExistingFiles(files);
|
||||||
|
|
||||||
|
Subject.ImportMovie(_localMovie, _movieFile, true);
|
||||||
|
|
||||||
|
_subtitleService.Verify(v => v.CanImportFile(_localMovie, _movieFile, It.IsAny<string>(), It.IsAny<string>(), true), Times.Never());
|
||||||
|
_otherExtraService.Verify(v => v.CanImportFile(_localMovie, _movieFile, It.IsAny<string>(), It.IsAny<string>(), true), Times.Never());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_pass_subtitle_file_to_subtitle_service()
|
||||||
|
{
|
||||||
|
var subtitleFile = Path.Combine(_releaseFolder, "Movie.Title.2022.en.srt").AsOsAgnostic();
|
||||||
|
|
||||||
|
var files = new List<string>
|
||||||
|
{
|
||||||
|
_localMovie.Path,
|
||||||
|
subtitleFile
|
||||||
|
};
|
||||||
|
|
||||||
|
WithExistingFiles(files);
|
||||||
|
|
||||||
|
Subject.ImportMovie(_localMovie, _movieFile, true);
|
||||||
|
|
||||||
|
_subtitleService.Verify(v => v.ImportFiles(_localMovie, _movieFile, new List<string> { subtitleFile }, true), Times.Once());
|
||||||
|
_otherExtraService.Verify(v => v.ImportFiles(_localMovie, _movieFile, new List<string> { subtitleFile }, true), Times.Never());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_pass_nfo_file_to_other_service()
|
||||||
|
{
|
||||||
|
var nfofile = Path.Combine(_releaseFolder, "Movie.Title.2022.nfo").AsOsAgnostic();
|
||||||
|
|
||||||
|
var files = new List<string>
|
||||||
|
{
|
||||||
|
_localMovie.Path,
|
||||||
|
nfofile
|
||||||
|
};
|
||||||
|
|
||||||
|
WithExistingFiles(files);
|
||||||
|
|
||||||
|
Subject.ImportMovie(_localMovie, _movieFile, true);
|
||||||
|
|
||||||
|
_subtitleService.Verify(v => v.ImportFiles(_localMovie, _movieFile, new List<string> { nfofile }, true), Times.Never());
|
||||||
|
_otherExtraService.Verify(v => v.ImportFiles(_localMovie, _movieFile, new List<string> { nfofile }, true), Times.Once());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_search_subtitles_when_importing_from_job_folder()
|
||||||
|
{
|
||||||
|
_localMovie.FolderMovieInfo = new ParsedMovieInfo();
|
||||||
|
|
||||||
|
var subtitleFile = Path.Combine(_releaseFolder, "Movie.Title.2022.en.srt").AsOsAgnostic();
|
||||||
|
|
||||||
|
var files = new List<string>
|
||||||
|
{
|
||||||
|
_localMovie.Path,
|
||||||
|
subtitleFile
|
||||||
|
};
|
||||||
|
|
||||||
|
WithExistingFiles(files);
|
||||||
|
|
||||||
|
Subject.ImportMovie(_localMovie, _movieFile, true);
|
||||||
|
|
||||||
|
Mocker.GetMock<IDiskProvider>().Verify(v => v.GetFiles(_releaseFolder, SearchOption.AllDirectories), Times.Once);
|
||||||
|
Mocker.GetMock<IDiskProvider>().Verify(v => v.GetFiles(_releaseFolder, SearchOption.TopDirectoryOnly), Times.Never);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_not_search_subtitles_when_not_importing_from_job_folder()
|
||||||
|
{
|
||||||
|
_localMovie.FolderMovieInfo = null;
|
||||||
|
|
||||||
|
var subtitleFile = Path.Combine(_releaseFolder, "Movie.Title.2022.en.srt").AsOsAgnostic();
|
||||||
|
|
||||||
|
var files = new List<string>
|
||||||
|
{
|
||||||
|
_localMovie.Path,
|
||||||
|
subtitleFile
|
||||||
|
};
|
||||||
|
|
||||||
|
WithExistingFiles(files);
|
||||||
|
|
||||||
|
Subject.ImportMovie(_localMovie, _movieFile, true);
|
||||||
|
|
||||||
|
Mocker.GetMock<IDiskProvider>().Verify(v => v.GetFiles(_releaseFolder, SearchOption.AllDirectories), Times.Never);
|
||||||
|
Mocker.GetMock<IDiskProvider>().Verify(v => v.GetFiles(_releaseFolder, SearchOption.TopDirectoryOnly), Times.Once);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,84 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using FizzWare.NBuilder;
|
||||||
|
using FluentAssertions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Common.Extensions;
|
||||||
|
using NzbDrone.Core.Extras.Others;
|
||||||
|
using NzbDrone.Core.MediaFiles;
|
||||||
|
using NzbDrone.Core.Movies;
|
||||||
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.Extras.Others
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class OtherExtraServiceFixture : CoreTest<OtherExtraService>
|
||||||
|
{
|
||||||
|
private Movie _movie;
|
||||||
|
private MovieFile _movieFile;
|
||||||
|
private LocalMovie _localMovie;
|
||||||
|
|
||||||
|
private string _movieFolder;
|
||||||
|
private string _releaseFolder;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
_movieFolder = @"C:\Test\Movies\Movie Title".AsOsAgnostic();
|
||||||
|
_releaseFolder = @"C:\Test\Unsorted Movies\Movie.Title.2022".AsOsAgnostic();
|
||||||
|
|
||||||
|
_movie = Builder<Movie>.CreateNew()
|
||||||
|
.With(s => s.Path = _movieFolder)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
_movieFile = Builder<MovieFile>.CreateNew()
|
||||||
|
.With(f => f.Path = Path.Combine(_movie.Path, "Movie Title - 2022.mkv").AsOsAgnostic())
|
||||||
|
.With(f => f.RelativePath = @"Movie Title - 2022.mkv")
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
_localMovie = Builder<LocalMovie>.CreateNew()
|
||||||
|
.With(l => l.Movie = _movie)
|
||||||
|
.With(l => l.Path = Path.Combine(_releaseFolder, "Movie.Title.2022.mkv").AsOsAgnostic())
|
||||||
|
.With(l => l.FileMovieInfo = new ParsedMovieInfo
|
||||||
|
{
|
||||||
|
MovieTitles = new List<string> { "Movie Title" },
|
||||||
|
Year = 2022
|
||||||
|
})
|
||||||
|
.Build();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
[TestCase("Movie Title - 2022.nfo", "Movie Title - 2022.nfo")]
|
||||||
|
[TestCase("Movie.Title.2022.nfo", "Movie Title - 2022.nfo")]
|
||||||
|
[TestCase("Movie Title 2022.nfo", "Movie Title - 2022.nfo")]
|
||||||
|
[TestCase("Movie_Title_2022.nfo", "Movie Title - 2022.nfo")]
|
||||||
|
[TestCase(@"Movie.Title.2022\thumb.jpg", "Movie Title - 2022.jpg")]
|
||||||
|
public void should_import_matching_file(string filePath, string expectedOutputPath)
|
||||||
|
{
|
||||||
|
var files = new List<string> { Path.Combine(_releaseFolder, filePath).AsOsAgnostic() };
|
||||||
|
|
||||||
|
var results = Subject.ImportFiles(_localMovie, _movieFile, files, true).ToList();
|
||||||
|
|
||||||
|
results.Count().Should().Be(1);
|
||||||
|
|
||||||
|
results[0].RelativePath.AsOsAgnostic().PathEquals(expectedOutputPath.AsOsAgnostic()).Should().Be(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_not_import_multiple_nfo_files()
|
||||||
|
{
|
||||||
|
var files = new List<string>
|
||||||
|
{
|
||||||
|
Path.Combine(_releaseFolder, "Movie.Title.2022.nfo").AsOsAgnostic(),
|
||||||
|
Path.Combine(_releaseFolder, "Movie_Title_2022.nfo").AsOsAgnostic(),
|
||||||
|
};
|
||||||
|
|
||||||
|
var results = Subject.ImportFiles(_localMovie, _movieFile, files, true).ToList();
|
||||||
|
|
||||||
|
results.Count().Should().Be(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,179 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using FizzWare.NBuilder;
|
||||||
|
using FluentAssertions;
|
||||||
|
using Moq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Common.Disk;
|
||||||
|
using NzbDrone.Common.Extensions;
|
||||||
|
using NzbDrone.Core.Extras.Subtitles;
|
||||||
|
using NzbDrone.Core.MediaFiles;
|
||||||
|
using NzbDrone.Core.MediaFiles.MovieImport;
|
||||||
|
using NzbDrone.Core.Movies;
|
||||||
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.Extras.Subtitles
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class SubtitleServiceFixture : CoreTest<SubtitleService>
|
||||||
|
{
|
||||||
|
private Movie _movie;
|
||||||
|
private MovieFile _movieFile;
|
||||||
|
private LocalMovie _localMovie;
|
||||||
|
|
||||||
|
private string _MovieFolder;
|
||||||
|
private string _releaseFolder;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
_MovieFolder = @"C:\Test\Movies\Movie Title".AsOsAgnostic();
|
||||||
|
_releaseFolder = @"C:\Test\Unsorted Movies\Movie.Title.2022".AsOsAgnostic();
|
||||||
|
|
||||||
|
_movie = Builder<Movie>.CreateNew()
|
||||||
|
.With(s => s.Path = _MovieFolder)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
_movieFile = Builder<MovieFile>.CreateNew()
|
||||||
|
.With(f => f.Path = Path.Combine(_movie.Path, "Movie Title - 2022.mkv").AsOsAgnostic())
|
||||||
|
.With(f => f.RelativePath = @"Movie Title - 2022.mkv".AsOsAgnostic())
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
_localMovie = Builder<LocalMovie>.CreateNew()
|
||||||
|
.With(l => l.Movie = _movie)
|
||||||
|
.With(l => l.Path = Path.Combine(_releaseFolder, "Movie.Title.2022.mkv").AsOsAgnostic())
|
||||||
|
.With(l => l.FileMovieInfo = new ParsedMovieInfo
|
||||||
|
{
|
||||||
|
MovieTitles = new List<string> { "Movie Title" },
|
||||||
|
Year = 2022
|
||||||
|
})
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
Mocker.GetMock<IDiskProvider>().Setup(s => s.GetParentFolder(It.IsAny<string>()))
|
||||||
|
.Returns((string path) => Directory.GetParent(path).FullName);
|
||||||
|
|
||||||
|
Mocker.GetMock<IDetectSample>().Setup(s => s.IsSample(It.IsAny<MovieMetadata>(), It.IsAny<string>()))
|
||||||
|
.Returns(DetectSampleResult.NotSample);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
[TestCase("Movie.Title.2022.en.nfo")]
|
||||||
|
public void should_not_import_non_subtitle_file(string filePath)
|
||||||
|
{
|
||||||
|
var files = new List<string> { Path.Combine(_releaseFolder, filePath).AsOsAgnostic() };
|
||||||
|
|
||||||
|
var results = Subject.ImportFiles(_localMovie, _movieFile, files, true).ToList();
|
||||||
|
|
||||||
|
results.Count().Should().Be(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
[TestCase("Movie Title - 2022.srt", "Movie Title - 2022.srt")]
|
||||||
|
[TestCase("Movie.Title.2022.en.srt", "Movie Title - 2022.en.srt")]
|
||||||
|
[TestCase("Movie.Title.2022.english.srt", "Movie Title - 2022.en.srt")]
|
||||||
|
[TestCase("Movie Title 2022_en_sdh_forced.srt", "Movie Title - 2022.en.srt")]
|
||||||
|
[TestCase("Movie_Title_2022 en.srt", "Movie Title - 2022.en.srt")]
|
||||||
|
[TestCase(@"Subs\Movie.Title.2022\2_en.srt", "Movie Title - 2022.en.srt")]
|
||||||
|
[TestCase("sub.srt", "Movie Title - 2022.srt")]
|
||||||
|
public void should_import_matching_subtitle_file(string filePath, string expectedOutputPath)
|
||||||
|
{
|
||||||
|
var files = new List<string> { Path.Combine(_releaseFolder, filePath).AsOsAgnostic() };
|
||||||
|
|
||||||
|
var results = Subject.ImportFiles(_localMovie, _movieFile, files, true).ToList();
|
||||||
|
|
||||||
|
results.Count().Should().Be(1);
|
||||||
|
|
||||||
|
results[0].RelativePath.AsOsAgnostic().PathEquals(expectedOutputPath.AsOsAgnostic()).Should().Be(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_import_multiple_subtitle_files_per_language()
|
||||||
|
{
|
||||||
|
var files = new List<string>
|
||||||
|
{
|
||||||
|
Path.Combine(_releaseFolder, "Movie.Title.2022.en.srt").AsOsAgnostic(),
|
||||||
|
Path.Combine(_releaseFolder, "Movie.Title.2022.english.srt").AsOsAgnostic(),
|
||||||
|
Path.Combine(_releaseFolder, "Subs", "Movie_Title_2022_en_forced.srt").AsOsAgnostic(),
|
||||||
|
Path.Combine(_releaseFolder, "Subs", "Movie.Title.2022", "2_fr.srt").AsOsAgnostic()
|
||||||
|
};
|
||||||
|
|
||||||
|
var expectedOutputs = new string[]
|
||||||
|
{
|
||||||
|
"Movie Title - 2022.1.en.srt",
|
||||||
|
"Movie Title - 2022.2.en.srt",
|
||||||
|
"Movie Title - 2022.3.en.srt",
|
||||||
|
"Movie Title - 2022.fr.srt",
|
||||||
|
};
|
||||||
|
|
||||||
|
var results = Subject.ImportFiles(_localMovie, _movieFile, files, true).ToList();
|
||||||
|
|
||||||
|
results.Count().Should().Be(expectedOutputs.Length);
|
||||||
|
|
||||||
|
for (int i = 0; i < expectedOutputs.Length; i++)
|
||||||
|
{
|
||||||
|
results[i].RelativePath.AsOsAgnostic().PathEquals(expectedOutputs[i].AsOsAgnostic()).Should().Be(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_import_multiple_subtitle_files_per_language_with_tags()
|
||||||
|
{
|
||||||
|
var files = new List<string>
|
||||||
|
{
|
||||||
|
Path.Combine(_releaseFolder, "Movie.Title.2022.en.forced.cc.srt").AsOsAgnostic(),
|
||||||
|
Path.Combine(_releaseFolder, "Movie.Title.2022.other.en.forced.cc.srt").AsOsAgnostic(),
|
||||||
|
Path.Combine(_releaseFolder, "Movie.Title.2022.en.forced.sdh.srt").AsOsAgnostic(),
|
||||||
|
Path.Combine(_releaseFolder, "Movie.Title.2022.en.forced.default.srt").AsOsAgnostic(),
|
||||||
|
};
|
||||||
|
|
||||||
|
var expectedOutputs = new[]
|
||||||
|
{
|
||||||
|
"Movie Title - 2022.1.en.forced.cc.srt",
|
||||||
|
"Movie Title - 2022.2.en.forced.cc.srt",
|
||||||
|
"Movie Title - 2022.en.forced.sdh.srt",
|
||||||
|
"Movie Title - 2022.en.forced.default.srt"
|
||||||
|
};
|
||||||
|
|
||||||
|
var results = Subject.ImportFiles(_localMovie, _movieFile, files, true).ToList();
|
||||||
|
|
||||||
|
results.Count().Should().Be(expectedOutputs.Length);
|
||||||
|
|
||||||
|
for (int i = 0; i < expectedOutputs.Length; i++)
|
||||||
|
{
|
||||||
|
results[i].RelativePath.AsOsAgnostic().PathEquals(expectedOutputs[i].AsOsAgnostic()).Should().Be(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
[TestCase(@"Subs\2_en.srt", "Movie Title - 2022.en.srt")]
|
||||||
|
public void should_import_unmatching_subtitle_file_if_only_episode(string filePath, string expectedOutputPath)
|
||||||
|
{
|
||||||
|
var subtitleFile = Path.Combine(_releaseFolder, filePath).AsOsAgnostic();
|
||||||
|
|
||||||
|
var sampleFile = Path.Combine(_movie.Path, "Movie Title - 2022.sample.mkv").AsOsAgnostic();
|
||||||
|
|
||||||
|
var videoFiles = new string[]
|
||||||
|
{
|
||||||
|
_localMovie.Path,
|
||||||
|
sampleFile
|
||||||
|
};
|
||||||
|
|
||||||
|
Mocker.GetMock<IDiskProvider>().Setup(s => s.GetFiles(It.IsAny<string>(), SearchOption.AllDirectories))
|
||||||
|
.Returns(videoFiles);
|
||||||
|
|
||||||
|
Mocker.GetMock<IDetectSample>().Setup(s => s.IsSample(It.IsAny<MovieMetadata>(), sampleFile))
|
||||||
|
.Returns(DetectSampleResult.Sample);
|
||||||
|
|
||||||
|
var results = Subject.ImportFiles(_localMovie, _movieFile, new List<string> { subtitleFile }, true).ToList();
|
||||||
|
|
||||||
|
results.Count().Should().Be(1);
|
||||||
|
|
||||||
|
results[0].RelativePath.AsOsAgnostic().PathEquals(expectedOutputPath.AsOsAgnostic()).Should().Be(true);
|
||||||
|
|
||||||
|
ExceptionVerification.ExpectedWarns(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue