Processed PR Comments.

Added tests for EpisodesWithCutoffUnmet.
This commit is contained in:
Taloth Saldono 2014-02-13 20:02:58 +01:00 committed by Mark McDowall
parent d416dd4177
commit 8f87f06ac6
8 changed files with 235 additions and 30 deletions

View File

@ -29,14 +29,18 @@ namespace NzbDrone.Api.Wanted
SortKey = pagingResource.SortKey, SortKey = pagingResource.SortKey,
SortDirection = pagingResource.SortDirection SortDirection = pagingResource.SortDirection
}; };
if (pagingResource.FilterKey == "monitored" && pagingResource.FilterValue == "false")
pagingSpec.FilterExpression = v => v.Monitored == false || v.Series.Monitored == false;
else
pagingSpec.FilterExpression = v => v.Monitored == true && v.Series.Monitored == true;
PagingResource<EpisodeResource> resource = ApplyToPage(_episodeService.GetCutoffUnmetEpisodes, pagingSpec); if (pagingResource.FilterKey == "monitored" && pagingResource.FilterValue == "false")
{
pagingSpec.FilterExpression = v => v.Monitored == false || v.Series.Monitored == false;
}
else
{
pagingSpec.FilterExpression = v => v.Monitored == true && v.Series.Monitored == true;
}
PagingResource<EpisodeResource> resource = ApplyToPage(_episodeService.EpisodesWhereCutoffUnmet, pagingSpec);
resource.Records = resource.Records.LoadSubtype(e => e.SeriesId, _seriesRepository).ToList(); resource.Records = resource.Records.LoadSubtype(e => e.SeriesId, _seriesRepository).ToList();
return resource; return resource;

View File

@ -28,13 +28,17 @@ namespace NzbDrone.Api.Wanted
SortKey = pagingResource.SortKey, SortKey = pagingResource.SortKey,
SortDirection = pagingResource.SortDirection SortDirection = pagingResource.SortDirection
}; };
if (pagingResource.FilterKey == "monitored" && pagingResource.FilterValue == "false")
pagingSpec.FilterExpression = v => v.Monitored == false || v.Series.Monitored == false;
else
pagingSpec.FilterExpression = v => v.Monitored == true && v.Series.Monitored == true;
PagingResource<EpisodeResource> resource = ApplyToPage(v => _episodeService.GetMissingEpisodes(v), pagingSpec); if (pagingResource.FilterKey == "monitored" && pagingResource.FilterValue == "false")
{
pagingSpec.FilterExpression = v => v.Monitored == false || v.Series.Monitored == false;
}
else
{
pagingSpec.FilterExpression = v => v.Monitored == true && v.Series.Monitored == true;
}
PagingResource<EpisodeResource> resource = ApplyToPage(v => _episodeService.EpisodesWithoutFiles(v), pagingSpec);
resource.Records = resource.Records.LoadSubtype(e => e.SeriesId, _seriesRepository).ToList(); resource.Records = resource.Records.LoadSubtype(e => e.SeriesId, _seriesRepository).ToList();

View File

@ -211,6 +211,7 @@
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedEpisodesFixture.cs" /> <Compile Include="Housekeeping\Housekeepers\CleanupOrphanedEpisodesFixture.cs" />
<Compile Include="ThingiProviderTests\NullConfigFixture.cs" /> <Compile Include="ThingiProviderTests\NullConfigFixture.cs" />
<Compile Include="ThingiProvider\ProviderBaseFixture.cs" /> <Compile Include="ThingiProvider\ProviderBaseFixture.cs" />
<Compile Include="TvTests\EpisodeRepositoryTests\EpisodesWhereCutoffUnmetFixture.cs" />
<Compile Include="TvTests\RefreshEpisodeServiceFixture.cs" /> <Compile Include="TvTests\RefreshEpisodeServiceFixture.cs" />
<Compile Include="TvTests\EpisodeProviderTests\HandleEpisodeFileDeletedFixture.cs" /> <Compile Include="TvTests\EpisodeProviderTests\HandleEpisodeFileDeletedFixture.cs" />
<Compile Include="TvTests\EpisodeRepositoryTests\FindEpisodeFixture.cs" /> <Compile Include="TvTests\EpisodeRepositoryTests\FindEpisodeFixture.cs" />

View File

@ -0,0 +1,168 @@
using System;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.MediaFiles;
namespace NzbDrone.Core.Test.TvTests.EpisodeRepositoryTests
{
[TestFixture]
public class EpisodesWhereCutoffUnmetFixture : DbTest<EpisodeRepository, Episode>
{
private Series _monitoredSeries;
private Series _unmonitoredSeries;
private PagingSpec<Episode> _pagingSpec;
[SetUp]
public void Setup()
{
var qualityProfile = new QualityProfile
{
Cutoff = Quality.WEBDL720p,
Items = Qualities.QualityFixture.GetDefaultQualities()
};
_monitoredSeries = Builder<Series>.CreateNew()
.With(s => s.Id = 0)
.With(s => s.TvRageId = RandomNumber)
.With(s => s.Runtime = 30)
.With(s => s.Monitored = true)
.With(s => s.TitleSlug = "Title3")
.With(s => s.QualityProfile = qualityProfile)
.Build();
_unmonitoredSeries = Builder<Series>.CreateNew()
.With(s => s.Id = 0)
.With(s => s.TvdbId = RandomNumber)
.With(s => s.Runtime = 30)
.With(s => s.Monitored = false)
.With(s => s.TitleSlug = "Title2")
.With(s => s.QualityProfile = qualityProfile)
.Build();
_monitoredSeries.Id = Db.Insert(_monitoredSeries).Id;
_unmonitoredSeries.Id = Db.Insert(_unmonitoredSeries).Id;
_pagingSpec = new PagingSpec<Episode>
{
Page = 1,
PageSize = 10,
SortKey = "AirDate",
SortDirection = SortDirection.Ascending
};
var qualityMet = new EpisodeFile { Path = "a", Quality = new QualityModel { Quality = Quality.WEBDL720p } };
var qualityUnmet = new EpisodeFile { Path = "b", Quality = new QualityModel { Quality = Quality.WEBDL480p } };
MediaFileRepository fileRepository = Mocker.Resolve<MediaFileRepository>();
qualityMet = fileRepository.Insert(qualityMet);
qualityUnmet = fileRepository.Insert(qualityUnmet);
var monitoredSeriesEpisodes = Builder<Episode>.CreateListOfSize(3)
.All()
.With(e => e.Id = 0)
.With(e => e.SeriesId = _monitoredSeries.Id)
.With(e => e.AirDateUtc = DateTime.Now.AddDays(-5))
.With(e => e.Monitored = true)
.With(e => e.EpisodeFileId = qualityUnmet.Id)
.TheFirst(1)
.With(e => e.Monitored = false)
.With(e => e.EpisodeFileId = qualityMet.Id)
.TheLast(1)
.With(e => e.SeasonNumber = 0)
.Build();
var unmonitoredSeriesEpisodes = Builder<Episode>.CreateListOfSize(3)
.All()
.With(e => e.Id = 0)
.With(e => e.SeriesId = _unmonitoredSeries.Id)
.With(e => e.AirDateUtc = DateTime.Now.AddDays(-5))
.With(e => e.Monitored = true)
.With(e => e.EpisodeFileId = qualityUnmet.Id)
.TheFirst(1)
.With(e => e.Monitored = false)
.With(e => e.EpisodeFileId = qualityMet.Id)
.TheLast(1)
.With(e => e.SeasonNumber = 0)
.Build();
var unairedEpisodes = Builder<Episode>.CreateListOfSize(1)
.All()
.With(e => e.Id = 0)
.With(e => e.SeriesId = _monitoredSeries.Id)
.With(e => e.AirDateUtc = DateTime.Now.AddDays(5))
.With(e => e.Monitored = true)
.With(e => e.EpisodeFileId = qualityUnmet.Id)
.Build();
Db.InsertMany(monitoredSeriesEpisodes);
Db.InsertMany(unmonitoredSeriesEpisodes);
Db.InsertMany(unairedEpisodes);
}
private void GivenMonitoredFilterExpression()
{
_pagingSpec.FilterExpression = e => e.Monitored == true && e.Series.Monitored == true;
}
private void GivenUnmonitoredFilterExpression()
{
_pagingSpec.FilterExpression = e => e.Monitored == false || e.Series.Monitored == false;
}
[Test]
public void should_get_monitored_episodes()
{
GivenMonitoredFilterExpression();
var episodes = Subject.EpisodesWhereCutoffUnmet(_pagingSpec, false);
episodes.Should().HaveCount(1);
}
[Test]
[Ignore("Specials not implemented")]
public void should_get_episode_including_specials()
{
var episodes = Subject.EpisodesWhereCutoffUnmet(_pagingSpec, true);
episodes.Should().HaveCount(2);
}
[Test]
public void should_not_include_unmonitored_episodes()
{
GivenMonitoredFilterExpression();
var episodes = Subject.EpisodesWhereCutoffUnmet(_pagingSpec, false);
episodes.Should().NotContain(e => e.Monitored == false);
}
[Test]
public void should_not_contain_unmonitored_series()
{
GivenMonitoredFilterExpression();
var episodes = Subject.EpisodesWhereCutoffUnmet(_pagingSpec, false);
episodes.Should().NotContain(e => e.SeriesId == _unmonitoredSeries.Id);
}
[Test]
public void should_not_include_cutoff_met_episodes()
{
GivenMonitoredFilterExpression();
var episodes = Subject.EpisodesWhereCutoffUnmet(_pagingSpec, false);
episodes.Should().NotContain(e => e.EpisodeFile.Value.Quality.Quality == Quality.WEBDL720p);
}
}
}

View File

@ -72,14 +72,37 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeRepositoryTests
.Build(); .Build();
var unairedEpisodes = Builder<Episode>.CreateListOfSize(1)
.All()
.With(e => e.Id = 0)
.With(e => e.SeriesId = _monitoredSeries.Id)
.With(e => e.EpisodeFileId = 0)
.With(e => e.AirDateUtc = DateTime.Now.AddDays(5))
.With(e => e.Monitored = true)
.Build();
Db.InsertMany(monitoredSeriesEpisodes); Db.InsertMany(monitoredSeriesEpisodes);
Db.InsertMany(unmonitoredSeriesEpisodes); Db.InsertMany(unmonitoredSeriesEpisodes);
Db.InsertMany(unairedEpisodes);
}
private void GivenMonitoredFilterExpression()
{
_pagingSpec.FilterExpression = e => e.Monitored == true && e.Series.Monitored == true;
}
private void GivenUnmonitoredFilterExpression()
{
_pagingSpec.FilterExpression = e => e.Monitored == false || e.Series.Monitored == false;
} }
[Test] [Test]
public void should_get_monitored_episodes() public void should_get_monitored_episodes()
{ {
var episodes = Subject.GetMissingEpisodes(_pagingSpec, false); GivenMonitoredFilterExpression();
var episodes = Subject.EpisodesWithoutFiles(_pagingSpec, false);
episodes.Records.Should().HaveCount(1); episodes.Records.Should().HaveCount(1);
} }
@ -88,7 +111,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeRepositoryTests
[Ignore("Specials not implemented")] [Ignore("Specials not implemented")]
public void should_get_episode_including_specials() public void should_get_episode_including_specials()
{ {
var episodes = Subject.GetMissingEpisodes(_pagingSpec, true); var episodes = Subject.EpisodesWithoutFiles(_pagingSpec, true);
episodes.Records.Should().HaveCount(2); episodes.Records.Should().HaveCount(2);
} }
@ -96,7 +119,9 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeRepositoryTests
[Test] [Test]
public void should_not_include_unmonitored_episodes() public void should_not_include_unmonitored_episodes()
{ {
var episodes = Subject.GetMissingEpisodes(_pagingSpec, false); GivenMonitoredFilterExpression();
var episodes = Subject.EpisodesWithoutFiles(_pagingSpec, false);
episodes.Records.Should().NotContain(e => e.Monitored == false); episodes.Records.Should().NotContain(e => e.Monitored == false);
} }
@ -104,17 +129,19 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeRepositoryTests
[Test] [Test]
public void should_not_contain_unmonitored_series() public void should_not_contain_unmonitored_series()
{ {
var episodes = Subject.GetMissingEpisodes(_pagingSpec, false); GivenMonitoredFilterExpression();
var episodes = Subject.EpisodesWithoutFiles(_pagingSpec, false);
episodes.Records.Should().NotContain(e => e.SeriesId == _unmonitoredSeries.Id); episodes.Records.Should().NotContain(e => e.SeriesId == _unmonitoredSeries.Id);
} }
[Test] [Test]
public void should_have_count_of_one() public void should_not_return_unaired()
{ {
var episodes = Subject.GetMissingEpisodes(_pagingSpec, false); var episodes = Subject.EpisodesWithoutFiles(_pagingSpec, false);
episodes.TotalRecords.Should().Be(1); episodes.TotalRecords.Should().Be(4);
} }
} }
} }

View File

@ -17,8 +17,8 @@ namespace NzbDrone.Core.Tv
List<Episode> GetEpisodes(int seriesId); List<Episode> GetEpisodes(int seriesId);
List<Episode> GetEpisodes(int seriesId, int seasonNumber); List<Episode> GetEpisodes(int seriesId, int seasonNumber);
List<Episode> GetEpisodeByFileId(int fileId); List<Episode> GetEpisodeByFileId(int fileId);
PagingSpec<Episode> GetMissingEpisodes(PagingSpec<Episode> pagingSpec, bool includeSpecials); PagingSpec<Episode> EpisodesWithoutFiles(PagingSpec<Episode> pagingSpec, bool includeSpecials);
List<Episode> GetCutoffUnmetEpisodes(PagingSpec<Episode> pagingSpec, bool includeSpecials); List<Episode> EpisodesWhereCutoffUnmet(PagingSpec<Episode> pagingSpec, bool includeSpecials);
Episode FindEpisodeBySceneNumbering(int seriesId, int seasonNumber, int episodeNumber); Episode FindEpisodeBySceneNumbering(int seriesId, int seasonNumber, int episodeNumber);
List<Episode> EpisodesBetweenDates(DateTime startDate, DateTime endDate); List<Episode> EpisodesBetweenDates(DateTime startDate, DateTime endDate);
void SetMonitoredFlat(Episode episode, bool monitored); void SetMonitoredFlat(Episode episode, bool monitored);
@ -82,7 +82,7 @@ namespace NzbDrone.Core.Tv
return Query.Where(e => e.EpisodeFileId == fileId).ToList(); return Query.Where(e => e.EpisodeFileId == fileId).ToList();
} }
public PagingSpec<Episode> GetMissingEpisodes(PagingSpec<Episode> pagingSpec, bool includeSpecials) public PagingSpec<Episode> EpisodesWithoutFiles(PagingSpec<Episode> pagingSpec, bool includeSpecials)
{ {
var currentTime = DateTime.UtcNow; var currentTime = DateTime.UtcNow;
var startingSeasonNumber = 1; var startingSeasonNumber = 1;
@ -98,7 +98,7 @@ namespace NzbDrone.Core.Tv
return pagingSpec; return pagingSpec;
} }
public List<Episode> GetCutoffUnmetEpisodes(PagingSpec<Episode> pagingSpec, bool includeSpecials) public List<Episode> EpisodesWhereCutoffUnmet(PagingSpec<Episode> pagingSpec, bool includeSpecials)
{ {
var currentTime = DateTime.UtcNow; var currentTime = DateTime.UtcNow;
var startingSeasonNumber = 1; var startingSeasonNumber = 1;

View File

@ -21,8 +21,8 @@ namespace NzbDrone.Core.Tv
Episode FindEpisode(int seriesId, String date); Episode FindEpisode(int seriesId, String date);
List<Episode> GetEpisodeBySeries(int seriesId); List<Episode> GetEpisodeBySeries(int seriesId);
List<Episode> GetEpisodesBySeason(int seriesId, int seasonNumber); List<Episode> GetEpisodesBySeason(int seriesId, int seasonNumber);
PagingSpec<Episode> GetMissingEpisodes(PagingSpec<Episode> pagingSpec); PagingSpec<Episode> EpisodesWithoutFiles(PagingSpec<Episode> pagingSpec);
PagingSpec<Episode> GetCutoffUnmetEpisodes(PagingSpec<Episode> pagingSpec); PagingSpec<Episode> EpisodesWhereCutoffUnmet(PagingSpec<Episode> pagingSpec);
List<Episode> GetEpisodesByFileId(int episodeFileId); List<Episode> GetEpisodesByFileId(int episodeFileId);
void UpdateEpisode(Episode episode); void UpdateEpisode(Episode episode);
void SetEpisodeMonitored(int episodeId, bool monitored); void SetEpisodeMonitored(int episodeId, bool monitored);
@ -109,12 +109,12 @@ namespace NzbDrone.Core.Tv
public PagingSpec<Episode> EpisodesWithoutFiles(PagingSpec<Episode> pagingSpec) public PagingSpec<Episode> EpisodesWithoutFiles(PagingSpec<Episode> pagingSpec)
{ {
var episodeResult = _episodeRepository.GetMissingEpisodes(pagingSpec, false); var episodeResult = _episodeRepository.EpisodesWithoutFiles(pagingSpec, false);
return episodeResult; return episodeResult;
} }
public PagingSpec<Episode> GetCutoffUnmetEpisodes(PagingSpec<Episode> pagingSpec) public PagingSpec<Episode> EpisodesWhereCutoffUnmet(PagingSpec<Episode> pagingSpec)
{ {
var allSpec = new PagingSpec<Episode> var allSpec = new PagingSpec<Episode>
{ {
@ -123,7 +123,7 @@ namespace NzbDrone.Core.Tv
FilterExpression = pagingSpec.FilterExpression FilterExpression = pagingSpec.FilterExpression
}; };
var allItems = _episodeRepository.GetCutoffUnmetEpisodes(allSpec, false); var allItems = _episodeRepository.EpisodesWhereCutoffUnmet(allSpec, false);
var qualityProfileComparers = _qualityProfileRepository.All().ToDictionary(v => v.Id, v => new { Profile = v, Comparer = new QualityModelComparer(v) }); var qualityProfileComparers = _qualityProfileRepository.All().ToDictionary(v => v.Id, v => new { Profile = v, Comparer = new QualityModelComparer(v) });

View File

@ -22,8 +22,9 @@ define(
setActive: function () { setActive: function () {
var storedKey = this.menu.defaultAction; var storedKey = this.menu.defaultAction;
if (this.menu.storeState) if (this.menu.storeState) {
storedKey = Config.getValue(this.menu.menuKey, storedKey); storedKey = Config.getValue(this.menu.menuKey, storedKey);
}
if (!storedKey) if (!storedKey)
return; return;