From 078b53dc13ea4739eaa31920740e43708c6b3010 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sat, 19 Aug 2017 00:26:42 -0700 Subject: [PATCH] Opt out of updating episodes matching season monitored state when updating series Fixed: Season pass resetting changes when a season changed it's monitored state Closes #2139 --- .../SceneNumbering/XemServiceFixture.cs | 10 +++++----- .../SetEpisodeMontitoredFixture.cs | 6 +++--- .../TvTests/MoveSeriesServiceFixture.cs | 6 +++--- .../TvTests/RefreshSeriesServiceFixture.cs | 16 ++++++++-------- src/NzbDrone.Core/Tv/EpisodeMonitoredService.cs | 2 +- src/NzbDrone.Core/Tv/SeriesService.cs | 8 +++++--- 6 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/NzbDrone.Core.Test/DataAugmentation/SceneNumbering/XemServiceFixture.cs b/src/NzbDrone.Core.Test/DataAugmentation/SceneNumbering/XemServiceFixture.cs index 5ad5e40e8..99f522a79 100644 --- a/src/NzbDrone.Core.Test/DataAugmentation/SceneNumbering/XemServiceFixture.cs +++ b/src/NzbDrone.Core.Test/DataAugmentation/SceneNumbering/XemServiceFixture.cs @@ -108,7 +108,7 @@ public void should_not_fetch_scenenumbering_if_not_listed() .Verify(v => v.GetSceneTvdbMappings(10), Times.Never()); Mocker.GetMock() - .Verify(v => v.UpdateSeries(It.IsAny()), Times.Never()); + .Verify(v => v.UpdateSeries(It.IsAny(), It.IsAny()), Times.Never()); } [Test] @@ -119,7 +119,7 @@ public void should_fetch_scenenumbering() Subject.Handle(new SeriesUpdatedEvent(_series)); Mocker.GetMock() - .Verify(v => v.UpdateSeries(It.Is(s => s.UseSceneNumbering == true)), Times.Once()); + .Verify(v => v.UpdateSeries(It.Is(s => s.UseSceneNumbering == true), It.IsAny()), Times.Once()); } [Test] @@ -130,7 +130,7 @@ public void should_clear_scenenumbering_if_removed_from_thexem() Subject.Handle(new SeriesUpdatedEvent(_series)); Mocker.GetMock() - .Verify(v => v.UpdateSeries(It.IsAny()), Times.Once()); + .Verify(v => v.UpdateSeries(It.IsAny(), It.IsAny()), Times.Once()); } [Test] @@ -143,7 +143,7 @@ public void should_not_clear_scenenumbering_if_no_results_at_all_from_thexem() Subject.Handle(new SeriesUpdatedEvent(_series)); Mocker.GetMock() - .Verify(v => v.UpdateSeries(It.IsAny()), Times.Never()); + .Verify(v => v.UpdateSeries(It.IsAny(), It.IsAny()), Times.Never()); ExceptionVerification.ExpectedWarns(1); } @@ -160,7 +160,7 @@ public void should_not_clear_scenenumbering_if_thexem_throws() Subject.Handle(new SeriesUpdatedEvent(_series)); Mocker.GetMock() - .Verify(v => v.UpdateSeries(It.IsAny()), Times.Never()); + .Verify(v => v.UpdateSeries(It.IsAny(), It.IsAny()), Times.Never()); ExceptionVerification.ExpectedWarns(1); } diff --git a/src/NzbDrone.Core.Test/TvTests/EpisodeMonitoredServiceTests/SetEpisodeMontitoredFixture.cs b/src/NzbDrone.Core.Test/TvTests/EpisodeMonitoredServiceTests/SetEpisodeMontitoredFixture.cs index 0cf020314..70108d1be 100644 --- a/src/NzbDrone.Core.Test/TvTests/EpisodeMonitoredServiceTests/SetEpisodeMontitoredFixture.cs +++ b/src/NzbDrone.Core.Test/TvTests/EpisodeMonitoredServiceTests/SetEpisodeMontitoredFixture.cs @@ -71,7 +71,7 @@ public void should_be_able_to_monitor_series_without_changing_episodes() Subject.SetEpisodeMonitoredStatus(_series, null); Mocker.GetMock() - .Verify(v => v.UpdateSeries(It.IsAny()), Times.Once()); + .Verify(v => v.UpdateSeries(It.IsAny(), It.IsAny()), Times.Once()); Mocker.GetMock() .Verify(v => v.UpdateEpisodes(It.IsAny>()), Times.Never()); @@ -249,13 +249,13 @@ private void VerifyNotMonitored(Func predicate) private void VerifySeasonMonitored(Func predicate) { Mocker.GetMock() - .Verify(v => v.UpdateSeries(It.Is(s => s.Seasons.Where(predicate).All(n => n.Monitored)))); + .Verify(v => v.UpdateSeries(It.Is(s => s.Seasons.Where(predicate).All(n => n.Monitored)), It.IsAny())); } private void VerifySeasonNotMonitored(Func predicate) { Mocker.GetMock() - .Verify(v => v.UpdateSeries(It.Is(s => s.Seasons.Where(predicate).All(n => !n.Monitored)))); + .Verify(v => v.UpdateSeries(It.Is(s => s.Seasons.Where(predicate).All(n => !n.Monitored)), It.IsAny())); } } } diff --git a/src/NzbDrone.Core.Test/TvTests/MoveSeriesServiceFixture.cs b/src/NzbDrone.Core.Test/TvTests/MoveSeriesServiceFixture.cs index 528816c99..fcf92117d 100644 --- a/src/NzbDrone.Core.Test/TvTests/MoveSeriesServiceFixture.cs +++ b/src/NzbDrone.Core.Test/TvTests/MoveSeriesServiceFixture.cs @@ -63,7 +63,7 @@ public void should_no_update_series_path_on_error() ExceptionVerification.ExpectedErrors(1); Mocker.GetMock() - .Verify(v => v.UpdateSeries(It.IsAny()), Times.Never()); + .Verify(v => v.UpdateSeries(It.IsAny(), It.IsAny()), Times.Never()); } [Test] @@ -81,7 +81,7 @@ public void should_build_new_path_when_root_folder_is_provided() Subject.Execute(_command); Mocker.GetMock() - .Verify(v => v.UpdateSeries(It.Is(s => s.Path == expectedPath)), Times.Once()); + .Verify(v => v.UpdateSeries(It.Is(s => s.Path == expectedPath), It.IsAny()), Times.Once()); } [Test] @@ -90,7 +90,7 @@ public void should_use_destination_path_if_destination_root_folder_is_blank() Subject.Execute(_command); Mocker.GetMock() - .Verify(v => v.UpdateSeries(It.Is(s => s.Path == _command.DestinationPath)), Times.Once()); + .Verify(v => v.UpdateSeries(It.Is(s => s.Path == _command.DestinationPath), It.IsAny()), Times.Once()); Mocker.GetMock() .Verify(v => v.GetSeriesFolder(It.IsAny(), null), Times.Never()); diff --git a/src/NzbDrone.Core.Test/TvTests/RefreshSeriesServiceFixture.cs b/src/NzbDrone.Core.Test/TvTests/RefreshSeriesServiceFixture.cs index f441496cd..1012149c1 100644 --- a/src/NzbDrone.Core.Test/TvTests/RefreshSeriesServiceFixture.cs +++ b/src/NzbDrone.Core.Test/TvTests/RefreshSeriesServiceFixture.cs @@ -62,7 +62,7 @@ public void should_monitor_new_seasons_automatically() Subject.Execute(new RefreshSeriesCommand(_series.Id)); Mocker.GetMock() - .Verify(v => v.UpdateSeries(It.Is(s => s.Seasons.Count == 2 && s.Seasons.Single(season => season.SeasonNumber == 2).Monitored == true))); + .Verify(v => v.UpdateSeries(It.Is(s => s.Seasons.Count == 2 && s.Seasons.Single(season => season.SeasonNumber == 2).Monitored == true), It.IsAny())); } [Test] @@ -78,7 +78,7 @@ public void should_not_monitor_new_special_season_automatically() Subject.Execute(new RefreshSeriesCommand(_series.Id)); Mocker.GetMock() - .Verify(v => v.UpdateSeries(It.Is(s => s.Seasons.Count == 2 && s.Seasons.Single(season => season.SeasonNumber == 0).Monitored == false))); + .Verify(v => v.UpdateSeries(It.Is(s => s.Seasons.Count == 2 && s.Seasons.Single(season => season.SeasonNumber == 0).Monitored == false), It.IsAny())); } [Test] @@ -92,7 +92,7 @@ public void should_update_tvrage_id_if_changed() Subject.Execute(new RefreshSeriesCommand(_series.Id)); Mocker.GetMock() - .Verify(v => v.UpdateSeries(It.Is(s => s.TvRageId == newSeriesInfo.TvRageId))); + .Verify(v => v.UpdateSeries(It.Is(s => s.TvRageId == newSeriesInfo.TvRageId), It.IsAny())); } [Test] @@ -106,7 +106,7 @@ public void should_update_tvmaze_id_if_changed() Subject.Execute(new RefreshSeriesCommand(_series.Id)); Mocker.GetMock() - .Verify(v => v.UpdateSeries(It.Is(s => s.TvMazeId == newSeriesInfo.TvMazeId))); + .Verify(v => v.UpdateSeries(It.Is(s => s.TvMazeId == newSeriesInfo.TvMazeId), It.IsAny())); } [Test] @@ -115,7 +115,7 @@ public void should_log_error_if_tvdb_id_not_found() Subject.Execute(new RefreshSeriesCommand(_series.Id)); Mocker.GetMock() - .Verify(v => v.UpdateSeries(It.IsAny()), Times.Never()); + .Verify(v => v.UpdateSeries(It.IsAny(), It.IsAny()), Times.Never()); ExceptionVerification.ExpectedErrors(1); } @@ -131,7 +131,7 @@ public void should_update_if_tvdb_id_changed() Subject.Execute(new RefreshSeriesCommand(_series.Id)); Mocker.GetMock() - .Verify(v => v.UpdateSeries(It.Is(s => s.TvdbId == newSeriesInfo.TvdbId))); + .Verify(v => v.UpdateSeries(It.Is(s => s.TvdbId == newSeriesInfo.TvdbId), It.IsAny())); ExceptionVerification.ExpectedWarns(1); } @@ -157,7 +157,7 @@ public void should_not_throw_if_duplicate_season_is_in_existing_info() Subject.Execute(new RefreshSeriesCommand(_series.Id)); Mocker.GetMock() - .Verify(v => v.UpdateSeries(It.Is(s => s.Seasons.Count == 2))); + .Verify(v => v.UpdateSeries(It.Is(s => s.Seasons.Count == 2), It.IsAny())); } [Test] @@ -177,7 +177,7 @@ public void should_filter_duplicate_seasons() Subject.Execute(new RefreshSeriesCommand(_series.Id)); Mocker.GetMock() - .Verify(v => v.UpdateSeries(It.Is(s => s.Seasons.Count == 2))); + .Verify(v => v.UpdateSeries(It.Is(s => s.Seasons.Count == 2), It.IsAny())); } } diff --git a/src/NzbDrone.Core/Tv/EpisodeMonitoredService.cs b/src/NzbDrone.Core/Tv/EpisodeMonitoredService.cs index f186ade10..c680116c6 100644 --- a/src/NzbDrone.Core/Tv/EpisodeMonitoredService.cs +++ b/src/NzbDrone.Core/Tv/EpisodeMonitoredService.cs @@ -83,7 +83,7 @@ public void SetEpisodeMonitoredStatus(Series series, MonitoringOptions monitorin _episodeService.UpdateEpisodes(episodes); } - _seriesService.UpdateSeries(series); + _seriesService.UpdateSeries(series, false); } private void ToggleEpisodesMonitoredState(IEnumerable episodes, bool monitored) diff --git a/src/NzbDrone.Core/Tv/SeriesService.cs b/src/NzbDrone.Core/Tv/SeriesService.cs index 171517ab3..124bf169d 100644 --- a/src/NzbDrone.Core/Tv/SeriesService.cs +++ b/src/NzbDrone.Core/Tv/SeriesService.cs @@ -25,7 +25,7 @@ public interface ISeriesService Series FindByTitleInexact(string title); void DeleteSeries(int seriesId, bool deleteFiles); List GetAllSeries(); - Series UpdateSeries(Series series); + Series UpdateSeries(Series series, bool updateEpisodesToMatchSeason = true); List UpdateSeries(List series); bool SeriesPathExists(string folder); void RemoveAddOptions(Series series); @@ -144,7 +144,9 @@ public List GetAllSeries() return _seriesRepository.All().ToList(); } - public Series UpdateSeries(Series series) + // updateEpisodesToMatchSeason is an override for EpisodeMonitoredService to use so a change via Season pass doesn't get nuked by the seasons loop. + // TODO: Remove when seasons are split from series (or we come up with a better way to address this) + public Series UpdateSeries(Series series, bool updateEpisodesToMatchSeason = true) { var storedSeries = GetSeries(series.Id); @@ -152,7 +154,7 @@ public Series UpdateSeries(Series series) { var storedSeason = storedSeries.Seasons.SingleOrDefault(s => s.SeasonNumber == season.SeasonNumber); - if (storedSeason != null && season.Monitored != storedSeason.Monitored) + if (storedSeason != null &&season.Monitored != storedSeason.Monitored && updateEpisodesToMatchSeason) { _episodeService.SetEpisodeMonitoredBySeason(series.Id, season.SeasonNumber, season.Monitored); }