From 4f68d07c9a723b26467352f57c923fac0b5df347 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 3 Aug 2011 22:44:24 -0700 Subject: [PATCH] Fixed issue with missing episodes incorrectly using include specials. Added tests for missing episodes. --- NzbDrone.Core.Test/EpisodeProviderTest.cs | 115 ++++++++++++++++++ NzbDrone.Core/Providers/EpisodeProvider.cs | 13 +- NzbDrone.Web/Controllers/MissingController.cs | 5 +- 3 files changed, 125 insertions(+), 8 deletions(-) diff --git a/NzbDrone.Core.Test/EpisodeProviderTest.cs b/NzbDrone.Core.Test/EpisodeProviderTest.cs index 8e3e5672f..029f134e6 100644 --- a/NzbDrone.Core.Test/EpisodeProviderTest.cs +++ b/NzbDrone.Core.Test/EpisodeProviderTest.cs @@ -1103,5 +1103,120 @@ namespace NzbDrone.Core.Test mocker.VerifyAllMocks(); } + + [Test] + public void IgnoreSeason_Ignore_Half() + { + 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) + .WhereTheFirst(2) + .Have(c => c.Ignored = false) + .AndTheRemaining() + .Have(c => c.Ignored = true) + .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 EpisodesWithoutFiles_no_specials() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + + var series = Builder.CreateNew() + .With(s => s.SeriesId = 10) + .Build(); + + var episodes = Builder.CreateListOfSize(4) + .WhereAll() + .Have(c => c.SeriesId = 10) + .Have(c => c.SeasonNumber = 1) + .Have(c => c.AirDate = DateTime.Today.AddDays(-4)) + .WhereTheFirst(2) + .Have(c => c.EpisodeFileId = 0) + .Build().ToList(); + + var specials = Builder.CreateListOfSize(2) + .WhereAll() + .Have(c => c.SeriesId = 10) + .Have(c => c.SeasonNumber = 0) + .Have(c => c.AirDate = DateTime.Today.AddDays(-4)) + .Have(c => c.EpisodeFileId = 0) + .Build().ToList(); + + db.Insert(series); + db.InsertMany(episodes); + db.InsertMany(specials); + + //Act + var missingFiles= mocker.Resolve().EpisodesWithoutFiles(false); + + //Assert + missingFiles.Should().HaveCount(2); + missingFiles.Where(e => e.EpisodeFileId == 0).Should().HaveCount(2); + + mocker.VerifyAllMocks(); + } + + [Test] + public void EpisodesWithoutFiles_with_specials() + { + var db = MockLib.GetEmptyDatabase(); + var mocker = new AutoMoqer(); + mocker.SetConstant(db); + + var series = Builder.CreateNew() + .With(s => s.SeriesId = 10) + .Build(); + + var episodes = Builder.CreateListOfSize(4) + .WhereAll() + .Have(c => c.SeriesId = 10) + .Have(c => c.SeasonNumber = 1) + .Have(c => c.AirDate = DateTime.Today.AddDays(-4)) + .WhereTheFirst(2) + .Have(c => c.EpisodeFileId = 0) + .Build().ToList(); + + var specials = Builder.CreateListOfSize(2) + .WhereAll() + .Have(c => c.SeriesId = 10) + .Have(c => c.SeasonNumber = 0) + .Have(c => c.AirDate = DateTime.Today.AddDays(-4)) + .Have(c => c.EpisodeFileId = 0) + .Build().ToList(); + + db.Insert(series); + db.InsertMany(episodes); + db.InsertMany(specials); + + //Act + var missingFiles = mocker.Resolve().EpisodesWithoutFiles(true); + + //Assert + missingFiles.Should().HaveCount(4); + missingFiles.Where(e => e.EpisodeFileId == 0).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 0e8f7ea4f..40c0475c2 100644 --- a/NzbDrone.Core/Providers/EpisodeProvider.cs +++ b/NzbDrone.Core/Providers/EpisodeProvider.cs @@ -159,12 +159,15 @@ namespace NzbDrone.Core.Providers public virtual IList EpisodesWithoutFiles(bool includeSpecials) { - var episodes = _database.Query("WHERE (EpisodeFileId=0 OR EpisodeFileId=NULL) AND AirDate<=@0", + var episodes = _database.Query(@"SELECT Episodes.*, Series.Title FROM Episodes + INNER JOIN Series + ON Episodes.SeriesId = Series.SeriesId + WHERE (EpisodeFileId=0 OR EpisodeFileId=NULL) AND AirDate<=@0", DateTime.Now.Date); - if (includeSpecials) + if (!includeSpecials) return episodes.Where(e => e.SeasonNumber > 0).ToList(); - return AttachSeries(episodes.ToList()); + return episodes.ToList(); } public virtual IList GetEpisodesByFileId(int episodeFileId) @@ -298,8 +301,8 @@ namespace NzbDrone.Core.Providers Logger.Info("Setting ignore flag on Series:{0} Season:{1} to {2}", seriesId, seasonNumber, isIgnored); _database.Execute(@"UPDATE Episodes SET Ignored = @0 - WHERE SeriesId = @1 AND SeasonNumber = @2", - isIgnored, seriesId, seasonNumber); + WHERE SeriesId = @1 AND SeasonNumber = @2 AND Ignored = @3", + isIgnored, seriesId, seasonNumber, !isIgnored); Logger.Info("Ignore flag for Series:{0} Season:{1} successfully set to {2}", seriesId, seasonNumber, isIgnored); } diff --git a/NzbDrone.Web/Controllers/MissingController.cs b/NzbDrone.Web/Controllers/MissingController.cs index 6b94dce08..581c3f541 100644 --- a/NzbDrone.Web/Controllers/MissingController.cs +++ b/NzbDrone.Web/Controllers/MissingController.cs @@ -26,10 +26,9 @@ namespace NzbDrone.Web.Controllers [GridAction] public ActionResult _AjaxBinding() { - //TODO: possible subsonic bug, IQuarible causes some issues so ToList() is called - //https://github.com/subsonic/SubSonic-3.0/issues/263 + var missingEpisodes = _episodeProvider.EpisodesWithoutFiles(false); - var missing = _episodeProvider.EpisodesWithoutFiles(true).Select(e => new MissingEpisodeModel + var missing = missingEpisodes.Select(e => new MissingEpisodeModel { EpisodeId = e.EpisodeId, SeasonNumber = e.SeasonNumber,