1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-26 01:38:24 +00:00

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

This commit is contained in:
kay.one 2012-02-04 20:34:28 -08:00
parent 9bee9be397
commit 9fcb3a4573
2 changed files with 148 additions and 0 deletions

View file

@ -255,6 +255,7 @@ public void RefreshEpisodeInfo_emptyRepo()
actualCount.Should().Be(episodeCount); actualCount.Should().Be(episodeCount);
} }
[Test] [Test]
public void RefreshEpisodeInfo_should_set_older_than_1900_to_null() public void RefreshEpisodeInfo_should_set_older_than_1900_to_null()
{ {
@ -369,6 +370,148 @@ public void RefreshEpisodeInfo_ignore_episode_zero()
result.Where(e => e.EpisodeNumber == 0 && e.SeasonNumber == 15).Single().Ignored.Should().BeTrue(); 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] [Test]
public void RefreshEpisodeInfo_ignore_season_zero() public void RefreshEpisodeInfo_ignore_season_zero()
{ {

View file

@ -282,6 +282,11 @@ public virtual void RefreshEpisodeInfo(Series series)
{ {
try 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); 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 //first check using tvdbId, this should cover cases when and episode number in a season is changed