mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-10-30 15:32:31 +01:00
Cleanup/fix EpisodeMonitoredService
Fixed: Unmonitor episodes when the season is unmonitored when adding the series Fixes #1852
This commit is contained in:
parent
6bbe4ce066
commit
5aa02eb15c
@ -194,6 +194,46 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeMonitoredServiceTests
|
||||
.Verify(v => v.UpdateEpisodes(It.Is<List<Episode>>(l => l.All(e => !e.Monitored))));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_should_not_monitor_episodes_if_season_is_not_monitored()
|
||||
{
|
||||
_series = Builder<Series>.CreateNew()
|
||||
.With(s => s.Seasons = Builder<Season>.CreateListOfSize(2)
|
||||
.TheFirst(1)
|
||||
.With(n => n.Monitored = true)
|
||||
.TheLast(1)
|
||||
.With(n => n.Monitored = false)
|
||||
.Build()
|
||||
.ToList())
|
||||
.Build();
|
||||
|
||||
var episodes = Builder<Episode>.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<IEpisodeService>()
|
||||
.Setup(s => s.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.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<Episode, bool> predicate)
|
||||
{
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
|
@ -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 the season is unmonitored we should unmonitor all episodes in that season
|
||||
|
||||
if (!season.Monitored)
|
||||
{
|
||||
if (!monitoringOptions.IgnoreEpisodesWithFiles && !monitoringOptions.IgnoreEpisodesWithoutFiles)
|
||||
{
|
||||
ToggleEpisodesMonitoredState(episodes.Where(e => e.SeasonNumber == season.SeasonNumber), true);
|
||||
}
|
||||
_logger.Debug("Unmonitoring all episodes in season {0}", season.SeasonNumber);
|
||||
ToggleEpisodesMonitoredState(episodes.Where(e => e.SeasonNumber == season.SeasonNumber), false);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user