Validate series is the one searched for

pull/6/head
Mark McDowall 11 years ago
parent fbf242d3d5
commit 0ab7d035e1

@ -0,0 +1,45 @@
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.DecisionEngine.Specifications.Search;
using NzbDrone.Core.IndexerSearch.Definitions;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Tv;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.DecisionEngineTests.Search
{
[TestFixture]
public class SeriesSpecificationFixture : TestBase<SeriesSpecification>
{
private Series _series1;
private Series _series2;
private RemoteEpisode _remoteEpisode = new RemoteEpisode();
private SearchCriteriaBase _searchCriteria = new SingleEpisodeSearchCriteria();
[SetUp]
public void Setup()
{
_series1 = Builder<Series>.CreateNew().With(s => s.Id = 1).Build();
_series2 = Builder<Series>.CreateNew().With(s => s.Id = 2).Build();
_remoteEpisode.Series = _series1;
}
[Test]
public void should_return_false_if_series_doesnt_match()
{
_searchCriteria.Series = _series2;
Subject.IsSatisfiedBy(_remoteEpisode, _searchCriteria).Should().BeFalse();
}
[Test]
public void should_return_true_when_series_ids_match()
{
_searchCriteria.Series = _series1;
Subject.IsSatisfiedBy(_remoteEpisode, _searchCriteria).Should().BeTrue();
}
}
}

@ -118,6 +118,7 @@
<Compile Include="DecisionEngineTests\CutoffSpecificationFixture.cs" />
<Compile Include="DecisionEngineTests\NotRestrictedReleaseSpecificationFixture.cs" />
<Compile Include="DecisionEngineTests\RssSync\ProperSpecificationFixture.cs" />
<Compile Include="DecisionEngineTests\Search\SeriesSpecificationFixture.cs" />
<Compile Include="Download\DownloadApprovedReportsTests\DownloadApprovedFixture.cs" />
<Compile Include="Download\DownloadApprovedReportsTests\GetQualifiedReportsFixture.cs" />
<Compile Include="Download\DownloadClientTests\BlackholeProviderFixture.cs" />

@ -0,0 +1,42 @@
using NLog;
using NzbDrone.Core.IndexerSearch.Definitions;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.DecisionEngine.Specifications.Search
{
public class SeriesSpecification : IDecisionEngineSpecification
{
private readonly Logger _logger;
public SeriesSpecification(Logger logger)
{
_logger = logger;
}
public string RejectionReason
{
get
{
return "Wrong series";
}
}
public bool IsSatisfiedBy(RemoteEpisode remoteEpisode, SearchCriteriaBase searchCriteria)
{
if (searchCriteria == null)
{
return true;
}
_logger.Trace("Checking if series matches searched series");
if (remoteEpisode.Series.Id != searchCriteria.Series.Id)
{
_logger.Trace("Series {0} does not match {1}", remoteEpisode.Series, searchCriteria.Series);
return false;
}
return true;
}
}
}

@ -218,6 +218,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\SeriesSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\Search\SeasonMatchSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\Search\DailyEpisodeMatchSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\AcceptableSizeSpecification.cs" />

Loading…
Cancel
Save