From 75cfb7e044af542132c5d32a57f821ecd399be2c Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 11 Dec 2011 23:22:28 -0800 Subject: [PATCH] Season Search will only search for past episodes if it falls back to that. --- .../JobTests/SeasonSearchJobTest.cs | 94 +++++++++++++------ NzbDrone.Core/Jobs/SeasonSearchJob.cs | 2 +- 2 files changed, 65 insertions(+), 31 deletions(-) diff --git a/NzbDrone.Core.Test/JobTests/SeasonSearchJobTest.cs b/NzbDrone.Core.Test/JobTests/SeasonSearchJobTest.cs index e1b83f75d..9328a626f 100644 --- a/NzbDrone.Core.Test/JobTests/SeasonSearchJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/SeasonSearchJobTest.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using FizzWare.NBuilder; @@ -20,21 +21,19 @@ namespace NzbDrone.Core.Test.JobTests [Test] public void SeasonSearch_full_season_success() { - var mocker = new AutoMoqer(MockBehavior.Strict); - var notification = new ProgressNotification("Season Search"); - mocker.GetMock() + Mocker.GetMock() .Setup(c => c.SeasonSearch(notification, 1, 1)).Returns(true); //Act - mocker.Resolve().Start(notification, 1, 1); + Mocker.Resolve().Start(notification, 1, 1); //Assert - mocker.VerifyAllMocks(); - mocker.GetMock().Verify(c => c.SeasonSearch(notification, 1, 1), Times.Once()); - mocker.GetMock().Verify(c => c.PartialSeasonSearch(notification, 1, 1), Times.Never()); - mocker.GetMock().Verify(c => c.Start(notification, It.IsAny(), 0), Times.Never()); + Mocker.VerifyAllMocks(); + Mocker.GetMock().Verify(c => c.SeasonSearch(notification, 1, 1), Times.Once()); + Mocker.GetMock().Verify(c => c.PartialSeasonSearch(notification, 1, 1), Times.Never()); + Mocker.GetMock().Verify(c => c.Start(notification, It.IsAny(), 0), Times.Never()); } [Test] @@ -46,28 +45,26 @@ namespace NzbDrone.Core.Test.JobTests .With(e => e.SeasonNumber = 1) .Build(); - var mocker = new AutoMoqer(MockBehavior.Strict); - var notification = new ProgressNotification("Season Search"); - mocker.GetMock() + Mocker.GetMock() .Setup(c => c.SeasonSearch(notification, 1, 1)).Returns(false); - mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetEpisodesBySeason(1, 1)).Returns(episodes); - mocker.GetMock() + Mocker.GetMock() .Setup(c => c.PartialSeasonSearch(notification, 1, 1)) .Returns(episodes.Select(e => e.EpisodeNumber).ToList()); //Act - mocker.Resolve().Start(notification, 1, 1); + Mocker.Resolve().Start(notification, 1, 1); //Assert - mocker.VerifyAllMocks(); - mocker.GetMock().Verify(c => c.SeasonSearch(notification, 1, 1), Times.Once()); - mocker.GetMock().Verify(c => c.PartialSeasonSearch(notification, 1, 1), Times.Once()); - mocker.GetMock().Verify(c => c.Start(notification, It.IsAny(), 0), Times.Never()); + Mocker.VerifyAllMocks(); + Mocker.GetMock().Verify(c => c.SeasonSearch(notification, 1, 1), Times.Once()); + Mocker.GetMock().Verify(c => c.PartialSeasonSearch(notification, 1, 1), Times.Once()); + Mocker.GetMock().Verify(c => c.Start(notification, It.IsAny(), 0), Times.Never()); } [Test] @@ -78,33 +75,70 @@ namespace NzbDrone.Core.Test.JobTests .With(e => e.SeriesId = 1) .With(e => e.SeasonNumber = 1) .With(e => e.Ignored = false) + .With(e => e.AirDate = DateTime.Today.AddDays(-1)) .Build(); - var mocker = new AutoMoqer(MockBehavior.Strict); - var notification = new ProgressNotification("Season Search"); - mocker.GetMock() + Mocker.GetMock() .Setup(c => c.SeasonSearch(notification, 1, 1)).Returns(false); - mocker.GetMock() + Mocker.GetMock() .Setup(c => c.GetEpisodesBySeason(1, 1)).Returns(episodes); - mocker.GetMock() + Mocker.GetMock() .Setup(c => c.PartialSeasonSearch(notification, 1, 1)) .Returns(new List{1}); - mocker.GetMock() + Mocker.GetMock() .Setup(c => c.Start(notification, It.IsAny(), 0)).Verifiable(); //Act - mocker.Resolve().Start(notification, 1, 1); + Mocker.Resolve().Start(notification, 1, 1); //Assert - mocker.VerifyAllMocks(); - mocker.GetMock().Verify(c => c.SeasonSearch(notification, 1, 1), Times.Once()); - mocker.GetMock().Verify(c => c.PartialSeasonSearch(notification, 1, 1), Times.Once()); - mocker.GetMock().Verify(c => c.Start(notification, It.IsAny(), 0), Times.Exactly(4)); + Mocker.VerifyAllMocks(); + Mocker.GetMock().Verify(c => c.SeasonSearch(notification, 1, 1), Times.Once()); + Mocker.GetMock().Verify(c => c.PartialSeasonSearch(notification, 1, 1), Times.Once()); + Mocker.GetMock().Verify(c => c.Start(notification, It.IsAny(), 0), Times.Exactly(4)); + } + + [Test] + public void SeasonSearch_should_not_search_for_episodes_that_havent_aired_yet_or_air_tomorrow() + { + var episodes = Builder.CreateListOfSize(5) + .All() + .With(e => e.SeriesId = 1) + .With(e => e.SeasonNumber = 1) + .With(e => e.Ignored = false) + .With(e => e.AirDate = DateTime.Today.AddDays(-1)) + .TheLast(2) + .With(e => e.AirDate = DateTime.Today.AddDays(2)) + .Build(); + + var notification = new ProgressNotification("Season Search"); + + Mocker.GetMock() + .Setup(c => c.SeasonSearch(notification, 1, 1)).Returns(false); + + Mocker.GetMock() + .Setup(c => c.GetEpisodesBySeason(1, 1)).Returns(episodes); + + Mocker.GetMock() + .Setup(c => c.PartialSeasonSearch(notification, 1, 1)) + .Returns(new List()); + + Mocker.GetMock() + .Setup(c => c.Start(notification, It.IsAny(), 0)).Verifiable(); + + //Act + Mocker.Resolve().Start(notification, 1, 1); + + //Assert + Mocker.VerifyAllMocks(); + Mocker.GetMock().Verify(c => c.SeasonSearch(notification, 1, 1), Times.Once()); + Mocker.GetMock().Verify(c => c.PartialSeasonSearch(notification, 1, 1), Times.Once()); + Mocker.GetMock().Verify(c => c.Start(notification, It.IsAny(), 0), Times.Exactly(3)); } } } \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/SeasonSearchJob.cs b/NzbDrone.Core/Jobs/SeasonSearchJob.cs index 3553320fb..2074996e3 100644 --- a/NzbDrone.Core/Jobs/SeasonSearchJob.cs +++ b/NzbDrone.Core/Jobs/SeasonSearchJob.cs @@ -61,7 +61,7 @@ namespace NzbDrone.Core.Jobs var addedSeries = _searchProvider.PartialSeasonSearch(notification, targetId, secondaryTargetId); addedSeries.Distinct().ToList().Sort(); - var episodeNumbers = episodes.Select(s => s.EpisodeNumber).ToList(); + var episodeNumbers = episodes.Where(w => w.AirDate <= DateTime.Today.AddDays(1)).Select(s => s.EpisodeNumber).ToList(); episodeNumbers.Sort(); if (addedSeries.SequenceEqual(episodeNumbers))