mirror of https://github.com/Radarr/Radarr
Moved Episode Not Requested check to new Specification. Updated tests.
This commit is contained in:
parent
198ff059c4
commit
38b0fae29a
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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,7 +27,7 @@ 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>()))
|
||||
|
@ -81,6 +82,10 @@ 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()
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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" />
|
||||
|
|
Loading…
Reference in New Issue