diff --git a/NzbDrone.Core.Test/EpisodeProviderTest.cs b/NzbDrone.Core.Test/EpisodeProviderTest.cs index 6b39034fc..e48aa22d7 100644 --- a/NzbDrone.Core.Test/EpisodeProviderTest.cs +++ b/NzbDrone.Core.Test/EpisodeProviderTest.cs @@ -324,6 +324,49 @@ public void RefreshEpisodeInfo_should_set_older_than_1900_to_null() mocker.VerifyAllMocks(); } + [Test] + public void RefreshEpisodeInfo_ignore_episode_zero() + { + //Arrange + const int seriesId = 71663; + const int episodeCount = 10; + + var fakeEpisodes = Builder.CreateNew().With( + c => c.Episodes = + new List(Builder.CreateListOfSize(episodeCount). + WhereAll() + .Have(l => l.Language = new TvdbLanguage(0, "eng", "a")) + .WhereTheFirst(1) + .Has(e => e.EpisodeNumber = 0) + .Has(e => e.SeasonNumber = 15) + .Build()) + ).With(c => c.Id = seriesId).Build(); + + var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); + + var mocker = new AutoMoqer(); + + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + db.Insert(fakeSeries); + + mocker.GetMock() + .Setup(c => c.GetSeries(seriesId, true)) + .Returns(fakeEpisodes); + + + //Act + mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + + //Assert + var result = mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); + mocker.GetMock().VerifyAll(); + result.Should().HaveCount(episodeCount); + mocker.VerifyAllMocks(); + result.Where(e => e.EpisodeNumber == 0 && e.SeasonNumber == 15).Single().Ignored.Should().BeTrue(); + } + [Test] public void new_episodes_only_calls_Insert() { diff --git a/NzbDrone.Core.Test/EpisodeProviderTest_GetEpisodesByParseResult.cs b/NzbDrone.Core.Test/EpisodeProviderTest_GetEpisodesByParseResult.cs index 150a931a7..70c61f288 100644 --- a/NzbDrone.Core.Test/EpisodeProviderTest_GetEpisodesByParseResult.cs +++ b/NzbDrone.Core.Test/EpisodeProviderTest_GetEpisodesByParseResult.cs @@ -188,5 +188,52 @@ public void Multi_GetSeason_Episode_Doesnt_exists_should_add() db.Fetch().Should().HaveCount(2); } + [Test] + public void Get_Episode_Zero_Doesnt_Exist_Should_add_ignored() + { + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + var fakeSeries = Builder.CreateNew().Build(); + + + var parseResult = new EpisodeParseResult + { + Series = fakeSeries, + SeasonNumber = 2, + EpisodeNumbers = new List { 0 } + }; + + var ep = mocker.Resolve().GetEpisodesByParseResult(parseResult, true); + + ep.Should().HaveCount(1); + db.Fetch().Should().HaveCount(1); + ep.First().Ignored.Should().BeTrue(); + } + + [Test] + public void Get_Multi_Episode_Zero_Doesnt_Exist_Should_not_add_ignored() + { + var mocker = new AutoMoqer(); + var db = MockLib.GetEmptyDatabase(); + mocker.SetConstant(db); + + var fakeSeries = Builder.CreateNew().Build(); + + + var parseResult = new EpisodeParseResult + { + Series = fakeSeries, + SeasonNumber = 2, + EpisodeNumbers = new List { 0, 1 } + }; + + var ep = mocker.Resolve().GetEpisodesByParseResult(parseResult, true); + + ep.Should().HaveCount(2); + db.Fetch().Should().HaveCount(2); + ep.First().Ignored.Should().BeFalse(); + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/EpisodeProvider.cs b/NzbDrone.Core/Providers/EpisodeProvider.cs index 029f658d7..eac5ef7fe 100644 --- a/NzbDrone.Core/Providers/EpisodeProvider.cs +++ b/NzbDrone.Core/Providers/EpisodeProvider.cs @@ -146,6 +146,9 @@ public virtual IList GetEpisodesByParseResult(EpisodeParseResult parseR Overview = String.Empty, }; + if (parseResult.EpisodeNumbers.Count == 1 && parseResult.EpisodeNumbers.First() == 0) + episodeInfo.Ignored = true; + AddEpisode(episodeInfo); } @@ -230,7 +233,15 @@ public virtual void RefreshEpisodeInfo(Series series) { episodeToUpdate = new Episode(); newList.Add(episodeToUpdate); + + //We need to check if this episode should be ignored based on IsIgnored rules + IsIgnored(series.SeriesId, episode.SeasonNumber); + + //If it is Episode Zero Ignore it, since it is new + if (episode.EpisodeNumber == 0) + episodeToUpdate.Ignored = true; } + else { updateList.Add(episodeToUpdate);