|
|
|
@ -45,31 +45,20 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
|
|
|
|
|
_fail2 = new Mock<IImportDecisionEngineSpecification>();
|
|
|
|
|
_fail3 = new Mock<IImportDecisionEngineSpecification>();
|
|
|
|
|
|
|
|
|
|
_pass1.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalEpisode>())).Returns(true);
|
|
|
|
|
_pass1.Setup(c => c.RejectionReason).Returns("_pass1");
|
|
|
|
|
_pass1.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalEpisode>())).Returns(Decision.Accept());
|
|
|
|
|
_pass2.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalEpisode>())).Returns(Decision.Accept());
|
|
|
|
|
_pass3.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalEpisode>())).Returns(Decision.Accept());
|
|
|
|
|
|
|
|
|
|
_pass2.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalEpisode>())).Returns(true);
|
|
|
|
|
_pass2.Setup(c => c.RejectionReason).Returns("_pass2");
|
|
|
|
|
_fail1.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalEpisode>())).Returns(Decision.Reject("_fail1"));
|
|
|
|
|
_fail2.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalEpisode>())).Returns(Decision.Reject("_fail2"));
|
|
|
|
|
_fail3.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalEpisode>())).Returns(Decision.Reject("_fail3"));
|
|
|
|
|
|
|
|
|
|
_pass3.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalEpisode>())).Returns(true);
|
|
|
|
|
_pass3.Setup(c => c.RejectionReason).Returns("_pass3");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_fail1.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalEpisode>())).Returns(false);
|
|
|
|
|
_fail1.Setup(c => c.RejectionReason).Returns("_fail1");
|
|
|
|
|
|
|
|
|
|
_fail2.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalEpisode>())).Returns(false);
|
|
|
|
|
_fail2.Setup(c => c.RejectionReason).Returns("_fail2");
|
|
|
|
|
|
|
|
|
|
_fail3.Setup(c => c.IsSatisfiedBy(It.IsAny<LocalEpisode>())).Returns(false);
|
|
|
|
|
_fail3.Setup(c => c.RejectionReason).Returns("_fail3");
|
|
|
|
|
|
|
|
|
|
_videoFiles = new List<string> { @"C:\Test\Unsorted\The.Office.S03E115.DVDRip.XviD-OSiTV.avi" };
|
|
|
|
|
_series = Builder<Series>.CreateNew()
|
|
|
|
|
.With(e => e.Profile = new Profile { Items = Qualities.QualityFixture.GetDefaultQualities() })
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
_quality = new QualityModel(Quality.DVD);
|
|
|
|
|
|
|
|
|
|
_localEpisode = new LocalEpisode
|
|
|
|
|
{
|
|
|
|
|
Series = _series,
|
|
|
|
@ -78,17 +67,24 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IParsingService>()
|
|
|
|
|
.Setup(c => c.GetLocalEpisode(It.IsAny<String>(), It.IsAny<Series>(), It.IsAny<Boolean>()))
|
|
|
|
|
.Setup(c => c.GetLocalEpisode(It.IsAny<String>(), It.IsAny<Series>(), It.IsAny<ParsedEpisodeInfo>(), It.IsAny<Boolean>()))
|
|
|
|
|
.Returns(_localEpisode);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IMediaFileService>()
|
|
|
|
|
.Setup(c => c.FilterExistingFiles(_videoFiles, It.IsAny<Series>()))
|
|
|
|
|
.Returns(_videoFiles);
|
|
|
|
|
GivenVideoFiles(new List<string> { @"C:\Test\Unsorted\The.Office.S03E115.DVDRip.XviD-OSiTV.avi".AsOsAgnostic() });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GivenSpecifications(params Mock<IImportDecisionEngineSpecification>[] mocks)
|
|
|
|
|
{
|
|
|
|
|
Mocker.SetConstant<IEnumerable<IRejectWithReason>>(mocks.Select(c => c.Object));
|
|
|
|
|
Mocker.SetConstant(mocks.Select(c => c.Object));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GivenVideoFiles(IEnumerable<string> videoFiles)
|
|
|
|
|
{
|
|
|
|
|
_videoFiles = videoFiles.ToList();
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IMediaFileService>()
|
|
|
|
|
.Setup(c => c.FilterExistingFiles(_videoFiles, It.IsAny<Series>()))
|
|
|
|
|
.Returns(_videoFiles);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
@ -96,7 +92,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
|
|
|
|
|
{
|
|
|
|
|
GivenSpecifications(_pass1, _pass2, _pass3, _fail1, _fail2, _fail3);
|
|
|
|
|
|
|
|
|
|
Subject.GetImportDecisions(_videoFiles, new Series(), false);
|
|
|
|
|
Subject.GetImportDecisions(_videoFiles, new Series(), null, false);
|
|
|
|
|
|
|
|
|
|
_fail1.Verify(c => c.IsSatisfiedBy(_localEpisode), Times.Once());
|
|
|
|
|
_fail2.Verify(c => c.IsSatisfiedBy(_localEpisode), Times.Once());
|
|
|
|
@ -111,7 +107,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
|
|
|
|
|
{
|
|
|
|
|
GivenSpecifications(_fail1);
|
|
|
|
|
|
|
|
|
|
var result = Subject.GetImportDecisions(_videoFiles, new Series(), false);
|
|
|
|
|
var result = Subject.GetImportDecisions(_videoFiles, new Series());
|
|
|
|
|
|
|
|
|
|
result.Single().Approved.Should().BeFalse();
|
|
|
|
|
}
|
|
|
|
@ -121,7 +117,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
|
|
|
|
|
{
|
|
|
|
|
GivenSpecifications(_pass1, _fail1, _pass2, _pass3);
|
|
|
|
|
|
|
|
|
|
var result = Subject.GetImportDecisions(_videoFiles, new Series(), false);
|
|
|
|
|
var result = Subject.GetImportDecisions(_videoFiles, new Series());
|
|
|
|
|
|
|
|
|
|
result.Single().Approved.Should().BeFalse();
|
|
|
|
|
}
|
|
|
|
@ -131,7 +127,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
|
|
|
|
|
{
|
|
|
|
|
GivenSpecifications(_pass1, _pass2, _pass3);
|
|
|
|
|
|
|
|
|
|
var result = Subject.GetImportDecisions(_videoFiles, new Series(), false);
|
|
|
|
|
var result = Subject.GetImportDecisions(_videoFiles, new Series());
|
|
|
|
|
|
|
|
|
|
result.Single().Approved.Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
@ -141,7 +137,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
|
|
|
|
|
{
|
|
|
|
|
GivenSpecifications(_pass1, _pass2, _pass3, _fail1, _fail2, _fail3);
|
|
|
|
|
|
|
|
|
|
var result = Subject.GetImportDecisions(_videoFiles, new Series(), false);
|
|
|
|
|
var result = Subject.GetImportDecisions(_videoFiles, new Series());
|
|
|
|
|
result.Single().Rejections.Should().HaveCount(3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -151,7 +147,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
|
|
|
|
|
GivenSpecifications(_pass1);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IParsingService>()
|
|
|
|
|
.Setup(c => c.GetLocalEpisode(It.IsAny<String>(), It.IsAny<Series>(), It.IsAny<Boolean>()))
|
|
|
|
|
.Setup(c => c.GetLocalEpisode(It.IsAny<String>(), It.IsAny<Series>(), It.IsAny<ParsedEpisodeInfo>(), It.IsAny<Boolean>()))
|
|
|
|
|
.Throws<TestException>();
|
|
|
|
|
|
|
|
|
|
_videoFiles = new List<String>
|
|
|
|
@ -161,14 +157,12 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
|
|
|
|
|
"The.Office.S03E115.DVDRip.XviD-OSiTV"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IMediaFileService>()
|
|
|
|
|
.Setup(c => c.FilterExistingFiles(_videoFiles, It.IsAny<Series>()))
|
|
|
|
|
.Returns(_videoFiles);
|
|
|
|
|
GivenVideoFiles(_videoFiles);
|
|
|
|
|
|
|
|
|
|
Subject.GetImportDecisions(_videoFiles, _series, false);
|
|
|
|
|
Subject.GetImportDecisions(_videoFiles, _series);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IParsingService>()
|
|
|
|
|
.Verify(c => c.GetLocalEpisode(It.IsAny<String>(), It.IsAny<Series>(), It.IsAny<Boolean>()), Times.Exactly(_videoFiles.Count));
|
|
|
|
|
.Verify(c => c.GetLocalEpisode(It.IsAny<String>(), It.IsAny<Series>(), It.IsAny<ParsedEpisodeInfo>(), It.IsAny<Boolean>()), Times.Exactly(_videoFiles.Count));
|
|
|
|
|
|
|
|
|
|
ExceptionVerification.ExpectedErrors(3);
|
|
|
|
|
}
|
|
|
|
@ -179,7 +173,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
|
|
|
|
|
GivenSpecifications(_pass1, _pass2, _pass3);
|
|
|
|
|
var expectedQuality = QualityParser.ParseQuality(_videoFiles.Single());
|
|
|
|
|
|
|
|
|
|
var result = Subject.GetImportDecisions(_videoFiles, _series, false, null);
|
|
|
|
|
var result = Subject.GetImportDecisions(_videoFiles, _series);
|
|
|
|
|
|
|
|
|
|
result.Single().LocalEpisode.Quality.Should().Be(expectedQuality);
|
|
|
|
|
}
|
|
|
|
@ -190,7 +184,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
|
|
|
|
|
GivenSpecifications(_pass1, _pass2, _pass3);
|
|
|
|
|
var expectedQuality = QualityParser.ParseQuality(_videoFiles.Single());
|
|
|
|
|
|
|
|
|
|
var result = Subject.GetImportDecisions(_videoFiles, _series, false, new QualityModel(Quality.SDTV));
|
|
|
|
|
var result = Subject.GetImportDecisions(_videoFiles, _series, new ParsedEpisodeInfo{Quality = new QualityModel(Quality.SDTV)}, true);
|
|
|
|
|
|
|
|
|
|
result.Single().LocalEpisode.Quality.Should().Be(expectedQuality);
|
|
|
|
|
}
|
|
|
|
@ -201,7 +195,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
|
|
|
|
|
GivenSpecifications(_pass1, _pass2, _pass3);
|
|
|
|
|
var expectedQuality = new QualityModel(Quality.Bluray1080p);
|
|
|
|
|
|
|
|
|
|
var result = Subject.GetImportDecisions(_videoFiles, _series, false, expectedQuality);
|
|
|
|
|
var result = Subject.GetImportDecisions(_videoFiles, _series, new ParsedEpisodeInfo { Quality = expectedQuality }, true);
|
|
|
|
|
|
|
|
|
|
result.Single().LocalEpisode.Quality.Should().Be(expectedQuality);
|
|
|
|
|
}
|
|
|
|
@ -212,7 +206,7 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
|
|
|
|
|
GivenSpecifications(_pass1);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IParsingService>()
|
|
|
|
|
.Setup(c => c.GetLocalEpisode(It.IsAny<String>(), It.IsAny<Series>(), It.IsAny<Boolean>()))
|
|
|
|
|
.Setup(c => c.GetLocalEpisode(It.IsAny<String>(), It.IsAny<Series>(), It.IsAny<ParsedEpisodeInfo>(), It.IsAny<Boolean>()))
|
|
|
|
|
.Throws(new EpisodeNotFoundException("Episode not found"));
|
|
|
|
|
|
|
|
|
|
_videoFiles = new List<String>
|
|
|
|
@ -222,14 +216,130 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeImport
|
|
|
|
|
"The.Office.S03E115.DVDRip.XviD-OSiTV"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IMediaFileService>()
|
|
|
|
|
.Setup(c => c.FilterExistingFiles(_videoFiles, It.IsAny<Series>()))
|
|
|
|
|
.Returns(_videoFiles);
|
|
|
|
|
GivenVideoFiles(_videoFiles);
|
|
|
|
|
|
|
|
|
|
Subject.GetImportDecisions(_videoFiles, _series);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IParsingService>()
|
|
|
|
|
.Verify(c => c.GetLocalEpisode(It.IsAny<String>(), It.IsAny<Series>(), It.IsAny<ParsedEpisodeInfo>(), It.IsAny<Boolean>()), Times.Exactly(_videoFiles.Count));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_use_folder_for_full_season()
|
|
|
|
|
{
|
|
|
|
|
var videoFiles = new[]
|
|
|
|
|
{
|
|
|
|
|
@"C:\Test\Unsorted\Series.Title.S01\S01E01.mkv".AsOsAgnostic(),
|
|
|
|
|
@"C:\Test\Unsorted\Series.Title.S01\S01E02.mkv".AsOsAgnostic(),
|
|
|
|
|
@"C:\Test\Unsorted\Series.Title.S01\S01E03.mkv".AsOsAgnostic()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
GivenSpecifications(_pass1);
|
|
|
|
|
GivenVideoFiles(videoFiles);
|
|
|
|
|
|
|
|
|
|
var folderInfo = Parser.Parser.ParseTitle("Series.Title.S01");
|
|
|
|
|
|
|
|
|
|
Subject.GetImportDecisions(_videoFiles, _series, false);
|
|
|
|
|
Subject.GetImportDecisions(_videoFiles, _series, folderInfo, true);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IParsingService>()
|
|
|
|
|
.Verify(c => c.GetLocalEpisode(It.IsAny<string>(), It.IsAny<Series>(), null, true), Times.Exactly(3));
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IParsingService>()
|
|
|
|
|
.Verify(c => c.GetLocalEpisode(It.IsAny<string>(), It.IsAny<Series>(), It.Is<ParsedEpisodeInfo>(p => p != null), true), Times.Never());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_use_folder_when_it_contains_more_than_one_valid_video_file()
|
|
|
|
|
{
|
|
|
|
|
var videoFiles = new[]
|
|
|
|
|
{
|
|
|
|
|
@"C:\Test\Unsorted\Series.Title.S01E01\S01E01.mkv".AsOsAgnostic(),
|
|
|
|
|
@"C:\Test\Unsorted\Series.Title.S01E01\1x01.mkv".AsOsAgnostic()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
GivenSpecifications(_pass1);
|
|
|
|
|
GivenVideoFiles(videoFiles);
|
|
|
|
|
|
|
|
|
|
var folderInfo = Parser.Parser.ParseTitle("Series.Title.S01E01");
|
|
|
|
|
|
|
|
|
|
Subject.GetImportDecisions(_videoFiles, _series, folderInfo, true);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IParsingService>()
|
|
|
|
|
.Verify(c => c.GetLocalEpisode(It.IsAny<string>(), It.IsAny<Series>(), null, true), Times.Exactly(2));
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IParsingService>()
|
|
|
|
|
.Verify(c => c.GetLocalEpisode(It.IsAny<string>(), It.IsAny<Series>(), It.Is<ParsedEpisodeInfo>(p => p != null), true), Times.Never());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_use_folder_when_only_one_video_file()
|
|
|
|
|
{
|
|
|
|
|
var videoFiles = new[]
|
|
|
|
|
{
|
|
|
|
|
@"C:\Test\Unsorted\Series.Title.S01E01\S01E01.mkv".AsOsAgnostic()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
GivenSpecifications(_pass1);
|
|
|
|
|
GivenVideoFiles(videoFiles);
|
|
|
|
|
|
|
|
|
|
var folderInfo = Parser.Parser.ParseTitle("Series.Title.S01E01");
|
|
|
|
|
|
|
|
|
|
Subject.GetImportDecisions(_videoFiles, _series, folderInfo, true);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IParsingService>()
|
|
|
|
|
.Verify(c => c.GetLocalEpisode(It.IsAny<string>(), It.IsAny<Series>(), It.IsAny<ParsedEpisodeInfo>(), true), Times.Exactly(1));
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IParsingService>()
|
|
|
|
|
.Verify(c => c.GetLocalEpisode(It.IsAny<string>(), It.IsAny<Series>(), null, true), Times.Never());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_use_folder_when_only_one_video_file_and_a_sample()
|
|
|
|
|
{
|
|
|
|
|
var videoFiles = new[]
|
|
|
|
|
{
|
|
|
|
|
@"C:\Test\Unsorted\Series.Title.S01E01\S01E01.mkv".AsOsAgnostic(),
|
|
|
|
|
@"C:\Test\Unsorted\Series.Title.S01E01\S01E01.sample.mkv".AsOsAgnostic()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
GivenSpecifications(_pass1);
|
|
|
|
|
GivenVideoFiles(videoFiles.ToList());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IDetectSample>()
|
|
|
|
|
.Setup(s => s.IsSample(_series, It.IsAny<QualityModel>(), It.Is<string>(c => c.Contains("sample")), It.IsAny<long>(), It.IsAny<int>()))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
|
|
var folderInfo = Parser.Parser.ParseTitle("Series.Title.S01E01");
|
|
|
|
|
|
|
|
|
|
Subject.GetImportDecisions(_videoFiles, _series, folderInfo, true);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IParsingService>()
|
|
|
|
|
.Verify(c => c.GetLocalEpisode(It.IsAny<string>(), It.IsAny<Series>(), It.IsAny<ParsedEpisodeInfo>(), true), Times.Exactly(2));
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IParsingService>()
|
|
|
|
|
.Verify(c => c.GetLocalEpisode(It.IsAny<string>(), It.IsAny<Series>(), null, true), Times.Never());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_use_folder_name_if_file_name_is_scene_name()
|
|
|
|
|
{
|
|
|
|
|
var videoFiles = new[]
|
|
|
|
|
{
|
|
|
|
|
@"C:\Test\Unsorted\Series.Title.S01E01.720p.HDTV-LOL\Series.Title.S01E01.720p.HDTV-LOL.mkv".AsOsAgnostic()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
GivenSpecifications(_pass1);
|
|
|
|
|
GivenVideoFiles(videoFiles);
|
|
|
|
|
|
|
|
|
|
var folderInfo = Parser.Parser.ParseTitle("Series.Title.S01E01.720p.HDTV-LOL");
|
|
|
|
|
|
|
|
|
|
Subject.GetImportDecisions(_videoFiles, _series, folderInfo, true);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IParsingService>()
|
|
|
|
|
.Verify(c => c.GetLocalEpisode(It.IsAny<string>(), It.IsAny<Series>(), null, true), Times.Exactly(1));
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IParsingService>()
|
|
|
|
|
.Verify(c => c.GetLocalEpisode(It.IsAny<String>(), It.IsAny<Series>(), It.IsAny<Boolean>()), Times.Exactly(_videoFiles.Count));
|
|
|
|
|
.Verify(c => c.GetLocalEpisode(It.IsAny<string>(), It.IsAny<Series>(), It.Is<ParsedEpisodeInfo>(p => p != null), true), Times.Never());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|