diff --git a/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest.cs index 036fb8a52..0b75cb2a0 100644 --- a/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest.cs @@ -326,6 +326,51 @@ public void RefreshEpisodeInfo_should_set_older_than_1900_to_null() mocker.VerifyAllMocks(); } + [Test] + public void RefreshEpisodeInfo_should_set_older_than_1900_to_null_for_existing_episodes() + { + //Arrange + const int seriesId = 71663; + + var fakeEpisode = Builder.CreateNew() + .With(e => e.TvDbEpisodeId = 12345) + .With(e => e.AirDate = DateTime.Today) + .Build(); + + var fakeTvDbEpisodes = Builder.CreateNew().With( + c => c.Episodes = + new List(Builder.CreateListOfSize(1) + .All() + .With(l => l.Language = new TvdbLanguage(0, "eng", "a")).And(e => e.FirstAired = DateTime.Now) + .TheFirst(1).With(e => e.FirstAired = new DateTime(1800, 1, 1)) + .Build()) + ).With(c => c.Id = seriesId).Build(); + + var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); + + var mocker = new AutoMoqer(); + + var db = TestDbHelper.GetEmptyDatabase(); + mocker.SetConstant(db); + + db.Insert(fakeSeries); + db.Insert(fakeEpisode); + + mocker.GetMock() + .Setup(c => c.GetSeries(seriesId, true)) + .Returns(fakeTvDbEpisodes); + + //Act + mocker.Resolve().RefreshEpisodeInfo(fakeSeries); + + //Assert + var storedEpisodes = mocker.Resolve().GetEpisodeBySeries(seriesId).ToList(); + storedEpisodes.Should().HaveCount(1); + storedEpisodes.Where(e => e.AirDate == null).Should().HaveCount(1); + + mocker.VerifyAllMocks(); + } + [Test] public void RefreshEpisodeInfo_ignore_episode_zero() { diff --git a/NzbDrone.Core/Providers/EpisodeProvider.cs b/NzbDrone.Core/Providers/EpisodeProvider.cs index 508abcf1c..a740800d5 100644 --- a/NzbDrone.Core/Providers/EpisodeProvider.cs +++ b/NzbDrone.Core/Providers/EpisodeProvider.cs @@ -258,9 +258,10 @@ public virtual void RefreshEpisodeInfo(Series series) episodeToUpdate.Overview = episode.Overview; if (episode.FirstAired.Year > 1900) - { episodeToUpdate.AirDate = episode.FirstAired.Date; - } + + else + episodeToUpdate.AirDate = null; successCount++; }