Cutoff moved to its own spec

This commit is contained in:
Mark McDowall 2013-09-10 19:07:22 -07:00
parent 92cc41edeb
commit 33fa468f91
9 changed files with 66 additions and 16 deletions

View File

@ -8,26 +8,26 @@ using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.DecisionEngineTests namespace NzbDrone.Core.Test.DecisionEngineTests
{ {
[TestFixture] [TestFixture]
public class QualityUpgradableSpecificationFixture : CoreTest<QualityUpgradableSpecification> public class CutoffSpecificationFixture : CoreTest<QualityUpgradableSpecification>
{ {
[Test] [Test]
public void IsUpgradePossible_should_return_true_if_current_episode_is_less_than_cutoff() public void IsUpgradePossible_should_return_true_if_current_episode_is_less_than_cutoff()
{ {
Subject.IsUpgradable(new QualityProfile { Cutoff = Quality.Bluray1080p }, Subject.CutoffNotMet(new QualityProfile { Cutoff = Quality.Bluray1080p },
new QualityModel(Quality.DVD, true)).Should().BeTrue(); new QualityModel(Quality.DVD, true)).Should().BeTrue();
} }
[Test] [Test]
public void IsUpgradePossible_should_return_false_if_current_episode_is_equal_to_cutoff() public void IsUpgradePossible_should_return_false_if_current_episode_is_equal_to_cutoff()
{ {
Subject.IsUpgradable(new QualityProfile { Cutoff = Quality.HDTV720p }, Subject.CutoffNotMet(new QualityProfile { Cutoff = Quality.HDTV720p },
new QualityModel(Quality.HDTV720p, true)).Should().BeFalse(); new QualityModel(Quality.HDTV720p, true)).Should().BeFalse();
} }
[Test] [Test]
public void IsUpgradePossible_should_return_false_if_current_episode_is_greater_than_cutoff() public void IsUpgradePossible_should_return_false_if_current_episode_is_greater_than_cutoff()
{ {
Subject.IsUpgradable(new QualityProfile { Cutoff = Quality.HDTV720p }, Subject.CutoffNotMet(new QualityProfile { Cutoff = Quality.HDTV720p },
new QualityModel(Quality.Bluray1080p, true)).Should().BeFalse(); new QualityModel(Quality.Bluray1080p, true)).Should().BeFalse();
} }
} }

View File

@ -17,7 +17,6 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
new object[] { Quality.SDTV, false, Quality.SDTV, true, Quality.SDTV, true }, new object[] { Quality.SDTV, false, Quality.SDTV, true, Quality.SDTV, true },
new object[] { Quality.WEBDL720p, false, Quality.WEBDL720p, true, Quality.WEBDL720p, true }, new object[] { Quality.WEBDL720p, false, Quality.WEBDL720p, true, Quality.WEBDL720p, true },
new object[] { Quality.SDTV, false, Quality.SDTV, false, Quality.SDTV, false }, new object[] { Quality.SDTV, false, Quality.SDTV, false, Quality.SDTV, false },
new object[] { Quality.SDTV, false, Quality.DVD, true, Quality.SDTV, false },
new object[] { Quality.WEBDL720p, false, Quality.HDTV720p, true, Quality.Bluray720p, false }, new object[] { Quality.WEBDL720p, false, Quality.HDTV720p, true, Quality.Bluray720p, false },
new object[] { Quality.WEBDL720p, false, Quality.HDTV720p, true, Quality.WEBDL720p, false }, new object[] { Quality.WEBDL720p, false, Quality.HDTV720p, true, Quality.WEBDL720p, false },
new object[] { Quality.WEBDL720p, false, Quality.WEBDL720p, false, Quality.WEBDL720p, false }, new object[] { Quality.WEBDL720p, false, Quality.WEBDL720p, false, Quality.WEBDL720p, false },
@ -37,7 +36,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
{ {
GivenAutoDownloadPropers(true); GivenAutoDownloadPropers(true);
Subject.IsUpgradable(new QualityProfile() { Cutoff = cutoff }, new QualityModel(current, currentProper), new QualityModel(newQuality, newProper)) Subject.IsUpgradable(new QualityModel(current, currentProper), new QualityModel(newQuality, newProper))
.Should().Be(expected); .Should().Be(expected);
} }
@ -46,8 +45,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
{ {
GivenAutoDownloadPropers(false); GivenAutoDownloadPropers(false);
Subject.IsUpgradable(new QualityProfile { Cutoff = Quality.Bluray1080p }, Subject.IsUpgradable(new QualityModel(Quality.DVD, true),
new QualityModel(Quality.DVD, true),
new QualityModel(Quality.DVD, false)).Should().BeFalse(); new QualityModel(Quality.DVD, false)).Should().BeFalse();
} }
} }

View File

@ -110,6 +110,7 @@
<Compile Include="Datastore\ReflectionStrategyFixture\Benchmarks.cs" /> <Compile Include="Datastore\ReflectionStrategyFixture\Benchmarks.cs" />
<Compile Include="Datastore\SQLiteMigrationHelperTests\AlterFixture.cs" /> <Compile Include="Datastore\SQLiteMigrationHelperTests\AlterFixture.cs" />
<Compile Include="Datastore\SQLiteMigrationHelperTests\DuplicateFixture.cs" /> <Compile Include="Datastore\SQLiteMigrationHelperTests\DuplicateFixture.cs" />
<Compile Include="DecisionEngineTests\CutoffSpecificationFixture.cs" />
<Compile Include="DecisionEngineTests\NotRestrictedReleaseSpecificationFixture.cs" /> <Compile Include="DecisionEngineTests\NotRestrictedReleaseSpecificationFixture.cs" />
<Compile Include="Download\DownloadApprovedReportsTests\DownloadApprovedFixture.cs" /> <Compile Include="Download\DownloadApprovedReportsTests\DownloadApprovedFixture.cs" />
<Compile Include="Download\DownloadApprovedReportsTests\GetQualifiedReportsFixture.cs" /> <Compile Include="Download\DownloadApprovedReportsTests\GetQualifiedReportsFixture.cs" />
@ -181,7 +182,6 @@
<Compile Include="DecisionEngineTests\UpgradeHistorySpecificationFixture.cs" /> <Compile Include="DecisionEngineTests\UpgradeHistorySpecificationFixture.cs" />
<Compile Include="DecisionEngineTests\UpgradeDiskSpecificationFixture.cs" /> <Compile Include="DecisionEngineTests\UpgradeDiskSpecificationFixture.cs" />
<Compile Include="DecisionEngineTests\QualityUpgradeSpecificationFixture.cs" /> <Compile Include="DecisionEngineTests\QualityUpgradeSpecificationFixture.cs" />
<Compile Include="DecisionEngineTests\QualityUpgradableSpecificationFixture.cs" />
<Compile Include="ProviderTests\DiskProviderTests\FreeDiskSpaceFixture.cs" /> <Compile Include="ProviderTests\DiskProviderTests\FreeDiskSpaceFixture.cs" />
<Compile Include="NotificationTests\ProwlProviderTest.cs" /> <Compile Include="NotificationTests\ProwlProviderTest.cs" />
<Compile Include="ProviderTests\DiskProviderTests\ArchiveProviderFixture.cs" /> <Compile Include="ProviderTests\DiskProviderTests\ArchiveProviderFixture.cs" />

View File

@ -1,3 +1,4 @@
using System;
using NLog; using NLog;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Qualities; using NzbDrone.Core.Qualities;
@ -7,7 +8,8 @@ namespace NzbDrone.Core.DecisionEngine
{ {
public interface IQualityUpgradableSpecification public interface IQualityUpgradableSpecification
{ {
bool IsUpgradable(QualityProfile profile, QualityModel currentQuality, QualityModel newQuality = null); bool IsUpgradable(QualityModel currentQuality, QualityModel newQuality = null);
bool CutoffNotMet(QualityProfile profile, QualityModel currentQuality, QualityModel newQuality = null);
} }
public class QualityUpgradableSpecification : IQualityUpgradableSpecification public class QualityUpgradableSpecification : IQualityUpgradableSpecification
@ -21,7 +23,7 @@ namespace NzbDrone.Core.DecisionEngine
_logger = logger; _logger = logger;
} }
public bool IsUpgradable(QualityProfile profile, QualityModel currentQuality, QualityModel newQuality = null) public bool IsUpgradable(QualityModel currentQuality, QualityModel newQuality = null)
{ {
if (newQuality != null) if (newQuality != null)
{ {
@ -38,6 +40,11 @@ namespace NzbDrone.Core.DecisionEngine
} }
} }
return true;
}
public bool CutoffNotMet(QualityProfile profile, QualityModel currentQuality, QualityModel newQuality = null)
{
if (currentQuality.Quality >= profile.Cutoff) if (currentQuality.Quality >= profile.Cutoff)
{ {
_logger.Trace("Existing item meets cut-off. skipping."); _logger.Trace("Existing item meets cut-off. skipping.");

View File

@ -0,0 +1,44 @@
using System;
using System.Linq;
using NLog;
using NzbDrone.Core.IndexerSearch.Definitions;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.DecisionEngine.Specifications
{
public class CutoffSpecification : IDecisionEngineSpecification
{
private readonly QualityUpgradableSpecification _qualityUpgradableSpecification;
private readonly Logger _logger;
public CutoffSpecification(QualityUpgradableSpecification qualityUpgradableSpecification, Logger logger)
{
_qualityUpgradableSpecification = qualityUpgradableSpecification;
_logger = logger;
}
public string RejectionReason
{
get
{
return "Cutoff has already been met";
}
}
public virtual bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
{
foreach (var file in subject.Episodes.Where(c => c.EpisodeFileId != 0).Select(c => c.EpisodeFile.Value))
{
_logger.Trace("Comparing file quality with report. Existing file is {0}", file.Quality);
if (!_qualityUpgradableSpecification.CutoffNotMet(subject.Series.QualityProfile, file.Quality, subject.ParsedEpisodeInfo.Quality))
{
return false;
}
}
return true;
}
}
}

View File

@ -22,7 +22,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
{ {
get get
{ {
return "Higher quality report exists in history"; return "Existing file in history is of equal or higher quality";
} }
} }
@ -40,7 +40,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
if (bestQualityInHistory != null) if (bestQualityInHistory != null)
{ {
_logger.Trace("Comparing history quality with report. History is {0}", bestQualityInHistory); _logger.Trace("Comparing history quality with report. History is {0}", bestQualityInHistory);
if (!_qualityUpgradableSpecification.IsUpgradable(subject.Series.QualityProfile, bestQualityInHistory, subject.ParsedEpisodeInfo.Quality)) if (!_qualityUpgradableSpecification.IsUpgradable(bestQualityInHistory, subject.ParsedEpisodeInfo.Quality))
return false; return false;
} }
} }

View File

@ -21,7 +21,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
{ {
get get
{ {
return "Higher quality exists on disk"; return "Existing file on disk is of equal or higher quality";
} }
} }
@ -31,7 +31,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
{ {
_logger.Trace("Comparing file quality with report. Existing file is {0}", file.Quality); _logger.Trace("Comparing file quality with report. Existing file is {0}", file.Quality);
if (!_qualityUpgradableSpecification.IsUpgradable(subject.Series.QualityProfile, file.Quality, subject.ParsedEpisodeInfo.Quality)) if (!_qualityUpgradableSpecification.IsUpgradable(file.Quality, subject.ParsedEpisodeInfo.Quality))
{ {
return false; return false;
} }

View File

@ -182,9 +182,10 @@
<Compile Include="Datastore\PagingSpecExtensions.cs" /> <Compile Include="Datastore\PagingSpecExtensions.cs" />
<Compile Include="Datastore\RelationshipExtensions.cs" /> <Compile Include="Datastore\RelationshipExtensions.cs" />
<Compile Include="Datastore\TableMapping.cs" /> <Compile Include="Datastore\TableMapping.cs" />
<Compile Include="DecisionEngine\DownloadDecision.cs" /> <Compile Include="DecisionEngine\Specifications\DownloadDecision.cs" />
<Compile Include="DecisionEngine\IRejectWithReason.cs" /> <Compile Include="DecisionEngine\IRejectWithReason.cs" />
<Compile Include="DecisionEngine\IDecisionEngineSpecification.cs" /> <Compile Include="DecisionEngine\IDecisionEngineSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\CutoffSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\NotRestrictedReleaseSpecification.cs" /> <Compile Include="DecisionEngine\Specifications\NotRestrictedReleaseSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\Search\SeasonMatchSpecification.cs" /> <Compile Include="DecisionEngine\Specifications\Search\SeasonMatchSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\Search\DailyEpisodeMatchSpecification.cs" /> <Compile Include="DecisionEngine\Specifications\Search\DailyEpisodeMatchSpecification.cs" />