Ignore Episode Zero when adding a new episode to the database, either via GetEpisodesByParseResult

or RefreshEpisodeInfo. With tests.
This commit is contained in:
Mark McDowall 2011-10-03 19:01:39 -07:00
parent 2cafedb1aa
commit 33930534c2
3 changed files with 101 additions and 0 deletions

View File

@ -324,6 +324,49 @@ namespace NzbDrone.Core.Test
mocker.VerifyAllMocks(); mocker.VerifyAllMocks();
} }
[Test]
public void RefreshEpisodeInfo_ignore_episode_zero()
{
//Arrange
const int seriesId = 71663;
const int episodeCount = 10;
var fakeEpisodes = Builder<TvdbSeries>.CreateNew().With(
c => c.Episodes =
new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
WhereAll()
.Have(l => l.Language = new TvdbLanguage(0, "eng", "a"))
.WhereTheFirst(1)
.Has(e => e.EpisodeNumber = 0)
.Has(e => e.SeasonNumber = 15)
.Build())
).With(c => c.Id = seriesId).Build();
var fakeSeries = Builder<Series>.CreateNew().With(c => c.SeriesId = seriesId).Build();
var mocker = new AutoMoqer();
var db = MockLib.GetEmptyDatabase();
mocker.SetConstant(db);
db.Insert(fakeSeries);
mocker.GetMock<TvDbProvider>()
.Setup(c => c.GetSeries(seriesId, true))
.Returns(fakeEpisodes);
//Act
mocker.Resolve<EpisodeProvider>().RefreshEpisodeInfo(fakeSeries);
//Assert
var result = mocker.Resolve<EpisodeProvider>().GetEpisodeBySeries(seriesId).ToList();
mocker.GetMock<TvDbProvider>().VerifyAll();
result.Should().HaveCount(episodeCount);
mocker.VerifyAllMocks();
result.Where(e => e.EpisodeNumber == 0 && e.SeasonNumber == 15).Single().Ignored.Should().BeTrue();
}
[Test] [Test]
public void new_episodes_only_calls_Insert() public void new_episodes_only_calls_Insert()
{ {

View File

@ -188,5 +188,52 @@ namespace NzbDrone.Core.Test
db.Fetch<Episode>().Should().HaveCount(2); db.Fetch<Episode>().Should().HaveCount(2);
} }
[Test]
public void Get_Episode_Zero_Doesnt_Exist_Should_add_ignored()
{
var mocker = new AutoMoqer();
var db = MockLib.GetEmptyDatabase();
mocker.SetConstant(db);
var fakeSeries = Builder<Series>.CreateNew().Build();
var parseResult = new EpisodeParseResult
{
Series = fakeSeries,
SeasonNumber = 2,
EpisodeNumbers = new List<int> { 0 }
};
var ep = mocker.Resolve<EpisodeProvider>().GetEpisodesByParseResult(parseResult, true);
ep.Should().HaveCount(1);
db.Fetch<Episode>().Should().HaveCount(1);
ep.First().Ignored.Should().BeTrue();
}
[Test]
public void Get_Multi_Episode_Zero_Doesnt_Exist_Should_not_add_ignored()
{
var mocker = new AutoMoqer();
var db = MockLib.GetEmptyDatabase();
mocker.SetConstant(db);
var fakeSeries = Builder<Series>.CreateNew().Build();
var parseResult = new EpisodeParseResult
{
Series = fakeSeries,
SeasonNumber = 2,
EpisodeNumbers = new List<int> { 0, 1 }
};
var ep = mocker.Resolve<EpisodeProvider>().GetEpisodesByParseResult(parseResult, true);
ep.Should().HaveCount(2);
db.Fetch<Episode>().Should().HaveCount(2);
ep.First().Ignored.Should().BeFalse();
}
} }
} }

View File

@ -146,6 +146,9 @@ namespace NzbDrone.Core.Providers
Overview = String.Empty, Overview = String.Empty,
}; };
if (parseResult.EpisodeNumbers.Count == 1 && parseResult.EpisodeNumbers.First() == 0)
episodeInfo.Ignored = true;
AddEpisode(episodeInfo); AddEpisode(episodeInfo);
} }
@ -230,7 +233,15 @@ namespace NzbDrone.Core.Providers
{ {
episodeToUpdate = new Episode(); episodeToUpdate = new Episode();
newList.Add(episodeToUpdate); newList.Add(episodeToUpdate);
//We need to check if this episode should be ignored based on IsIgnored rules
IsIgnored(series.SeriesId, episode.SeasonNumber);
//If it is Episode Zero Ignore it, since it is new
if (episode.EpisodeNumber == 0)
episodeToUpdate.Ignored = true;
} }
else else
{ {
updateList.Add(episodeToUpdate); updateList.Add(episodeToUpdate);