1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-25 09:21:57 +00:00

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

This commit is contained in:
kay.one 2012-02-11 16:02:36 -08:00
parent 6df184b7cb
commit 659b3dee55
2 changed files with 75 additions and 129 deletions

View file

@ -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 @@ public class UpcomingEpisodesProviderTest : CoreTest
[SetUp]
public void Setup()
{
WithRealDb();
episodes = Builder<Episode>.CreateListOfSize(6)
.All()
.With(e => e.SeriesId = 1)
@ -42,174 +41,120 @@ public void Setup()
.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);
}
private void WithIgnoredEpisodes()
{
episodes.ToList().ForEach(c => c.Ignored = true);
Db.UpdateMany(episodes);
}
private void WithIgnoredSeries()
{
series.Monitored = false;
Db.Update(series);
}
[Test]
public void Get_Yesterday()
{
//Setup
var database = TestDbHelper.GetEmptyDatabase();
Mocker.SetConstant(database);
database.InsertMany(episodes);
database.Insert(series);
//Act
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);
WithIgnoredEpisodes();
Mocker.Resolve<UpcomingEpisodesProvider>().Week().Should().BeEmpty();
}
episodes.Where(e => e.AirDate == DateTime.Today.AddDays(2)).Single().Ignored = true;
[Test]
public void Get_Today_should_skip_unmonitored_series()
{
WithIgnoredSeries();
Mocker.Resolve<UpcomingEpisodesProvider>().Today().Should().BeEmpty();
}
database.InsertMany(episodes);
database.Insert(series);
[Test]
public void Get_Tomoroww_should_skip_unmonitored_series()
{
WithIgnoredSeries();
Mocker.Resolve<UpcomingEpisodesProvider>().Tomorrow().Should().BeEmpty();
}
//Act
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Week();
//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();
}
}
}

View file

@ -20,30 +20,31 @@ public UpcomingEpisodesProvider(IDatabase database)
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);
}
}
}