From 0ab7d035e1ca22686de1a68411606622f24fc4c7 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 30 Jan 2014 17:35:22 -0800 Subject: [PATCH] Validate series is the one searched for --- .../Search/SeriesSpecificationFixture.cs | 45 +++++++++++++++++++ .../NzbDrone.Core.Test.csproj | 1 + .../Search/SeriesSpecification.cs | 42 +++++++++++++++++ src/NzbDrone.Core/NzbDrone.Core.csproj | 1 + 4 files changed, 89 insertions(+) create mode 100644 src/NzbDrone.Core.Test/DecisionEngineTests/Search/SeriesSpecificationFixture.cs create mode 100644 src/NzbDrone.Core/DecisionEngine/Specifications/Search/SeriesSpecification.cs diff --git a/src/NzbDrone.Core.Test/DecisionEngineTests/Search/SeriesSpecificationFixture.cs b/src/NzbDrone.Core.Test/DecisionEngineTests/Search/SeriesSpecificationFixture.cs new file mode 100644 index 000000000..a868ebc2a --- /dev/null +++ b/src/NzbDrone.Core.Test/DecisionEngineTests/Search/SeriesSpecificationFixture.cs @@ -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 + { + private Series _series1; + private Series _series2; + private RemoteEpisode _remoteEpisode = new RemoteEpisode(); + private SearchCriteriaBase _searchCriteria = new SingleEpisodeSearchCriteria(); + + [SetUp] + public void Setup() + { + _series1 = Builder.CreateNew().With(s => s.Id = 1).Build(); + _series2 = Builder.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(); + } + } +} diff --git a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 326789038..c9c4da8b6 100644 --- a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -118,6 +118,7 @@ + diff --git a/src/NzbDrone.Core/DecisionEngine/Specifications/Search/SeriesSpecification.cs b/src/NzbDrone.Core/DecisionEngine/Specifications/Search/SeriesSpecification.cs new file mode 100644 index 000000000..8a30288d2 --- /dev/null +++ b/src/NzbDrone.Core/DecisionEngine/Specifications/Search/SeriesSpecification.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; + } + } +} \ No newline at end of file diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 43c0f7b67..c2be091cf 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -218,6 +218,7 @@ +