2018-03-14 20:41:36 +00:00
|
|
|
using System.Collections.Generic;
|
2013-07-06 21:47:49 +00:00
|
|
|
using System.Linq;
|
|
|
|
using FluentAssertions;
|
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using NzbDrone.Core.DecisionEngine;
|
2013-07-19 05:18:11 +00:00
|
|
|
using NzbDrone.Core.MediaFiles;
|
2018-03-14 20:41:36 +00:00
|
|
|
using NzbDrone.Core.MediaFiles.MovieImport;
|
2013-07-06 21:47:49 +00:00
|
|
|
using NzbDrone.Core.Parser;
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
2014-06-08 08:22:55 +00:00
|
|
|
using NzbDrone.Core.Profiles;
|
2013-11-12 00:49:43 +00:00
|
|
|
using NzbDrone.Core.Qualities;
|
2013-07-06 21:47:49 +00:00
|
|
|
using NzbDrone.Core.Test.Framework;
|
2018-03-14 20:41:36 +00:00
|
|
|
using NzbDrone.Core.Movies;
|
2013-07-06 21:47:49 +00:00
|
|
|
using NzbDrone.Test.Common;
|
2014-01-18 11:44:36 +00:00
|
|
|
using FizzWare.NBuilder;
|
2018-03-14 20:41:36 +00:00
|
|
|
using NzbDrone.Core.Download;
|
2019-07-16 02:27:35 +00:00
|
|
|
using NzbDrone.Core.MediaFiles.MovieImport.Aggregation;
|
2013-07-06 21:47:49 +00:00
|
|
|
|
2018-03-14 20:41:36 +00:00
|
|
|
namespace NzbDrone.Core.Test.MediaFiles.MovieImport
|
2013-07-06 21:47:49 +00:00
|
|
|
{
|
2018-09-10 19:25:10 +00:00
|
|
|
[TestFixture]
|
2019-12-22 21:24:10 +00:00
|
|
|
//TODO: Add tests to ensure helpers for augmenters are correctly passed.
|
2013-07-06 21:47:49 +00:00
|
|
|
public class ImportDecisionMakerFixture : CoreTest<ImportDecisionMaker>
|
|
|
|
{
|
2013-09-10 17:54:59 +00:00
|
|
|
private List<string> _videoFiles;
|
2018-09-10 19:25:10 +00:00
|
|
|
private LocalMovie _localMovie;
|
|
|
|
private Movie _movie;
|
2013-11-12 00:49:43 +00:00
|
|
|
private QualityModel _quality;
|
2018-09-10 19:25:10 +00:00
|
|
|
private ParsedMovieInfo _fileInfo;
|
2013-07-06 21:47:49 +00:00
|
|
|
|
|
|
|
private Mock<IImportDecisionEngineSpecification> _pass1;
|
|
|
|
private Mock<IImportDecisionEngineSpecification> _pass2;
|
|
|
|
private Mock<IImportDecisionEngineSpecification> _pass3;
|
|
|
|
|
|
|
|
private Mock<IImportDecisionEngineSpecification> _fail1;
|
|
|
|
private Mock<IImportDecisionEngineSpecification> _fail2;
|
|
|
|
private Mock<IImportDecisionEngineSpecification> _fail3;
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
|
|
|
_pass1 = new Mock<IImportDecisionEngineSpecification>();
|
|
|
|
_pass2 = new Mock<IImportDecisionEngineSpecification>();
|
|
|
|
_pass3 = new Mock<IImportDecisionEngineSpecification>();
|
|
|
|
|
|
|
|
_fail1 = new Mock<IImportDecisionEngineSpecification>();
|
|
|
|
_fail2 = new Mock<IImportDecisionEngineSpecification>();
|
|
|
|
_fail3 = new Mock<IImportDecisionEngineSpecification>();
|
|
|
|
|
2018-03-14 20:41:36 +00:00
|
|
|
_pass1.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalMovie>(), It.IsAny<DownloadClientItem>())).Returns(Decision.Accept());
|
|
|
|
_pass2.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalMovie>(), It.IsAny<DownloadClientItem>())).Returns(Decision.Accept());
|
|
|
|
_pass3.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalMovie>(), It.IsAny<DownloadClientItem>())).Returns(Decision.Accept());
|
2013-07-06 21:47:49 +00:00
|
|
|
|
2018-03-14 20:41:36 +00:00
|
|
|
_fail1.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalMovie>(), It.IsAny<DownloadClientItem>())).Returns(Decision.Reject("_fail1"));
|
|
|
|
_fail2.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalMovie>(), It.IsAny<DownloadClientItem>())).Returns(Decision.Reject("_fail2"));
|
|
|
|
_fail3.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalMovie>(), It.IsAny<DownloadClientItem>())).Returns(Decision.Reject("_fail3"));
|
2013-07-06 21:47:49 +00:00
|
|
|
|
2018-09-10 19:25:10 +00:00
|
|
|
_movie = Builder<Movie>.CreateNew()
|
2019-12-07 06:17:01 +00:00
|
|
|
.With(e => e.Path = @"C:\Test\Movie".AsOsAgnostic())
|
2014-06-08 08:22:55 +00:00
|
|
|
.With(e => e.Profile = new Profile { Items = Qualities.QualityFixture.GetDefaultQualities() })
|
2014-01-18 11:44:36 +00:00
|
|
|
.Build();
|
|
|
|
|
2013-11-12 00:49:43 +00:00
|
|
|
_quality = new QualityModel(Quality.DVD);
|
2015-01-27 05:57:07 +00:00
|
|
|
|
2018-09-10 19:25:10 +00:00
|
|
|
_localMovie = new LocalMovie
|
|
|
|
{
|
|
|
|
Movie = _movie,
|
2013-11-12 00:49:43 +00:00
|
|
|
Quality = _quality,
|
2018-09-10 19:25:10 +00:00
|
|
|
Path = @"C:\Test\Unsorted\The.Office.2018.DVDRip.XviD-OSiTV.avi"
|
2013-11-12 00:49:43 +00:00
|
|
|
};
|
2013-07-06 21:47:49 +00:00
|
|
|
|
2018-09-10 19:25:10 +00:00
|
|
|
_fileInfo = new ParsedMovieInfo
|
|
|
|
{
|
|
|
|
MovieTitle = "The Office",
|
|
|
|
Year = 2018,
|
|
|
|
Quality = _quality
|
|
|
|
};
|
|
|
|
|
2013-07-23 05:50:32 +00:00
|
|
|
Mocker.GetMock<IParsingService>()
|
2018-09-10 19:25:10 +00:00
|
|
|
.Setup(c => c.ParseMinimalPathMovieInfo(It.IsAny<string>()))
|
|
|
|
.Returns(_fileInfo);
|
2013-07-06 21:47:49 +00:00
|
|
|
|
2018-09-10 19:25:10 +00:00
|
|
|
GivenVideoFiles(new List<string> { @"C:\Test\Unsorted\The.Office.2018.DVDRip.XviD-OSiTV.avi".AsOsAgnostic() });
|
2013-07-06 21:47:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void GivenSpecifications(params Mock<IImportDecisionEngineSpecification>[] mocks)
|
|
|
|
{
|
2015-01-27 05:57:07 +00:00
|
|
|
Mocker.SetConstant(mocks.Select(c => c.Object));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void GivenVideoFiles(IEnumerable<string> videoFiles)
|
|
|
|
{
|
|
|
|
_videoFiles = videoFiles.ToList();
|
|
|
|
|
|
|
|
Mocker.GetMock<IMediaFileService>()
|
2018-03-14 20:41:36 +00:00
|
|
|
.Setup(c => c.FilterExistingFiles(_videoFiles, It.IsAny<Movie>()))
|
2015-10-23 05:21:44 +00:00
|
|
|
.Returns(_videoFiles);
|
2013-07-06 21:47:49 +00:00
|
|
|
}
|
|
|
|
|
2019-07-16 02:27:35 +00:00
|
|
|
private void GivenAugmentationSuccess()
|
|
|
|
{
|
|
|
|
Mocker.GetMock<IAggregationService>()
|
|
|
|
.Setup(s => s.Augment(It.IsAny<LocalMovie>(), It.IsAny<bool>()))
|
|
|
|
.Callback<LocalMovie, bool>((localMovie, otherFiles) =>
|
|
|
|
{
|
|
|
|
localMovie.Movie = _localMovie.Movie;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-07-06 21:47:49 +00:00
|
|
|
[Test]
|
|
|
|
public void should_call_all_specifications()
|
|
|
|
{
|
2018-03-14 20:41:36 +00:00
|
|
|
var downloadClientItem = Builder<DownloadClientItem>.CreateNew().Build();
|
2019-12-07 06:17:01 +00:00
|
|
|
GivenAugmentationSuccess();
|
2013-07-06 21:47:49 +00:00
|
|
|
GivenSpecifications(_pass1, _pass2, _pass3, _fail1, _fail2, _fail3);
|
|
|
|
|
2019-12-07 06:17:01 +00:00
|
|
|
Subject.GetImportDecisions(_videoFiles, _movie, downloadClientItem, null, false, true);
|
2013-07-06 21:47:49 +00:00
|
|
|
|
2019-07-16 02:27:35 +00:00
|
|
|
_fail1.Verify(c => c.IsSatisfiedBy(It.IsAny<LocalMovie>(), downloadClientItem), Times.Once());
|
|
|
|
_fail2.Verify(c => c.IsSatisfiedBy(It.IsAny<LocalMovie>(), downloadClientItem), Times.Once());
|
|
|
|
_fail3.Verify(c => c.IsSatisfiedBy(It.IsAny<LocalMovie>(), downloadClientItem), Times.Once());
|
|
|
|
_pass1.Verify(c => c.IsSatisfiedBy(It.IsAny<LocalMovie>(), downloadClientItem), Times.Once());
|
|
|
|
_pass2.Verify(c => c.IsSatisfiedBy(It.IsAny<LocalMovie>(), downloadClientItem), Times.Once());
|
|
|
|
_pass3.Verify(c => c.IsSatisfiedBy(It.IsAny<LocalMovie>(), downloadClientItem), Times.Once());
|
2013-07-06 21:47:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_return_rejected_if_single_specs_fail()
|
|
|
|
{
|
|
|
|
GivenSpecifications(_fail1);
|
|
|
|
|
2019-12-07 06:17:01 +00:00
|
|
|
var result = Subject.GetImportDecisions(_videoFiles, _movie);
|
2013-07-06 21:47:49 +00:00
|
|
|
|
|
|
|
result.Single().Approved.Should().BeFalse();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_return_rejected_if_one_of_specs_fail()
|
|
|
|
{
|
|
|
|
GivenSpecifications(_pass1, _fail1, _pass2, _pass3);
|
|
|
|
|
2019-12-07 06:17:01 +00:00
|
|
|
var result = Subject.GetImportDecisions(_videoFiles, _movie);
|
2013-07-06 21:47:49 +00:00
|
|
|
|
|
|
|
result.Single().Approved.Should().BeFalse();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2019-12-07 06:17:01 +00:00
|
|
|
public void should_return_approved_if_all_specs_pass()
|
2013-07-06 21:47:49 +00:00
|
|
|
{
|
2019-12-07 06:17:01 +00:00
|
|
|
GivenAugmentationSuccess();
|
2013-07-06 21:47:49 +00:00
|
|
|
GivenSpecifications(_pass1, _pass2, _pass3);
|
|
|
|
|
2019-12-07 06:17:01 +00:00
|
|
|
var result = Subject.GetImportDecisions(_videoFiles, _movie);
|
2013-07-06 21:47:49 +00:00
|
|
|
|
|
|
|
result.Single().Approved.Should().BeTrue();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_have_same_number_of_rejections_as_specs_that_failed()
|
|
|
|
{
|
2019-12-07 06:17:01 +00:00
|
|
|
GivenAugmentationSuccess();
|
2013-07-06 21:47:49 +00:00
|
|
|
GivenSpecifications(_pass1, _pass2, _pass3, _fail1, _fail2, _fail3);
|
|
|
|
|
2019-12-07 06:17:01 +00:00
|
|
|
var result = Subject.GetImportDecisions(_videoFiles, _movie);
|
2013-07-06 21:47:49 +00:00
|
|
|
result.Single().Rejections.Should().HaveCount(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2014-09-04 00:57:27 +00:00
|
|
|
public void should_not_blowup_the_process_due_to_failed_parse()
|
2013-07-06 21:47:49 +00:00
|
|
|
{
|
|
|
|
GivenSpecifications(_pass1);
|
|
|
|
|
2019-07-16 02:27:35 +00:00
|
|
|
Mocker.GetMock<IAggregationService>()
|
|
|
|
.Setup(c => c.Augment(It.IsAny<LocalMovie>(), It.IsAny<bool>()))
|
2014-09-04 00:57:27 +00:00
|
|
|
.Throws<TestException>();
|
2013-07-06 21:47:49 +00:00
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
_videoFiles = new List<string>
|
2013-07-06 21:47:49 +00:00
|
|
|
{
|
|
|
|
"The.Office.S03E115.DVDRip.XviD-OSiTV",
|
|
|
|
"The.Office.S03E115.DVDRip.XviD-OSiTV",
|
|
|
|
"The.Office.S03E115.DVDRip.XviD-OSiTV"
|
|
|
|
};
|
|
|
|
|
2015-01-27 05:57:07 +00:00
|
|
|
GivenVideoFiles(_videoFiles);
|
2013-07-19 05:25:42 +00:00
|
|
|
|
2018-09-10 19:25:10 +00:00
|
|
|
Subject.GetImportDecisions(_videoFiles, _movie);
|
2013-07-06 21:47:49 +00:00
|
|
|
|
2019-07-16 02:27:35 +00:00
|
|
|
Mocker.GetMock<IAggregationService>()
|
|
|
|
.Verify(c => c.Augment(It.IsAny<LocalMovie>(), It.IsAny<bool>()), Times.Exactly(_videoFiles.Count));
|
2013-07-06 21:47:49 +00:00
|
|
|
|
|
|
|
ExceptionVerification.ExpectedErrors(3);
|
|
|
|
}
|
2013-11-12 00:49:43 +00:00
|
|
|
|
|
|
|
[Test]
|
2018-09-10 19:25:10 +00:00
|
|
|
public void should_call_parsing_service_with_filename_as_simpletitle()
|
2013-11-12 00:49:43 +00:00
|
|
|
{
|
|
|
|
GivenSpecifications(_pass1, _pass2, _pass3);
|
|
|
|
|
2018-09-10 19:25:10 +00:00
|
|
|
Mocker.GetMock<IParsingService>()
|
|
|
|
.Setup(c => c.ParseMinimalPathMovieInfo(It.IsAny<string>()))
|
|
|
|
.Returns<ParsedMovieInfo>(null);
|
2013-11-12 00:49:43 +00:00
|
|
|
|
2018-09-10 19:25:10 +00:00
|
|
|
var folderInfo = new ParsedMovieInfo {SimpleReleaseTitle = "A Movie Folder 2018", Quality = _quality};
|
|
|
|
|
|
|
|
var result = Subject.GetImportDecisions(_videoFiles, _movie, null, folderInfo, true);
|
|
|
|
|
|
|
|
var fileNames = _videoFiles.Select(System.IO.Path.GetFileName);
|
|
|
|
|
2019-07-16 02:27:35 +00:00
|
|
|
Mocker.GetMock<IAggregationService>()
|
|
|
|
.Setup(c => c.Augment(It.IsAny<LocalMovie>(), It.IsAny<bool>()))
|
|
|
|
.Throws<TestException>();
|
2015-05-25 06:18:57 +00:00
|
|
|
}
|
2016-04-17 21:17:46 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_return_a_decision_when_exception_is_caught()
|
|
|
|
{
|
2019-07-16 02:27:35 +00:00
|
|
|
Mocker.GetMock<IAggregationService>()
|
|
|
|
.Setup(c => c.Augment(It.IsAny<LocalMovie>(), It.IsAny<bool>()))
|
2016-04-17 21:17:46 +00:00
|
|
|
.Throws<TestException>();
|
|
|
|
|
|
|
|
_videoFiles = new List<string>
|
|
|
|
{
|
|
|
|
"The.Office.S03E115.DVDRip.XviD-OSiTV"
|
|
|
|
};
|
|
|
|
|
|
|
|
GivenVideoFiles(_videoFiles);
|
|
|
|
|
2018-09-10 19:25:10 +00:00
|
|
|
Subject.GetImportDecisions(_videoFiles, _movie).Should().HaveCount(1);
|
2016-04-17 21:17:46 +00:00
|
|
|
|
|
|
|
ExceptionVerification.ExpectedErrors(1);
|
|
|
|
}
|
2018-09-10 19:25:10 +00:00
|
|
|
}
|
2015-01-27 05:57:07 +00:00
|
|
|
}
|