Improved: Upcoming episodes page no longer shows series that aren't monitored.

pull/6/head
kay.one 13 years ago
parent 6df184b7cb
commit 659b3dee55

@ -1,21 +1,18 @@
// ReSharper disable RedundantUsingDirective
// ReSharper disable InconsistentNaming
using System;
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.Core.Test.ProviderTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class UpcomingEpisodesProviderTest : CoreTest
{
private IList<Episode> episodes;
@ -24,6 +21,8 @@ namespace NzbDrone.Core.Test.ProviderTests
[SetUp]
public void Setup()
{
WithRealDb();
episodes = Builder<Episode>.CreateListOfSize(6)
.All()
.With(e => e.SeriesId = 1)
@ -42,174 +41,120 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(e => e.AirDate = DateTime.Today.AddDays(9))
.Build();
series = Builder<Series>.CreateNew().With(s => s.SeriesId = 1).Build();
series = Builder<Series>.CreateNew()
.With(s => s.SeriesId = 1)
.And(c => c.Monitored = true)
.Build();
Db.InsertMany(episodes);
Db.Insert(series);
}
[Test]
public void Get_Yesterday()
private void WithIgnoredEpisodes()
{
//Setup
var database = TestDbHelper.GetEmptyDatabase();
Mocker.SetConstant(database);
episodes.ToList().ForEach(c => c.Ignored = true);
Db.UpdateMany(episodes);
}
database.InsertMany(episodes);
database.Insert(series);
private void WithIgnoredSeries()
{
series.Monitored = false;
Db.Update(series);
}
//Act
[Test]
public void Get_Yesterday()
{
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Yesterday();
//Assert
result.Should().HaveCount(1);
result.First().Title.Should().Be(episodes.Where(e => e.AirDate == DateTime.Today.AddDays(-1)).First().Title);
result.Should().NotBeEmpty();
result.Should().OnlyContain(c => c.AirDate.Value.Date == DateTime.Today.AddDays(-1).Date);
result.First().Series.Should().NotBeNull();
result.First().Series.SeriesId.Should().NotBe(0);
result.First().Series.SeriesId.Should().Be(series.SeriesId);
}
[Test]
public void Get_Today()
{
//Setup
var database = TestDbHelper.GetEmptyDatabase();
Mocker.SetConstant(database);
database.InsertMany(episodes);
database.Insert(series);
//Act
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Today();
//Assert
result.Should().HaveCount(1);
result.First().Title.Should().Be(episodes.Where(e => e.AirDate == DateTime.Today).First().Title);
result.Should().NotBeEmpty();
result.Should().OnlyContain(c => c.AirDate.Value.Date == DateTime.Today.Date);
result.First().Series.Should().NotBeNull();
result.First().Series.SeriesId.Should().NotBe(0);
result.First().Series.SeriesId.Should().Be(series.SeriesId);
}
[Test]
public void Get_Tomorrow()
{
//Setup
var database = TestDbHelper.GetEmptyDatabase();
Mocker.SetConstant(database);
database.InsertMany(episodes);
database.Insert(series);
//Act
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Tomorrow();
//Assert
result.Should().HaveCount(1);
result.First().Title.Should().Be(episodes.Where(e => e.AirDate == DateTime.Today.AddDays(1)).First().Title);
result.Should().NotBeEmpty();
result.Should().OnlyContain(c => c.AirDate.Value.Date == DateTime.Today.AddDays(1).Date);
result.First().Series.Should().NotBeNull();
result.First().Series.SeriesId.Should().NotBe(0);
result.First().Series.SeriesId.Should().Be(series.SeriesId);
}
[Test]
public void Get_Week()
{
//Setup
var database = TestDbHelper.GetEmptyDatabase();
Mocker.SetConstant(database);
database.InsertMany(episodes);
database.Insert(series);
//Act
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Week();
//Assert
result.Should().HaveCount(2);
result.First().Series.Should().NotBeNull();
result.First().Series.SeriesId.Should().NotBe(0);
result.Last().Series.Should().NotBeNull();
result.Last().Series.SeriesId.Should().NotBe(0);
result.Should().OnlyContain(c => c.Series != null && c.SeriesId == series.SeriesId);
}
[Test]
public void Get_Yesterday_skip_ingored()
public void Get_Yesterday_should_skip_ingored()
{
//Setup
var database = TestDbHelper.GetEmptyDatabase();
Mocker.SetConstant(database);
episodes.Where(e => e.AirDate == DateTime.Today.AddDays(-1)).Single().Ignored = true;
database.InsertMany(episodes);
database.Insert(series);
//Act
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Yesterday();
//Assert
result.Should().BeEmpty();
WithIgnoredEpisodes();
Mocker.Resolve<UpcomingEpisodesProvider>().Yesterday().Should().BeEmpty();
}
[Test]
public void Get_Today_skip_ingored()
public void Get_Today_should_skip_ingored()
{
//Setup
var database = TestDbHelper.GetEmptyDatabase();
Mocker.SetConstant(database);
episodes.Where(e => e.AirDate == DateTime.Today).Single().Ignored = true;
database.InsertMany(episodes);
database.Insert(series);
//Act
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Today();
//Assert
result.Should().BeEmpty();
WithIgnoredEpisodes();
Mocker.Resolve<UpcomingEpisodesProvider>().Today().Should().BeEmpty();
}
[Test]
public void Get_Tomorrow_skip_ingored()
public void Get_Tomorrow_should_skip_ingored()
{
//Setup
var database = TestDbHelper.GetEmptyDatabase();
Mocker.SetConstant(database);
episodes.Where(e => e.AirDate == DateTime.Today.AddDays(1)).Single().Ignored = true;
database.InsertMany(episodes);
database.Insert(series);
//Act
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Tomorrow();
//Assert
result.Should().BeEmpty();
WithIgnoredEpisodes();
Mocker.Resolve<UpcomingEpisodesProvider>().Tomorrow().Should().BeEmpty();
}
[Test]
public void Get_Week_skip_ingored()
public void Get_Week_should_skip_ingored()
{
//Setup
var database = TestDbHelper.GetEmptyDatabase();
Mocker.SetConstant(database);
episodes.Where(e => e.AirDate == DateTime.Today.AddDays(2)).Single().Ignored = true;
WithIgnoredEpisodes();
Mocker.Resolve<UpcomingEpisodesProvider>().Week().Should().BeEmpty();
}
database.InsertMany(episodes);
database.Insert(series);
[Test]
public void Get_Today_should_skip_unmonitored_series()
{
WithIgnoredSeries();
Mocker.Resolve<UpcomingEpisodesProvider>().Today().Should().BeEmpty();
}
//Act
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Week();
[Test]
public void Get_Tomoroww_should_skip_unmonitored_series()
{
WithIgnoredSeries();
Mocker.Resolve<UpcomingEpisodesProvider>().Tomorrow().Should().BeEmpty();
}
//Assert
result.Should().HaveCount(1);
result.First().Series.Should().NotBeNull();
result.First().Series.SeriesId.Should().NotBe(0);
[Test]
public void Get_Week_should_skip_unmonitored_series()
{
WithIgnoredSeries();
Mocker.Resolve<UpcomingEpisodesProvider>().Week().Should().BeEmpty();
}
}
}

@ -20,30 +20,31 @@ namespace NzbDrone.Core.Providers
public virtual List<Episode> Yesterday()
{
return _database.Fetch<Episode, Series>(@"SELECT * FROM Episodes
INNER JOIN Series ON Episodes.SeriesId = Series.SeriesId
WHERE Ignored = 0 AND AirDate = @0", DateTime.Today.AddDays(-1));
return RecentEpisodes().Where(c => c.AirDate.Value.Date == DateTime.Now.Date.AddDays(-1)).ToList();
}
public virtual List<Episode> Today()
{
return _database.Fetch<Episode, Series>(@"SELECT * FROM Episodes
INNER JOIN Series ON Episodes.SeriesId = Series.SeriesId
WHERE Ignored = 0 AND AirDate = @0", DateTime.Today);
return RecentEpisodes().Where(c => c.AirDate.Value.Date == DateTime.Now.Date).ToList();
}
public virtual List<Episode> Tomorrow()
{
return _database.Fetch<Episode, Series>(@"SELECT * FROM Episodes
INNER JOIN Series ON Episodes.SeriesId = Series.SeriesId
WHERE Ignored = 0 AND AirDate = @0", DateTime.Today.AddDays(1));
return RecentEpisodes().Where(c => c.AirDate.Value.Date == DateTime.Now.Date.AddDays(1)).ToList();
}
public virtual List<Episode> Week()
{
return RecentEpisodes().Where(c => c.AirDate >= DateTime.Today.AddDays(2).Date).ToList();
}
private List<Episode> RecentEpisodes()
{
return _database.Fetch<Episode, Series>(@"SELECT * FROM Episodes
INNER JOIN Series ON Episodes.SeriesId = Series.SeriesId
WHERE Ignored = 0 AND AirDate BETWEEN @0 AND @1", DateTime.Today.AddDays(2), DateTime.Today.AddDays(8));
WHERE Series.Monitored = 1 AND Ignored = 0 AND AirDate BETWEEN @0 AND @1"
,DateTime.Today.AddDays(-1).Date, DateTime.Today.AddDays(8).Date);
}
}
}
Loading…
Cancel
Save