Fixed: Monitoring latest season ignoring unaired episodes

Fixes #3200
This commit is contained in:
Mark McDowall 2019-07-11 17:45:04 -07:00
parent 81ac359f71
commit c21cacd309
2 changed files with 38 additions and 1 deletions

View File

@ -223,6 +223,41 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeMonitoredServiceTests
.Verify(v => v.UpdateEpisodes(It.Is<List<Episode>>(l => l.All(e => !e.Monitored)))); .Verify(v => v.UpdateEpisodes(It.Is<List<Episode>>(l => l.All(e => !e.Monitored))));
} }
[Test]
public void should_monitor_latest_season_if_some_episodes_have_aired()
{
_series.Seasons = Builder<Season>.CreateListOfSize(2)
.All()
.With(n => n.Monitored = true)
.Build()
.ToList();
_episodes = Builder<Episode>.CreateListOfSize(5)
.All()
.With(e => e.SeasonNumber = 1)
.With(e => e.EpisodeFileId = 0)
.With(e => e.AirDateUtc = DateTime.UtcNow.AddDays(-100))
.TheLast(2)
.With(e => e.SeasonNumber = 2)
.TheLast(1)
.With(e => e.AirDateUtc = DateTime.UtcNow.AddDays(100))
.Build()
.ToList();
var monitoringOptions = new MonitoringOptions
{
Monitor = MonitorTypes.LatestSeason
};
Subject.SetEpisodeMonitoredStatus(_series, monitoringOptions);
VerifySeasonMonitored(n => n.SeasonNumber == 2);
VerifyMonitored(n => n.SeasonNumber == 2);
VerifySeasonNotMonitored(n => n.SeasonNumber == 1);
VerifyNotMonitored(n => n.SeasonNumber == 1);
}
private void VerifyMonitored(Func<Episode, bool> predicate) private void VerifyMonitored(Func<Episode, bool> predicate)
{ {
Mocker.GetMock<IEpisodeService>() Mocker.GetMock<IEpisodeService>()

View File

@ -79,7 +79,9 @@ namespace NzbDrone.Core.Tv
case MonitorTypes.LatestSeason: case MonitorTypes.LatestSeason:
if (episodes.Where(e => e.SeasonNumber == lastSeason) if (episodes.Where(e => e.SeasonNumber == lastSeason)
.All(e => e.AirDateUtc.HasValue && !e.AirDateUtc.Value.InLastDays(90))) .All(e => e.AirDateUtc.HasValue &&
e.AirDateUtc.Value.Before(DateTime.UtcNow) &&
!e.AirDateUtc.Value.InLastDays(90)))
{ {
_logger.Debug("[{0}] Unmonitoring all episodes because latest season aired more than 90 days ago", series.Title); _logger.Debug("[{0}] Unmonitoring all episodes because latest season aired more than 90 days ago", series.Title);
ToggleEpisodesMonitoredState(episodes, e => false); ToggleEpisodesMonitoredState(episodes, e => false);