mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 12:02:35 +02: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 @@ public void should_ignore_episodes_when_season_is_not_monitored()
|
||||
.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 @@ public void SetEpisodeMonitoredStatus(Series series, MonitoringOptions monitorin
|
||||
|
||||
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 @@ public void SetEpisodeMonitoredStatus(Series series, MonitoringOptions monitorin
|
||||
|
||||
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 @@ public void SetEpisodeMonitoredStatus(Series series, MonitoringOptions monitorin
|
||||
{
|
||||
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