diff --git a/NzbDrone.Core.Test/SeriesSearchJobTest.cs b/NzbDrone.Core.Test/SeriesSearchJobTest.cs index 81b442854..2e3985d38 100644 --- a/NzbDrone.Core.Test/SeriesSearchJobTest.cs +++ b/NzbDrone.Core.Test/SeriesSearchJobTest.cs @@ -24,80 +24,46 @@ public class SeriesSearchJobTest : TestBase [Test] public void SeriesSearch_success() { - var episodes = Builder.CreateListOfSize(5) - .WhereAll() - .Have(e => e.SeriesId = 1) - .Have(e => e.Ignored = false) - .Build(); + var seasons = new List { 1, 2, 3, 4, 5 }; var mocker = new AutoMoqer(MockBehavior.Strict); var notification = new ProgressNotification("Series Search"); mocker.GetMock() - .Setup(c => c.GetEpisodeBySeries(1)).Returns(episodes); + .Setup(c => c.GetSeasons(1)).Returns(seasons); - mocker.GetMock() - .Setup(c => c.Start(notification, It.IsAny(), 0)).Verifiable(); + mocker.GetMock() + .Setup(c => c.Start(notification, 1, It.IsAny())).Verifiable(); //Act mocker.Resolve().Start(notification, 1, 0); //Assert mocker.VerifyAllMocks(); - mocker.GetMock().Verify(c => c.Start(notification, It.IsAny(), 0), - Times.Exactly(episodes.Count)); + mocker.GetMock().Verify(c => c.Start(notification, 1, It.IsAny()), + Times.Exactly(seasons.Count)); } [Test] - public void SeriesSearch_no_episodes() + public void SeriesSearch_no_seasons() { + var seasons = new List(); + var mocker = new AutoMoqer(MockBehavior.Strict); + var notification = new ProgressNotification("Series Search"); - List nullList = null; mocker.GetMock() - .Setup(c => c.GetEpisodeBySeries(1)).Returns(nullList); + .Setup(c => c.GetSeasons(1)).Returns(seasons); //Act mocker.Resolve().Start(notification, 1, 0); //Assert mocker.VerifyAllMocks(); - mocker.GetMock().Verify(c => c.Start(notification, It.IsAny(), 0), + mocker.GetMock().Verify(c => c.Start(notification, 1, It.IsAny()), Times.Never()); - ExceptionVerification.ExcpectedWarns(1); - } - - [Test] - public void SeriesSearch_skip_ignored() - { - var episodes = Builder.CreateListOfSize(10) - .WhereAll() - .Have(e => e.SeriesId = 1) - .WhereTheFirst(5) - .Have(e => e.Ignored = false) - .AndTheRemaining() - .Have(e => e.Ignored = true) - .Build(); - - var mocker = new AutoMoqer(MockBehavior.Strict); - - var notification = new ProgressNotification("Series Search"); - - mocker.GetMock() - .Setup(c => c.GetEpisodeBySeries(1)).Returns(episodes); - - mocker.GetMock() - .Setup(c => c.Start(notification, It.IsAny(), 0)).Verifiable(); - - //Act - mocker.Resolve().Start(notification, 1, 0); - - //Assert - mocker.VerifyAllMocks(); - mocker.GetMock().Verify(c => c.Start(notification, It.IsAny(), 0), - Times.Exactly(5)); } } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/Jobs/SeasonSearchJob.cs b/NzbDrone.Core/Providers/Jobs/SeasonSearchJob.cs index 698d62961..68736b109 100644 --- a/NzbDrone.Core/Providers/Jobs/SeasonSearchJob.cs +++ b/NzbDrone.Core/Providers/Jobs/SeasonSearchJob.cs @@ -24,6 +24,11 @@ public SeasonSearchJob(SearchProvider searchProvider, EpisodeSearchJob episodeSe _episodeProvider = episodeProvider; } + public SeasonSearchJob() + { + + } + public string Name { get { return "Season Search"; } @@ -34,7 +39,7 @@ public int DefaultInterval get { return 0; } } - public void Start(ProgressNotification notification, int targetId, int secondaryTargetId) + public virtual void Start(ProgressNotification notification, int targetId, int secondaryTargetId) { if (targetId <= 0) throw new ArgumentOutOfRangeException("targetId"); diff --git a/NzbDrone.Core/Providers/Jobs/SeriesSearchJob.cs b/NzbDrone.Core/Providers/Jobs/SeriesSearchJob.cs index e5d7acd34..e5dd26b2d 100644 --- a/NzbDrone.Core/Providers/Jobs/SeriesSearchJob.cs +++ b/NzbDrone.Core/Providers/Jobs/SeriesSearchJob.cs @@ -11,14 +11,14 @@ namespace NzbDrone.Core.Providers.Jobs public class SeriesSearchJob : IJob { private readonly EpisodeProvider _episodeProvider; - private readonly EpisodeSearchJob _episodeSearchJob; + private readonly SeasonSearchJob _seasonSearchJob; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - public SeriesSearchJob(EpisodeProvider episodeProvider, EpisodeSearchJob episodeSearchJob) + public SeriesSearchJob(EpisodeProvider episodeProvider, SeasonSearchJob seasonSearchJob) { _episodeProvider = episodeProvider; - _episodeSearchJob = episodeSearchJob; + _seasonSearchJob = seasonSearchJob; } public string Name @@ -36,20 +36,16 @@ public void Start(ProgressNotification notification, int targetId, int secondary if (targetId <= 0) throw new ArgumentOutOfRangeException("targetId"); - Logger.Debug("Getting episodes from database for series: {0}.", targetId); - var episodes = _episodeProvider.GetEpisodeBySeries(targetId); + Logger.Debug("Getting seasons from database for series: {0}", targetId); + var seasons = _episodeProvider.GetSeasons(targetId); - if (episodes == null) + foreach (var season in seasons) { - Logger.Warn("No episodes in database found for series: {0}.", targetId); - return; - } + //Skip ignored seasons + if (_episodeProvider.IsIgnored(targetId, season)) + continue; - //Todo: Search for a full season NZB before individual episodes - - foreach (var episode in episodes.Where(e => !e.Ignored)) - { - _episodeSearchJob.Start(notification, episode.EpisodeId, 0); + _seasonSearchJob.Start(notification, targetId, season); } } }