2013-04-07 09:30:37 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2013-03-07 04:45:36 +01:00
|
|
|
|
using FluentAssertions;
|
2012-02-07 06:08:07 +01:00
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
2013-02-19 03:19:38 +01:00
|
|
|
|
using NzbDrone.Core.DecisionEngine;
|
2013-04-15 03:41:39 +02:00
|
|
|
|
using NzbDrone.Core.Parser;
|
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
2012-02-07 06:08:07 +01:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2013-04-28 21:46:13 +02:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2013-04-30 05:43:05 +02:00
|
|
|
|
using NzbDrone.Test.Common;
|
2012-02-07 06:08:07 +01:00
|
|
|
|
|
2013-02-19 03:19:38 +01:00
|
|
|
|
namespace NzbDrone.Core.Test.DecisionEngineTests
|
2012-02-07 06:08:07 +01:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2013-06-28 22:23:41 +02:00
|
|
|
|
public class DownloadDecisionMakerFixture : CoreTest<DownloadDecisionMaker>
|
2012-02-07 06:08:07 +01:00
|
|
|
|
{
|
2013-04-15 03:41:39 +02:00
|
|
|
|
private List<ReportInfo> _reports;
|
|
|
|
|
private RemoteEpisode _remoteEpisode;
|
2012-02-07 06:08:07 +01:00
|
|
|
|
|
2013-04-07 09:30:37 +02:00
|
|
|
|
private Mock<IDecisionEngineSpecification> _pass1;
|
|
|
|
|
private Mock<IDecisionEngineSpecification> _pass2;
|
|
|
|
|
private Mock<IDecisionEngineSpecification> _pass3;
|
2013-01-16 02:36:02 +01:00
|
|
|
|
|
2013-04-07 09:30:37 +02:00
|
|
|
|
private Mock<IDecisionEngineSpecification> _fail1;
|
|
|
|
|
private Mock<IDecisionEngineSpecification> _fail2;
|
|
|
|
|
private Mock<IDecisionEngineSpecification> _fail3;
|
2012-02-07 06:08:07 +01:00
|
|
|
|
|
2013-03-07 02:51:47 +01:00
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
2012-02-07 06:08:07 +01:00
|
|
|
|
{
|
2013-04-07 09:30:37 +02:00
|
|
|
|
_pass1 = new Mock<IDecisionEngineSpecification>();
|
|
|
|
|
_pass2 = new Mock<IDecisionEngineSpecification>();
|
|
|
|
|
_pass3 = new Mock<IDecisionEngineSpecification>();
|
2012-02-07 06:08:07 +01:00
|
|
|
|
|
2013-04-07 09:30:37 +02:00
|
|
|
|
_fail1 = new Mock<IDecisionEngineSpecification>();
|
|
|
|
|
_fail2 = new Mock<IDecisionEngineSpecification>();
|
|
|
|
|
_fail3 = new Mock<IDecisionEngineSpecification>();
|
2012-02-07 06:08:07 +01:00
|
|
|
|
|
2013-08-07 05:18:05 +02:00
|
|
|
|
_pass1.Setup(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null)).Returns(true);
|
2013-04-29 03:47:06 +02:00
|
|
|
|
_pass1.Setup(c => c.RejectionReason).Returns("_pass1");
|
|
|
|
|
|
2013-08-07 05:18:05 +02:00
|
|
|
|
_pass2.Setup(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null)).Returns(true);
|
2013-04-29 03:47:06 +02:00
|
|
|
|
_pass2.Setup(c => c.RejectionReason).Returns("_pass2");
|
|
|
|
|
|
2013-08-07 05:18:05 +02:00
|
|
|
|
_pass3.Setup(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null)).Returns(true);
|
2013-04-29 03:47:06 +02:00
|
|
|
|
_pass3.Setup(c => c.RejectionReason).Returns("_pass3");
|
|
|
|
|
|
2012-02-07 06:08:07 +01:00
|
|
|
|
|
2013-08-07 05:18:05 +02:00
|
|
|
|
_fail1.Setup(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null)).Returns(false);
|
2013-04-29 03:47:06 +02:00
|
|
|
|
_fail1.Setup(c => c.RejectionReason).Returns("_fail1");
|
|
|
|
|
|
2013-08-07 05:18:05 +02:00
|
|
|
|
_fail2.Setup(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null)).Returns(false);
|
2013-04-29 03:47:06 +02:00
|
|
|
|
_fail2.Setup(c => c.RejectionReason).Returns("_fail2");
|
|
|
|
|
|
2013-08-07 05:18:05 +02:00
|
|
|
|
_fail3.Setup(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null)).Returns(false);
|
2013-04-29 03:47:06 +02:00
|
|
|
|
_fail3.Setup(c => c.RejectionReason).Returns("_fail3");
|
2012-02-07 06:08:07 +01:00
|
|
|
|
|
2013-04-28 21:46:13 +02:00
|
|
|
|
_reports = new List<ReportInfo> { new ReportInfo { Title = "The.Office.S03E115.DVDRip.XviD-OSiTV" } };
|
|
|
|
|
_remoteEpisode = new RemoteEpisode { Series = new Series() };
|
2013-04-15 03:41:39 +02:00
|
|
|
|
|
2013-04-28 21:46:13 +02:00
|
|
|
|
Mocker.GetMock<IParsingService>().Setup(c => c.Map(It.IsAny<ParsedEpisodeInfo>()))
|
2013-04-15 03:41:39 +02:00
|
|
|
|
.Returns(_remoteEpisode);
|
2012-09-19 17:13:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-07 09:30:37 +02:00
|
|
|
|
private void GivenSpecifications(params Mock<IDecisionEngineSpecification>[] mocks)
|
2013-03-07 04:45:36 +01:00
|
|
|
|
{
|
2013-04-07 19:53:04 +02:00
|
|
|
|
Mocker.SetConstant<IEnumerable<IRejectWithReason>>(mocks.Select(c => c.Object));
|
2013-03-07 04:45:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-07 06:08:07 +01:00
|
|
|
|
[Test]
|
2013-03-07 02:51:47 +01:00
|
|
|
|
public void should_call_all_specifications()
|
2012-02-07 06:08:07 +01:00
|
|
|
|
{
|
2013-03-07 04:45:36 +01:00
|
|
|
|
GivenSpecifications(_pass1, _pass2, _pass3, _fail1, _fail2, _fail3);
|
|
|
|
|
|
2013-04-15 03:41:39 +02:00
|
|
|
|
Subject.GetRssDecision(_reports).ToList();
|
2013-03-07 04:45:36 +01:00
|
|
|
|
|
2013-08-07 05:18:05 +02:00
|
|
|
|
_fail1.Verify(c => c.IsSatisfiedBy(_remoteEpisode, null), Times.Once());
|
|
|
|
|
_fail2.Verify(c => c.IsSatisfiedBy(_remoteEpisode, null), Times.Once());
|
|
|
|
|
_fail3.Verify(c => c.IsSatisfiedBy(_remoteEpisode, null), Times.Once());
|
|
|
|
|
_pass1.Verify(c => c.IsSatisfiedBy(_remoteEpisode, null), Times.Once());
|
|
|
|
|
_pass2.Verify(c => c.IsSatisfiedBy(_remoteEpisode, null), Times.Once());
|
|
|
|
|
_pass3.Verify(c => c.IsSatisfiedBy(_remoteEpisode, null), Times.Once());
|
2013-03-07 04:45:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-29 03:47:06 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void should_return_rejected_if_single_specs_fail()
|
|
|
|
|
{
|
|
|
|
|
GivenSpecifications(_fail1);
|
|
|
|
|
|
|
|
|
|
var result = Subject.GetRssDecision(_reports);
|
|
|
|
|
|
|
|
|
|
result.Single().Approved.Should().BeFalse();
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-07 04:45:36 +01:00
|
|
|
|
[Test]
|
|
|
|
|
public void should_return_rejected_if_one_of_specs_fail()
|
|
|
|
|
{
|
|
|
|
|
GivenSpecifications(_pass1, _fail1, _pass2, _pass3);
|
|
|
|
|
|
2013-04-15 03:41:39 +02:00
|
|
|
|
var result = Subject.GetRssDecision(_reports);
|
2013-03-07 04:45:36 +01:00
|
|
|
|
|
2013-04-07 09:30:37 +02:00
|
|
|
|
result.Single().Approved.Should().BeFalse();
|
2013-03-07 04:45:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_return_pass_if_all_specs_pass()
|
|
|
|
|
{
|
|
|
|
|
GivenSpecifications(_pass1, _pass2, _pass3);
|
|
|
|
|
|
2013-04-15 03:41:39 +02:00
|
|
|
|
var result = Subject.GetRssDecision(_reports);
|
2013-03-07 04:45:36 +01:00
|
|
|
|
|
2013-04-07 09:30:37 +02:00
|
|
|
|
result.Single().Approved.Should().BeTrue();
|
2013-03-07 04:45:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_have_same_number_of_rejections_as_specs_that_failed()
|
|
|
|
|
{
|
|
|
|
|
GivenSpecifications(_pass1, _pass2, _pass3, _fail1, _fail2, _fail3);
|
|
|
|
|
|
2013-04-15 03:41:39 +02:00
|
|
|
|
var result = Subject.GetRssDecision(_reports);
|
2013-04-07 09:30:37 +02:00
|
|
|
|
result.Single().Rejections.Should().HaveCount(3);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-28 02:25:28 +02:00
|
|
|
|
[Test]
|
2013-04-28 21:46:13 +02:00
|
|
|
|
public void should_not_attempt_to_map_episode_if_not_parsable()
|
2013-04-28 02:25:28 +02:00
|
|
|
|
{
|
|
|
|
|
GivenSpecifications(_pass1, _pass2, _pass3);
|
2013-04-28 21:46:13 +02:00
|
|
|
|
_reports[0].Title = "Not parsable";
|
2013-04-28 02:25:28 +02:00
|
|
|
|
|
|
|
|
|
var results = Subject.GetRssDecision(_reports).ToList();
|
|
|
|
|
|
2013-04-28 21:46:13 +02:00
|
|
|
|
Mocker.GetMock<IParsingService>().Verify(c => c.Map(It.IsAny<ParsedEpisodeInfo>()), Times.Never());
|
|
|
|
|
|
2013-08-07 05:18:05 +02:00
|
|
|
|
_pass1.Verify(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null), Times.Never());
|
|
|
|
|
_pass2.Verify(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null), Times.Never());
|
|
|
|
|
_pass3.Verify(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null), Times.Never());
|
2013-04-28 02:25:28 +02:00
|
|
|
|
|
|
|
|
|
results.Should().BeEmpty();
|
2013-04-28 21:46:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-28 22:23:41 +02:00
|
|
|
|
[Test] public void should_not_attempt_to_map_episode_series_title_is_blank()
|
|
|
|
|
{
|
|
|
|
|
GivenSpecifications(_pass1, _pass2, _pass3);
|
|
|
|
|
_reports[0].Title = "1937 - Snow White and the Seven Dwarves";
|
|
|
|
|
|
|
|
|
|
var results = Subject.GetRssDecision(_reports).ToList();
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IParsingService>().Verify(c => c.Map(It.IsAny<ParsedEpisodeInfo>()), Times.Never());
|
|
|
|
|
|
2013-08-07 05:18:05 +02:00
|
|
|
|
_pass1.Verify(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null), Times.Never());
|
|
|
|
|
_pass2.Verify(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null), Times.Never());
|
|
|
|
|
_pass3.Verify(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null), Times.Never());
|
2013-06-28 22:23:41 +02:00
|
|
|
|
|
|
|
|
|
results.Should().BeEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-28 21:46:13 +02:00
|
|
|
|
[Test]
|
2013-06-28 22:23:41 +02:00
|
|
|
|
public void should_not_attempt_to_make_decision_if_series_is_unknown()
|
2013-04-28 21:46:13 +02:00
|
|
|
|
{
|
|
|
|
|
GivenSpecifications(_pass1, _pass2, _pass3);
|
|
|
|
|
|
|
|
|
|
_remoteEpisode.Series = null;
|
|
|
|
|
|
|
|
|
|
Subject.GetRssDecision(_reports);
|
|
|
|
|
|
2013-08-07 05:18:05 +02:00
|
|
|
|
_pass1.Verify(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null), Times.Never());
|
|
|
|
|
_pass2.Verify(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null), Times.Never());
|
|
|
|
|
_pass3.Verify(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null), Times.Never());
|
2013-04-28 21:46:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2013-04-30 05:43:05 +02:00
|
|
|
|
public void broken_report_shouldnt_blowup_the_process()
|
|
|
|
|
{
|
|
|
|
|
GivenSpecifications(_pass1);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IParsingService>().Setup(c => c.Map(It.IsAny<ParsedEpisodeInfo>()))
|
|
|
|
|
.Throws<TestException>();
|
|
|
|
|
|
|
|
|
|
_reports = new List<ReportInfo>
|
|
|
|
|
{
|
|
|
|
|
new ReportInfo{Title = "The.Office.S03E115.DVDRip.XviD-OSiTV"},
|
|
|
|
|
new ReportInfo{Title = "The.Office.S03E115.DVDRip.XviD-OSiTV"},
|
|
|
|
|
new ReportInfo{Title = "The.Office.S03E115.DVDRip.XviD-OSiTV"}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Subject.GetRssDecision(_reports);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IParsingService>().Verify(c => c.Map(It.IsAny<ParsedEpisodeInfo>()), Times.Exactly(_reports.Count));
|
|
|
|
|
|
|
|
|
|
ExceptionVerification.ExpectedErrors(3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2013-07-06 23:47:49 +02:00
|
|
|
|
public void should_return_unknown_series_rejection_if_series_is_unknown()
|
2013-04-28 21:46:13 +02:00
|
|
|
|
{
|
|
|
|
|
GivenSpecifications(_pass1, _pass2, _pass3);
|
|
|
|
|
|
|
|
|
|
_remoteEpisode.Series = null;
|
|
|
|
|
|
|
|
|
|
var result = Subject.GetRssDecision(_reports);
|
|
|
|
|
|
|
|
|
|
result.Should().HaveCount(1);
|
2013-04-28 02:25:28 +02:00
|
|
|
|
}
|
2012-02-07 06:08:07 +01:00
|
|
|
|
}
|
|
|
|
|
}
|