Fixed issue with missing episodes incorrectly using include specials.

Added tests for missing episodes.
This commit is contained in:
Mark McDowall 2011-08-03 22:44:24 -07:00
parent 45b4bb4629
commit 4f68d07c9a
3 changed files with 125 additions and 8 deletions

View File

@ -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<Episode>.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<EpisodeProvider>().SetSeasonIgnore(10, 1, true);
//Assert
var episodesInDb = db.Fetch<Episode>(@"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<Series>.CreateNew()
.With(s => s.SeriesId = 10)
.Build();
var episodes = Builder<Episode>.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<Episode>.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<EpisodeProvider>().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<Series>.CreateNew()
.With(s => s.SeriesId = 10)
.Build();
var episodes = Builder<Episode>.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<Episode>.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<EpisodeProvider>().EpisodesWithoutFiles(true);
//Assert
missingFiles.Should().HaveCount(4);
missingFiles.Where(e => e.EpisodeFileId == 0).Should().HaveCount(4);
mocker.VerifyAllMocks();
}
}
}

View File

@ -159,12 +159,15 @@ namespace NzbDrone.Core.Providers
public virtual IList<Episode> EpisodesWithoutFiles(bool includeSpecials)
{
var episodes = _database.Query<Episode>("WHERE (EpisodeFileId=0 OR EpisodeFileId=NULL) AND AirDate<=@0",
var episodes = _database.Query<Episode, Series>(@"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<Episode> 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);
}

View File

@ -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,