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

or RefreshEpisodeInfo. With tests.
pull/4/head
Mark McDowall 13 years ago
parent 2cafedb1aa
commit 33930534c2

@ -324,6 +324,49 @@ namespace NzbDrone.Core.Test
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]
public void new_episodes_only_calls_Insert()
{

@ -188,5 +188,52 @@ namespace NzbDrone.Core.Test
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();
}
}
}

@ -146,6 +146,9 @@ namespace NzbDrone.Core.Providers
Overview = String.Empty,
};
if (parseResult.EpisodeNumbers.Count == 1 && parseResult.EpisodeNumbers.First() == 0)
episodeInfo.Ignored = true;
AddEpisode(episodeInfo);
}
@ -230,7 +233,15 @@ namespace NzbDrone.Core.Providers
{
episodeToUpdate = new Episode();
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
{
updateList.Add(episodeToUpdate);

Loading…
Cancel
Save