Next airing will not show ignored episodes.

pull/4/head
Mark McDowall 13 years ago
parent ec6a0e6b7f
commit 7db08a10ec

@ -488,6 +488,7 @@ namespace NzbDrone.Core.Test
var fakeEpisodes = Builder<Episode>.CreateListOfSize(2) var fakeEpisodes = Builder<Episode>.CreateListOfSize(2)
.WhereAll() .WhereAll()
.Have(e => e.SeriesId = fakeSeries.SeriesId) .Have(e => e.SeriesId = fakeSeries.SeriesId)
.Have(e => e.Ignored = false)
.WhereTheFirst(1) .WhereTheFirst(1)
.Have(e => e.AirDate = DateTime.Today) .Have(e => e.AirDate = DateTime.Today)
.AndTheRemaining() .AndTheRemaining()
@ -519,6 +520,7 @@ namespace NzbDrone.Core.Test
var fakeEpisodes = Builder<Episode>.CreateListOfSize(2) var fakeEpisodes = Builder<Episode>.CreateListOfSize(2)
.WhereAll() .WhereAll()
.Have(e => e.SeriesId = fakeSeries.SeriesId) .Have(e => e.SeriesId = fakeSeries.SeriesId)
.Have(e => e.Ignored = false)
.WhereTheFirst(1) .WhereTheFirst(1)
.Have(e => e.AirDate = DateTime.Today.AddDays(-1)) .Have(e => e.AirDate = DateTime.Today.AddDays(-1))
.AndTheRemaining() .AndTheRemaining()
@ -551,6 +553,7 @@ namespace NzbDrone.Core.Test
.WhereAll() .WhereAll()
.Have(e => e.SeriesId = fakeSeries.SeriesId) .Have(e => e.SeriesId = fakeSeries.SeriesId)
.Have(e => e.AirDate = null) .Have(e => e.AirDate = null)
.Have(e => e.Ignored = false)
.Build(); .Build();
db.Insert(fakeSeries); db.Insert(fakeSeries);
@ -578,6 +581,7 @@ namespace NzbDrone.Core.Test
var fakeEpisodes = Builder<Episode>.CreateListOfSize(2) var fakeEpisodes = Builder<Episode>.CreateListOfSize(2)
.WhereAll() .WhereAll()
.Have(e => e.SeriesId = fakeSeries.SeriesId) .Have(e => e.SeriesId = fakeSeries.SeriesId)
.Have(e => e.Ignored = false)
.WhereTheFirst(1) .WhereTheFirst(1)
.Have(e => e.AirDate = DateTime.Today.AddDays(-1)) .Have(e => e.AirDate = DateTime.Today.AddDays(-1))
.AndTheRemaining() .AndTheRemaining()
@ -596,5 +600,38 @@ namespace NzbDrone.Core.Test
series.Should().HaveCount(1); series.Should().HaveCount(1);
series[0].NextAiring.Should().Be(DateTime.Today.AddMonths(1)); series[0].NextAiring.Should().Be(DateTime.Today.AddMonths(1));
} }
[Test]
public void Get_Series_NextAiring_skip_ignored()
{
var mocker = new AutoMoqer(MockBehavior.Strict);
var db = MockLib.GetEmptyDatabase();
mocker.SetConstant(db);
var fakeQuality = Builder<QualityProfile>.CreateNew().Build();
var fakeSeries = Builder<Series>.CreateNew().With(e => e.QualityProfileId = fakeQuality.QualityProfileId).Build();
var fakeEpisodes = Builder<Episode>.CreateListOfSize(2)
.WhereAll()
.Have(e => e.SeriesId = fakeSeries.SeriesId)
.WhereTheFirst(1)
.Have(e => e.AirDate = DateTime.Today.AddDays(1))
.Have(e => e.Ignored = true)
.AndTheRemaining()
.Have(e => e.AirDate = DateTime.Today.AddMonths(1))
.Have(e => e.Ignored = false)
.Build();
db.Insert(fakeSeries);
db.Insert(fakeQuality);
db.InsertMany(fakeEpisodes);
//Act
mocker.Resolve<QualityProvider>();
var series = mocker.Resolve<SeriesProvider>().GetAllSeriesWithEpisodeCount();
//Assert
series.Should().HaveCount(1);
series[0].NextAiring.Should().Be(DateTime.Today.AddMonths(1));
}
} }
} }

@ -49,7 +49,7 @@ namespace NzbDrone.Core.Providers
Series.Language, Series.Path, Series.Monitored, Series.QualityProfileId, Series.SeasonFolder, Series.Language, Series.Path, Series.Monitored, Series.QualityProfileId, Series.SeasonFolder,
SUM(CASE WHEN Ignored = 0 AND Airdate <= @0 THEN 1 ELSE 0 END) AS EpisodeCount, SUM(CASE WHEN Ignored = 0 AND Airdate <= @0 THEN 1 ELSE 0 END) AS EpisodeCount,
SUM(CASE WHEN Episodes.Ignored = 0 AND Episodes.EpisodeFileId > 0 AND Episodes.AirDate <= @0 THEN 1 ELSE 0 END) as EpisodeFileCount, SUM(CASE WHEN Episodes.Ignored = 0 AND Episodes.EpisodeFileId > 0 AND Episodes.AirDate <= @0 THEN 1 ELSE 0 END) as EpisodeFileCount,
MAX(Episodes.SeasonNumber) as SeasonCount, MIN(CASE WHEN AirDate < @0 THEN NULL ELSE AirDate END) as NextAiring, MAX(Episodes.SeasonNumber) as SeasonCount, MIN(CASE WHEN AirDate < @0 OR Ignored = 1 THEN NULL ELSE AirDate END) as NextAiring,
QualityProfiles.QualityProfileId, QualityProfiles.Name, QualityProfiles.Cutoff, QualityProfiles.SonicAllowed QualityProfiles.QualityProfileId, QualityProfiles.Name, QualityProfiles.Cutoff, QualityProfiles.SonicAllowed
FROM Series FROM Series
INNER JOIN QualityProfiles ON Series.QualityProfileId = QualityProfiles.QualityProfileId INNER JOIN QualityProfiles ON Series.QualityProfileId = QualityProfiles.QualityProfileId

Loading…
Cancel
Save