Improved: Episodes that are in the future AND have no title will not be added to db (place holder episodes in TVDB)

pull/2/head
kay.one 13 years ago
parent 9bee9be397
commit 9fcb3a4573

@ -255,6 +255,7 @@ namespace NzbDrone.Core.Test.ProviderTests
actualCount.Should().Be(episodeCount);
}
[Test]
public void RefreshEpisodeInfo_should_set_older_than_1900_to_null()
{
@ -369,6 +370,148 @@ namespace NzbDrone.Core.Test.ProviderTests
result.Where(e => e.EpisodeNumber == 0 && e.SeasonNumber == 15).Single().Ignored.Should().BeTrue();
}
[Test]
public void RefreshEpisodeInfo_should_skip_future_episodes_with_no_title()
{
//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).
All()
.With(a => c.FirstAired = DateTime.Now.AddDays(-2))
.With(e => e.EpisodeName = "Something")
.TheFirst(3)
.With(e => e.EpisodeName = "")
.With(e => e.FirstAired = DateTime.Now.AddDays(10))
.Build())
).With(c => c.Id = seriesId).Build();
var fakeSeries = Builder<Series>.CreateNew().With(c => c.SeriesId = seriesId).Build();
WithRealDb();
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();
result.Should().HaveCount(episodeCount - 3);
result.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.Title) || c.AirDate < DateTime.Now);
}
[Test]
public void RefreshEpisodeInfo_should_skip_older_than_1900_year_episodes_with_no_title()
{
//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).
All()
.With(a => c.FirstAired = DateTime.Now.AddDays(-2))
.With(e => e.EpisodeName = "Something")
.TheFirst(3)
.With(e => e.EpisodeName = "")
.With(e => e.FirstAired = new DateTime(1889,1,1))
.Build())
).With(c => c.Id = seriesId).Build();
var fakeSeries = Builder<Series>.CreateNew().With(c => c.SeriesId = seriesId).Build();
WithRealDb();
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();
result.Should().HaveCount(episodeCount - 3);
result.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.Title) || c.AirDate < DateTime.Now);
}
[Test]
public void RefreshEpisodeInfo_should_add_future_episodes_with_title()
{
const int seriesId = 71663;
var fakeEpisodes = Builder<TvdbSeries>.CreateNew().With(
c => c.Episodes = new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(10).
All()
.With(a => a.FirstAired = DateTime.Now.AddDays(10))
.With(e => e.EpisodeName = "Something")
.Build())
).With(c => c.Id = seriesId).Build();
var fakeSeries = Builder<Series>.CreateNew().With(c => c.SeriesId = seriesId).Build();
WithRealDb();
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();
result.Should().HaveSameCount(fakeEpisodes.Episodes);
}
[Test]
public void RefreshEpisodeInfo_should_add_old_episodes_with_no_title()
{
const int seriesId = 71663;
var fakeEpisodes = Builder<TvdbSeries>.CreateNew().With(
c => c.Episodes = new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(10).
All()
.With(a => a.FirstAired = DateTime.Now.AddDays(-10))
.With(e => e.EpisodeName = string.Empty)
.Build())
).With(c => c.Id = seriesId).Build();
var fakeSeries = Builder<Series>.CreateNew().With(c => c.SeriesId = seriesId).Build();
WithRealDb();
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();
result.Should().HaveSameCount(fakeEpisodes.Episodes);
}
[Test]
public void RefreshEpisodeInfo_ignore_season_zero()
{

@ -282,6 +282,11 @@ namespace NzbDrone.Core.Providers
{
try
{
//skip episodes that are too far in the future and have no title.
if ((episode.FirstAired > DateTime.Now.AddDays(2) || episode.FirstAired.Year < 1900) &&
string.IsNullOrWhiteSpace(episode.EpisodeName))
continue;
Logger.Trace("Updating info for [{0}] - S{1}E{2}", tvDbSeriesInfo.SeriesName, episode.SeasonNumber, episode.EpisodeNumber);
//first check using tvdbId, this should cover cases when and episode number in a season is changed

Loading…
Cancel
Save