Added EpisodesWithFiles to get episodes in a serires that have an episode file

This commit is contained in:
Mark McDowall 2014-03-06 01:46:19 -08:00
parent 9533e9e403
commit fb5bd4994a
4 changed files with 92 additions and 0 deletions

View File

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

View File

@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Test.TvTests.EpisodeRepositoryTests
{
[TestFixture]
public class EpisodesWithFilesFixture : DbTest<EpisodeRepository, Episode>
{
private const int SERIES_ID = 1;
private List<Episode> _episodes;
private List<EpisodeFile> _episodeFiles;
[SetUp]
public void Setup()
{
_episodeFiles = Builder<EpisodeFile>.CreateListOfSize(5)
.BuildListOfNew()
.ToList();
Db.InsertMany(_episodeFiles);
_episodes = Builder<Episode>.CreateListOfSize(10)
.All()
.With(e => e.EpisodeFileId = 0)
.With(e => e.SeriesId = SERIES_ID)
.BuildListOfNew()
.ToList();
for (int i = 0; i < _episodeFiles.Count; i++)
{
_episodes[i].EpisodeFileId = _episodeFiles[i].Id;
}
Db.InsertMany(_episodes);
}
[Test]
public void should_only_get_files_that_have_episode_files()
{
var result = Subject.EpisodesWithFiles(SERIES_ID);
result.Should().OnlyContain(e => e.EpisodeFileId > 0);
result.Should().HaveCount(_episodeFiles.Count);
}
[Test]
public void should_only_contain_episodes_for_the_given_series()
{
var episodeFile = Builder<EpisodeFile>.CreateNew()
.BuildNew();
Db.Insert(episodeFile);
var episode = Builder<Episode>.CreateNew()
.With(e => e.SeriesId = SERIES_ID + 10)
.With(e => e.EpisodeFileId = episodeFile.Id)
.BuildNew();
Db.Insert(episode);
Subject.EpisodesWithFiles(episode.SeriesId).Should().OnlyContain(e => e.SeriesId == episode.SeriesId);
}
[Test]
public void should_have_episode_file_loaded()
{
Subject.EpisodesWithFiles(SERIES_ID).Should().OnlyContain(e => e.EpisodeFile.IsLoaded);
}
}
}

View File

@ -19,6 +19,7 @@ namespace NzbDrone.Core.Tv
List<Episode> GetEpisodes(int seriesId);
List<Episode> GetEpisodes(int seriesId, int seasonNumber);
List<Episode> GetEpisodeByFileId(int fileId);
List<Episode> EpisodesWithFiles(int seriesId);
PagingSpec<Episode> EpisodesWithoutFiles(PagingSpec<Episode> pagingSpec, bool includeSpecials);
PagingSpec<Episode> EpisodesWhereCutoffUnmet(PagingSpec<Episode> pagingSpec, List<QualitiesBelowCutoff> qualitiesBelowCutoff, bool includeSpecials);
List<Episode> FindEpisodesBySceneNumbering(int seriesId, int seasonNumber, int episodeNumber);
@ -84,6 +85,12 @@ namespace NzbDrone.Core.Tv
return Query.Where(e => e.EpisodeFileId == fileId).ToList();
}
public List<Episode> EpisodesWithFiles(int seriesId)
{
return Query.Join<Episode, EpisodeFile>(JoinType.Inner, e => e.EpisodeFile, (e, ef) => e.EpisodeFileId == ef.Id)
.Where(e => e.SeriesId == seriesId);
}
public PagingSpec<Episode> EpisodesWithoutFiles(PagingSpec<Episode> pagingSpec, bool includeSpecials)
{
var currentTime = DateTime.UtcNow;

View File

@ -22,6 +22,7 @@ namespace NzbDrone.Core.Tv
Episode FindEpisode(int seriesId, String date);
List<Episode> GetEpisodeBySeries(int seriesId);
List<Episode> GetEpisodesBySeason(int seriesId, int seasonNumber);
List<Episode> EpisodesWithFiles(int seriesId);
PagingSpec<Episode> EpisodesWithoutFiles(PagingSpec<Episode> pagingSpec);
List<Episode> GetEpisodesByFileId(int episodeFileId);
void UpdateEpisode(Episode episode);
@ -105,6 +106,11 @@ namespace NzbDrone.Core.Tv
});
}
public List<Episode> EpisodesWithFiles(int seriesId)
{
return _episodeRepository.EpisodesWithFiles(seriesId);
}
public PagingSpec<Episode> EpisodesWithoutFiles(PagingSpec<Episode> pagingSpec)
{
var episodeResult = _episodeRepository.EpisodesWithoutFiles(pagingSpec, false);