From c88ead05850da964064fcf185d3f77bda458d5be Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 3 Aug 2011 18:45:45 -0700 Subject: [PATCH] Wired in the season and episode ignore saving. Converted setSeasonIgnore & setEpisodeIgnore to use inline SQL. Added tests for setSeasonIgnore & setEpisodeIgnore. --- NzbDrone.Core.Test/EpisodeProviderTest.cs | 112 +++++++++++++++++++ NzbDrone.Core/Providers/EpisodeProvider.cs | 27 ++--- NzbDrone.Web/Content/Images/ignored.png | Bin 3537 -> 3485 bytes NzbDrone.Web/Controllers/SeriesController.cs | 15 ++- NzbDrone.Web/Scripts/seriesDetails.js | 73 ++++++++++-- NzbDrone.Web/Views/Series/Details.cshtml | 2 +- 6 files changed, 198 insertions(+), 31 deletions(-) diff --git a/NzbDrone.Core.Test/EpisodeProviderTest.cs b/NzbDrone.Core.Test/EpisodeProviderTest.cs index 03e12b013..8e3e5672f 100644 --- a/NzbDrone.Core.Test/EpisodeProviderTest.cs +++ b/NzbDrone.Core.Test/EpisodeProviderTest.cs @@ -991,5 +991,117 @@ public void AddEpisode_episode_is_not_ignored_when_not_full_season_is_not_ignore mocker.VerifyAllMocks(); } + + [Test] + public void IgnoreEpisode_Ignore() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + + var episodes = Builder.CreateListOfSize(4) + .WhereAll() + .Have(c => c.SeriesId = 10) + .Have(c => c.SeasonNumber = 1) + .Have(c => c.Ignored = false) + .Build().ToList(); + + episodes.ForEach(c => db.Insert(c)); + + //Act + mocker.Resolve().SetEpisodeIgnore(1, true); + + //Assert + var episodesInDb = db.Fetch(@"SELECT * FROM Episodes"); + + episodesInDb.Should().HaveCount(4); + episodesInDb.Where(e => e.Ignored).Should().HaveCount(1); + + mocker.VerifyAllMocks(); + } + + [Test] + public void IgnoreEpisode_RemoveIgnore() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + + var episodes = Builder.CreateListOfSize(4) + .WhereAll() + .Have(c => c.SeriesId = 10) + .Have(c => c.SeasonNumber = 1) + .Have(c => c.Ignored = true) + .Build().ToList(); + + episodes.ForEach(c => db.Insert(c)); + + //Act + mocker.Resolve().SetEpisodeIgnore(1, false); + + //Assert + var episodesInDb = db.Fetch(@"SELECT * FROM Episodes"); + + episodesInDb.Should().HaveCount(4); + episodesInDb.Where(e => !e.Ignored).Should().HaveCount(1); + + mocker.VerifyAllMocks(); + } + + [Test] + public void IgnoreSeason_Ignore() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + + var episodes = Builder.CreateListOfSize(4) + .WhereAll() + .Have(c => c.SeriesId = 10) + .Have(c => c.SeasonNumber = 1) + .Have(c => c.Ignored = false) + .Build().ToList(); + + episodes.ForEach(c => db.Insert(c)); + + //Act + mocker.Resolve().SetSeasonIgnore(10, 1, true); + + //Assert + var episodesInDb = db.Fetch(@"SELECT * FROM Episodes"); + + episodesInDb.Should().HaveCount(4); + episodesInDb.Where(e => e.Ignored).Should().HaveCount(4); + + mocker.VerifyAllMocks(); + } + + [Test] + public void IgnoreSeason_RemoveIgnore() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + + var episodes = Builder.CreateListOfSize(4) + .WhereAll() + .Have(c => c.SeriesId = 10) + .Have(c => c.SeasonNumber = 1) + .Have(c => c.Ignored = true) + .Build().ToList(); + + episodes.ForEach(c => db.Insert(c)); + + //Act + mocker.Resolve().SetSeasonIgnore(10, 1, false); + + //Assert + var episodesInDb = db.Fetch(@"SELECT * FROM Episodes"); + + episodesInDb.Should().HaveCount(4); + episodesInDb.Where(e => !e.Ignored).Should().HaveCount(4); + + mocker.VerifyAllMocks(); + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/EpisodeProvider.cs b/NzbDrone.Core/Providers/EpisodeProvider.cs index 416def223..0e8f7ea4f 100644 --- a/NzbDrone.Core/Providers/EpisodeProvider.cs +++ b/NzbDrone.Core/Providers/EpisodeProvider.cs @@ -296,26 +296,23 @@ public virtual IList GetSeasons(int seriesId) public virtual void SetSeasonIgnore(long seriesId, int seasonNumber, bool isIgnored) { Logger.Info("Setting ignore flag on Series:{0} Season:{1} to {2}", seriesId, seasonNumber, isIgnored); - var episodes = GetEpisodesBySeason(seriesId, seasonNumber); - using (var tran = _database.GetTransaction()) - { - foreach (var episode in episodes) - { - episode.Ignored = isIgnored; - _database.Update(episode); - } - - //Shouldn't run if Database is a mock since transaction will be null - if (_database.GetType().Namespace != "Castle.Proxies" && tran != null) - { - tran.Complete(); - } + _database.Execute(@"UPDATE Episodes SET Ignored = @0 + WHERE SeriesId = @1 AND SeasonNumber = @2", + isIgnored, seriesId, seasonNumber); Logger.Info("Ignore flag for Series:{0} Season:{1} successfully set to {2}", seriesId, seasonNumber, isIgnored); - } + } + public virtual void SetEpisodeIgnore(int episodeId, bool isIgnored) + { + Logger.Info("Setting ignore flag on Episode:{0} to {1}", episodeId, isIgnored); + _database.Execute(@"UPDATE Episodes SET Ignored = @0 + WHERE EpisodeId = @1", + isIgnored, episodeId); + + Logger.Info("Ignore flag for Episode:{0} successfully set to {1}", episodeId, isIgnored); } public IList AttachSeries(IList episodes) diff --git a/NzbDrone.Web/Content/Images/ignored.png b/NzbDrone.Web/Content/Images/ignored.png index 06b5934d61068f17b36cf16a9ea4032b6ff14036..41423bad28f74f9981c8f84d70433918c11b2798 100644 GIT binary patch delta 713 zcmV;)0yh288=V`lxe5XT&XcAZ?8UO+aXB3EuiPiu6_wNDF z;s%iApz?x54ARp8G6Q55E_(n12qOeUMMd?2)B>Ppa4=J$paO+l1JK+6Ab*|k`t|FJ z$dUj7gc1TGA|mlX3lD%SC*V7fngm#ogV<0pe0o4;9st>aY$ref!9zeuNC;&40wR2r z@b>N7g=k_2fq0>?urSE*1q4E40njdnckkYT%>W1>a0mzr3W6;M#uo!V4Du-!%i#bd z2U0_XISW8`g7g3c5aZ^}n}7A8S%(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