Moved Episode Not Requested check to new Specification. Updated tests.

This commit is contained in:
Taloth Saldono 2014-04-01 21:39:17 +02:00
parent 198ff059c4
commit 38b0fae29a
6 changed files with 100 additions and 32 deletions

View File

@ -239,11 +239,16 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
Episodes = episodes.Where(v => v.SceneEpisodeNumber == p.EpisodeNumbers.First()).ToList()
});
Mocker.SetConstant<IEnumerable<IDecisionEngineSpecification>>(new List<IDecisionEngineSpecification>());
Mocker.SetConstant<IEnumerable<IDecisionEngineSpecification>>(new List<IDecisionEngineSpecification>
{
Mocker.Resolve<NzbDrone.Core.DecisionEngine.Specifications.Search.EpisodeRequestedSpecification>()
});
var decisions = Subject.GetSearchDecision(reports, criteria);
Assert.AreEqual(1, decisions.Count);
var approvedDecisions = decisions.Where(v => v.Approved).ToList();
approvedDecisions.Count.Should().Be(1);
}
}
}

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Tv;
@ -26,12 +27,12 @@ namespace NzbDrone.Core.Test.IndexerSearchTests
Mocker.GetMock<IIndexerFactory>()
.Setup(s => s.GetAvailableProviders())
.Returns(new List<IIndexer>{indexer.Object});
.Returns(new List<IIndexer> { indexer.Object });
Mocker.GetMock<NzbDrone.Core.DecisionEngine.IMakeDownloadDecision>()
.Setup(s => s.GetSearchDecision(It.IsAny<List<Parser.Model.ReleaseInfo>>(), It.IsAny<SearchCriteriaBase>()))
.Returns(new List<NzbDrone.Core.DecisionEngine.Specifications.DownloadDecision>());
_xemSeries = Builder<Series>.CreateNew()
.With(v => v.UseSceneNumbering = true)
.Build();
@ -81,12 +82,16 @@ namespace NzbDrone.Core.Test.IndexerSearchTests
WithEpisode(4, 2, 5, 14);
WithEpisode(4, 3, 6, 11);
WithEpisode(5, 1, 6, 12);
// Season 7+ maps normally, so no mapping specified.
WithEpisode(7, 1, 0, 0);
WithEpisode(7, 2, 0, 0);
}
private List<SearchCriteriaBase> WatchForSearchCriteria()
{
List<SearchCriteriaBase> result = new List<SearchCriteriaBase>();
Mocker.GetMock<IFetchFeedFromIndexers>()
.Setup(v => v.Fetch(It.IsAny<IIndexer>(), It.IsAny<SingleEpisodeSearchCriteria>()))
.Callback<IIndexer, SingleEpisodeSearchCriteria>((i, s) => result.Add(s))
@ -94,7 +99,7 @@ namespace NzbDrone.Core.Test.IndexerSearchTests
Mocker.GetMock<IFetchFeedFromIndexers>()
.Setup(v => v.Fetch(It.IsAny<IIndexer>(), It.IsAny<SeasonSearchCriteria>()))
.Callback<IIndexer,SeasonSearchCriteria>((i,s) => result.Add(s))
.Callback<IIndexer, SeasonSearchCriteria>((i, s) => result.Add(s))
.Returns(new List<Parser.Model.ReleaseInfo>());
return result;
@ -111,9 +116,9 @@ namespace NzbDrone.Core.Test.IndexerSearchTests
var criteria = allCriteria.OfType<SingleEpisodeSearchCriteria>().ToList();
Assert.AreEqual(1, criteria.Count);
Assert.AreEqual(2, criteria[0].SeasonNumber);
Assert.AreEqual(3, criteria[0].EpisodeNumber);
criteria.Count.Should().Be(1);
criteria[0].SeasonNumber.Should().Be(2);
criteria[0].EpisodeNumber.Should().Be(3);
}
[Test]
@ -127,8 +132,8 @@ namespace NzbDrone.Core.Test.IndexerSearchTests
var criteria = allCriteria.OfType<SeasonSearchCriteria>().ToList();
Assert.AreEqual(1, criteria.Count);
Assert.AreEqual(2, criteria[0].SeasonNumber);
criteria.Count.Should().Be(1);
criteria[0].SeasonNumber.Should().Be(2);
}
[Test]
@ -142,9 +147,9 @@ namespace NzbDrone.Core.Test.IndexerSearchTests
var criteria = allCriteria.OfType<SeasonSearchCriteria>().ToList();
Assert.AreEqual(2, criteria.Count);
Assert.AreEqual(3, criteria[0].SeasonNumber);
Assert.AreEqual(4, criteria[1].SeasonNumber);
criteria.Count.Should().Be(2);
criteria[0].SeasonNumber.Should().Be(3);
criteria[1].SeasonNumber.Should().Be(4);
}
[Test]
@ -159,12 +164,27 @@ namespace NzbDrone.Core.Test.IndexerSearchTests
var criteria1 = allCriteria.OfType<SeasonSearchCriteria>().ToList();
var criteria2 = allCriteria.OfType<SingleEpisodeSearchCriteria>().ToList();
Assert.AreEqual(1, criteria1.Count);
Assert.AreEqual(5, criteria1[0].SeasonNumber);
criteria1.Count.Should().Be(1);
criteria1[0].SeasonNumber.Should().Be(5);
Assert.AreEqual(1, criteria2.Count);
Assert.AreEqual(6, criteria2[0].SeasonNumber);
Assert.AreEqual(11, criteria2[0].EpisodeNumber);
criteria2.Count.Should().Be(1);
criteria2[0].SeasonNumber.Should().Be(6);
criteria2[0].EpisodeNumber.Should().Be(11);
}
[Test]
public void scene_seasonsearch_should_use_seasonnumber_if_no_scene_number_is_available()
{
WithEpisodes();
var allCriteria = WatchForSearchCriteria();
Subject.SeasonSearch(_xemSeries.Id, 7);
var criteria = allCriteria.OfType<SeasonSearchCriteria>().ToList();
criteria.Count.Should().Be(1);
criteria[0].SeasonNumber.Should().Be(7);
}
}
}

View File

@ -97,17 +97,6 @@ namespace NzbDrone.Core.DecisionEngine
if (decision != null)
{
if (searchCriteria != null)
{
var criteriaEpisodes = searchCriteria.Episodes.Select(v => v.Id).ToList();
var remoteEpisodes = decision.RemoteEpisode.Episodes.Select(v => v.Id).ToList();
if (!criteriaEpisodes.Intersect(remoteEpisodes).Any())
{
_logger.Debug("Release rejected since the episode wasn't requested: {0}", decision.RemoteEpisode.ParsedEpisodeInfo);
continue;
}
}
if (decision.Rejections.Any())
{
_logger.Debug("Release rejected for the following reasons: {0}", String.Join(", ", decision.Rejections));

View File

@ -0,0 +1,43 @@
using System.Linq;
using NLog;
using NzbDrone.Core.IndexerSearch.Definitions;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.DecisionEngine.Specifications.Search
{
public class EpisodeRequestedSpecification : IDecisionEngineSpecification
{
private readonly Logger _logger;
public EpisodeRequestedSpecification(Logger logger)
{
_logger = logger;
}
public string RejectionReason
{
get
{
return "Episode wasn't requested";
}
}
public bool IsSatisfiedBy(RemoteEpisode remoteEpisode, SearchCriteriaBase searchCriteria)
{
if (searchCriteria == null)
{
return true;
}
var criteriaEpisodes = searchCriteria.Episodes.Select(v => v.Id).ToList();
var remoteEpisodes = remoteEpisode.Episodes.Select(v => v.Id).ToList();
if (!criteriaEpisodes.Intersect(remoteEpisodes).Any())
{
_logger.Debug("Release rejected since the episode wasn't requested: {0}", remoteEpisode.ParsedEpisodeInfo);
return false;
}
return true;
}
}
}

View File

@ -142,15 +142,25 @@ namespace NzbDrone.Core.IndexerSearch
if (series.UseSceneNumbering)
{
var sceneSeasonGroups = episodes.GroupBy(v => v.SceneSeasonNumber).Distinct();
var sceneSeasonGroups = episodes.GroupBy(v =>
{
if (v.SceneSeasonNumber == 0 && v.SceneEpisodeNumber == 0)
return v.SeasonNumber;
else
return v.SceneSeasonNumber;
}).Distinct();
foreach (var sceneSeasonEpisodes in sceneSeasonGroups)
{
if (sceneSeasonEpisodes.Count() == 1)
{
var episode = sceneSeasonEpisodes.First();
var searchSpec = Get<SingleEpisodeSearchCriteria>(series, sceneSeasonEpisodes.ToList());
searchSpec.SeasonNumber = sceneSeasonEpisodes.Key;
searchSpec.EpisodeNumber = sceneSeasonEpisodes.First().SceneEpisodeNumber;
if (episode.SceneSeasonNumber == 0 && episode.SceneEpisodeNumber == 0)
searchSpec.EpisodeNumber = episode.EpisodeNumber;
else
searchSpec.EpisodeNumber = episode.SceneEpisodeNumber;
var decisions = Dispatch(indexer => _feedFetcher.Fetch(indexer, searchSpec), searchSpec);
downloadDecisions.AddRange(decisions);

View File

@ -217,6 +217,7 @@
<Compile Include="DecisionEngine\Specifications\NotRestrictedReleaseSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\NotSampleSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\RssSync\ProperSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\Search\EpisodeRequestedSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\Search\SeriesSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\Search\SeasonMatchSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\Search\DailyEpisodeMatchSpecification.cs" />