diff --git a/src/NzbDrone.Core.Test/TvTests/EpisodeMonitoredServiceTests/SetEpisodeMontitoredFixture.cs b/src/NzbDrone.Core.Test/TvTests/EpisodeMonitoredServiceTests/SetEpisodeMontitoredFixture.cs index 058a09b86..0cf020314 100644 --- a/src/NzbDrone.Core.Test/TvTests/EpisodeMonitoredServiceTests/SetEpisodeMontitoredFixture.cs +++ b/src/NzbDrone.Core.Test/TvTests/EpisodeMonitoredServiceTests/SetEpisodeMontitoredFixture.cs @@ -194,6 +194,46 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeMonitoredServiceTests .Verify(v => v.UpdateEpisodes(It.Is>(l => l.All(e => !e.Monitored)))); } + [Test] + public void should_should_not_monitor_episodes_if_season_is_not_monitored() + { + _series = Builder.CreateNew() + .With(s => s.Seasons = Builder.CreateListOfSize(2) + .TheFirst(1) + .With(n => n.Monitored = true) + .TheLast(1) + .With(n => n.Monitored = false) + .Build() + .ToList()) + .Build(); + + var episodes = Builder.CreateListOfSize(10) + .All() + .With(e => e.Monitored = true) + .With(e => e.EpisodeFileId = 0) + .With(e => e.AirDateUtc = DateTime.UtcNow.AddDays(-7)) + .TheFirst(5) + .With(e => e.SeasonNumber = 1) + .TheLast(5) + .With(e => e.SeasonNumber = 2) + .BuildList(); + + Mocker.GetMock() + .Setup(s => s.GetEpisodeBySeries(It.IsAny())) + .Returns(episodes); + + Subject.SetEpisodeMonitoredStatus(_series, new MonitoringOptions + { + IgnoreEpisodesWithFiles = true, + IgnoreEpisodesWithoutFiles = false + }); + + VerifyMonitored(e => e.SeasonNumber == 1); + VerifyNotMonitored(e => e.SeasonNumber == 2); + VerifySeasonMonitored(s => s.SeasonNumber == 1); + VerifySeasonNotMonitored(s => s.SeasonNumber == 2); + } + private void VerifyMonitored(Func predicate) { Mocker.GetMock() diff --git a/src/NzbDrone.Core/Tv/EpisodeMonitoredService.cs b/src/NzbDrone.Core/Tv/EpisodeMonitoredService.cs index b15c130be..f186ade10 100644 --- a/src/NzbDrone.Core/Tv/EpisodeMonitoredService.cs +++ b/src/NzbDrone.Core/Tv/EpisodeMonitoredService.cs @@ -34,10 +34,9 @@ namespace NzbDrone.Core.Tv if (monitoringOptions.IgnoreEpisodesWithFiles) { - _logger.Debug("Ignoring Episodes with Files"); + _logger.Debug("Unmonitoring Episodes with Files"); ToggleEpisodesMonitoredState(episodes.Where(e => e.HasFile), false); } - else { _logger.Debug("Monitoring Episodes with Files"); @@ -46,10 +45,9 @@ namespace NzbDrone.Core.Tv if (monitoringOptions.IgnoreEpisodesWithoutFiles) { - _logger.Debug("Ignoring Episodes without Files"); + _logger.Debug("Unmonitoring Episodes without Files"); ToggleEpisodesMonitoredState(episodes.Where(e => !e.HasFile && e.AirDateUtc.HasValue && e.AirDateUtc.Value.Before(DateTime.UtcNow)), false); } - else { _logger.Debug("Monitoring Episodes without Files"); @@ -62,31 +60,21 @@ namespace NzbDrone.Core.Tv { var season = s; - if (season.Monitored) - { - if (!monitoringOptions.IgnoreEpisodesWithFiles && !monitoringOptions.IgnoreEpisodesWithoutFiles) - { - ToggleEpisodesMonitoredState(episodes.Where(e => e.SeasonNumber == season.SeasonNumber), true); - } - } + // If the season is unmonitored we should unmonitor all episodes in that season - else + if (!season.Monitored) { - if (!monitoringOptions.IgnoreEpisodesWithFiles && !monitoringOptions.IgnoreEpisodesWithoutFiles) - { - ToggleEpisodesMonitoredState(episodes.Where(e => e.SeasonNumber == season.SeasonNumber), false); - } - - else if (season.SeasonNumber == 0) - { - ToggleEpisodesMonitoredState(episodes.Where(e => e.SeasonNumber == season.SeasonNumber), false); - } + _logger.Debug("Unmonitoring all episodes in season {0}", season.SeasonNumber); + ToggleEpisodesMonitoredState(episodes.Where(e => e.SeasonNumber == season.SeasonNumber), false); } + // If the season is not the latest season and all it's episodes are unmonitored the season will be unmonitored + if (season.SeasonNumber < lastSeason) { if (episodes.Where(e => e.SeasonNumber == season.SeasonNumber).All(e => !e.Monitored)) { + _logger.Debug("Unmonitoring season {0} because all episodes are not monitored", season.SeasonNumber); season.Monitored = false; } }