TVDB numbering confusion fixed

Fixed: Issue when episode numbers changed on TheTVDB causing episode
files were linked incorrectly
pull/2/head
Mark McDowall 12 years ago
parent 02cf23721a
commit 23f8f534fc

@ -630,7 +630,16 @@ namespace NzbDrone.Core.Test.ProviderTests
var currentEpisodes = new List<Episode>();
foreach (var tvDbEpisode in tvdbSeries.Episodes)
{
currentEpisodes.Add(new Episode { TvDbEpisodeId = tvDbEpisode.Id, EpisodeId = 99, EpisodeFileId = 69, Ignored = true, Series = fakeSeries });
currentEpisodes.Add(new Episode
{
TvDbEpisodeId = tvDbEpisode.Id,
EpisodeId = 99,
EpisodeFileId = 69,
Ignored = true,
Series = fakeSeries,
EpisodeNumber = tvDbEpisode.EpisodeNumber,
SeasonNumber = tvDbEpisode.SeasonNumber
});
}
Mocker.GetMock<TvDbProvider>(MockBehavior.Strict)
@ -657,6 +666,98 @@ namespace NzbDrone.Core.Test.ProviderTests
updatedEpisodes.Should().OnlyContain(c => c.Ignored == true);
}
[Test]
public void existing_episodes_remote_their_episodeId_file_id_when_episode_number_doesnt_match_tvdbid()
{
const int seriesId = 71663;
var tvdbSeries = Builder<TvdbSeries>.CreateNew()
.With(c => c.Episodes = new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(5).Build())
).With(c => c.Id = seriesId).Build();
var fakeSeries = Builder<Series>.CreateNew().With(c => c.SeriesId = seriesId).Build();
var currentEpisodes = new List<Episode>();
foreach (var tvDbEpisode in tvdbSeries.Episodes)
{
currentEpisodes.Add(new Episode
{
TvDbEpisodeId = tvDbEpisode.Id,
EpisodeId = 99,
EpisodeFileId = 69,
Ignored = true,
Series = fakeSeries,
EpisodeNumber = tvDbEpisode.EpisodeNumber + 1,
SeasonNumber = tvDbEpisode.SeasonNumber
});
}
Mocker.GetMock<TvDbProvider>(MockBehavior.Strict)
.Setup(c => c.GetSeries(seriesId, true, false))
.Returns(tvdbSeries);
var updatedEpisodes = new List<Episode>();
Mocker.GetMock<IDatabase>()
.Setup(d => d.Fetch<Episode, Series, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
.Returns(currentEpisodes);
Mocker.GetMock<IDatabase>()
.Setup(c => c.UpdateMany(It.IsAny<IEnumerable<Episode>>()))
.Callback<IEnumerable<Episode>>(ep => updatedEpisodes = ep.ToList());
//Act
Mocker.Resolve<EpisodeProvider>().RefreshEpisodeInfo(fakeSeries);
//Assert
updatedEpisodes.Should().OnlyContain(c => c.EpisodeFileId == 0);
}
[Test]
public void existing_episodes_remote_their_episodeId_file_id_when_season_number_doesnt_match_tvdbid()
{
const int seriesId = 71663;
var tvdbSeries = Builder<TvdbSeries>.CreateNew()
.With(c => c.Episodes = new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(5).Build())
).With(c => c.Id = seriesId).Build();
var fakeSeries = Builder<Series>.CreateNew().With(c => c.SeriesId = seriesId).Build();
var currentEpisodes = new List<Episode>();
foreach (var tvDbEpisode in tvdbSeries.Episodes)
{
currentEpisodes.Add(new Episode
{
TvDbEpisodeId = tvDbEpisode.Id,
EpisodeId = 99,
EpisodeFileId = 69,
Ignored = true,
Series = fakeSeries,
EpisodeNumber = tvDbEpisode.EpisodeNumber,
SeasonNumber = tvDbEpisode.SeasonNumber + 1
});
}
Mocker.GetMock<TvDbProvider>(MockBehavior.Strict)
.Setup(c => c.GetSeries(seriesId, true, false))
.Returns(tvdbSeries);
var updatedEpisodes = new List<Episode>();
Mocker.GetMock<IDatabase>()
.Setup(d => d.Fetch<Episode, Series, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
.Returns(currentEpisodes);
Mocker.GetMock<IDatabase>()
.Setup(c => c.UpdateMany(It.IsAny<IEnumerable<Episode>>()))
.Callback<IEnumerable<Episode>>(ep => updatedEpisodes = ep.ToList());
//Act
Mocker.Resolve<EpisodeProvider>().RefreshEpisodeInfo(fakeSeries);
//Assert
updatedEpisodes.Should().OnlyContain(c => c.EpisodeFileId == 0);
}
[Test]
public void RefreshEpisodeInfo_should_ignore_new_episode_for_ignored_season()
{

@ -322,6 +322,16 @@ namespace NzbDrone.Core.Providers
updateList.Add(episodeToUpdate);
}
if ((episodeToUpdate.EpisodeNumber != episode.EpisodeNumber ||
episodeToUpdate.SeasonNumber != episode.SeasonNumber) &&
episodeToUpdate.EpisodeFileId > 0)
{
logger.Info("Unlinking episode file because TheTVDB changed the epsiode number...");
_database.Delete<EpisodeFile>(episodeToUpdate.EpisodeFileId);
episodeToUpdate.EpisodeFileId = 0;
}
episodeToUpdate.SeriesId = series.SeriesId;
episodeToUpdate.TvDbEpisodeId = episode.Id;
episodeToUpdate.EpisodeNumber = episode.EpisodeNumber;

Loading…
Cancel
Save