From 659b3dee55334c1dbdfa5dddd09157fb10986a28 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sat, 11 Feb 2012 16:02:36 -0800 Subject: [PATCH] Improved: Upcoming episodes page no longer shows series that aren't monitored. --- .../UpcomingEpisodesProviderTest.cs | 183 ++++++------------ .../Providers/UpcomingEpisodesProvider.cs | 21 +- 2 files changed, 75 insertions(+), 129 deletions(-) diff --git a/NzbDrone.Core.Test/ProviderTests/UpcomingEpisodesProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/UpcomingEpisodesProviderTest.cs index 3eb840579..627dd2ca1 100644 --- a/NzbDrone.Core.Test/ProviderTests/UpcomingEpisodesProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/UpcomingEpisodesProviderTest.cs @@ -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 episodes; @@ -24,6 +21,8 @@ namespace NzbDrone.Core.Test.ProviderTests [SetUp] public void Setup() { + WithRealDb(); + episodes = Builder.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.CreateNew().With(s => s.SeriesId = 1).Build(); + series = Builder.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().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().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().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().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().Yesterday(); - - //Assert - result.Should().BeEmpty(); + WithIgnoredEpisodes(); + Mocker.Resolve().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().Today(); - - //Assert - result.Should().BeEmpty(); + WithIgnoredEpisodes(); + Mocker.Resolve().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().Tomorrow(); - - //Assert - result.Should().BeEmpty(); + WithIgnoredEpisodes(); + Mocker.Resolve().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().Week().Should().BeEmpty(); + } - database.InsertMany(episodes); - database.Insert(series); + [Test] + public void Get_Today_should_skip_unmonitored_series() + { + WithIgnoredSeries(); + Mocker.Resolve().Today().Should().BeEmpty(); + } - //Act - var result = Mocker.Resolve().Week(); + [Test] + public void Get_Tomoroww_should_skip_unmonitored_series() + { + WithIgnoredSeries(); + Mocker.Resolve().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().Week().Should().BeEmpty(); } } } diff --git a/NzbDrone.Core/Providers/UpcomingEpisodesProvider.cs b/NzbDrone.Core/Providers/UpcomingEpisodesProvider.cs index b5488f888..cba27572e 100644 --- a/NzbDrone.Core/Providers/UpcomingEpisodesProvider.cs +++ b/NzbDrone.Core/Providers/UpcomingEpisodesProvider.cs @@ -20,30 +20,31 @@ namespace NzbDrone.Core.Providers public virtual List Yesterday() { - return _database.Fetch(@"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 Today() { - return _database.Fetch(@"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 Tomorrow() { - return _database.Fetch(@"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 Week() + { + return RecentEpisodes().Where(c => c.AirDate >= DateTime.Today.AddDays(2).Date).ToList(); + + } + + private List RecentEpisodes() { return _database.Fetch(@"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); } } } \ No newline at end of file