|
|
|
@ -6,6 +6,7 @@ using FluentAssertions;
|
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using NzbDrone.Core.MetadataSource;
|
|
|
|
|
using NzbDrone.Core.MetadataSource.Tvdb;
|
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
using NzbDrone.Test.Common;
|
|
|
|
@ -42,6 +43,15 @@ namespace NzbDrone.Core.Test.TvTests
|
|
|
|
|
return series;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Series GetAnimeSeries()
|
|
|
|
|
{
|
|
|
|
|
var series = Builder<Series>.CreateNew().Build();
|
|
|
|
|
series.SeriesType = SeriesTypes.Anime;
|
|
|
|
|
series.Seasons = new List<Season>();
|
|
|
|
|
|
|
|
|
|
return series;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
|
|
|
@ -61,6 +71,13 @@ namespace NzbDrone.Core.Test.TvTests
|
|
|
|
|
.Callback<List<Episode>>(e => _deletedEpisodes = e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GivenAnimeEpisodes(List<Episode> episodes)
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<ITvdbProxy>()
|
|
|
|
|
.Setup(s => s.GetEpisodeInfo(It.IsAny<Int32>()))
|
|
|
|
|
.Returns(episodes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_create_all_when_no_existing_episodes()
|
|
|
|
|
{
|
|
|
|
@ -168,24 +185,102 @@ namespace NzbDrone.Core.Test.TvTests
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
[Ignore]
|
|
|
|
|
public void should_set_absolute_episode_number()
|
|
|
|
|
public void should_set_absolute_episode_number_for_anime()
|
|
|
|
|
{
|
|
|
|
|
//TODO: Only run this against an anime series
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(3).Build().ToList();
|
|
|
|
|
GivenAnimeEpisodes(episodes);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
|
|
|
|
.Returns(new List<Episode>());
|
|
|
|
|
|
|
|
|
|
Subject.RefreshEpisodeInfo(GetSeries(), GetEpisodes());
|
|
|
|
|
Subject.RefreshEpisodeInfo(GetAnimeSeries(), episodes);
|
|
|
|
|
|
|
|
|
|
_insertedEpisodes.All(e => e.AbsoluteEpisodeNumber > 0).Should().BeTrue();
|
|
|
|
|
_updatedEpisodes.Should().BeEmpty();
|
|
|
|
|
_deletedEpisodes.Should().BeEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var season1 = _insertedEpisodes.Where(e => e.SeasonNumber == 1 && e.EpisodeNumber > 0);
|
|
|
|
|
var season2episode1 = _insertedEpisodes.Single(e => e.SeasonNumber == 2 && e.EpisodeNumber == 1);
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_set_absolute_episode_number_even_if_not_previously_set_for_anime()
|
|
|
|
|
{
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(3).Build().ToList();
|
|
|
|
|
GivenAnimeEpisodes(episodes);
|
|
|
|
|
|
|
|
|
|
season2episode1.AbsoluteEpisodeNumber.Should().Be(season1.Count() + 1);
|
|
|
|
|
var existingEpisodes = episodes.JsonClone();
|
|
|
|
|
existingEpisodes.ForEach(e => e.AbsoluteEpisodeNumber = 0);
|
|
|
|
|
|
|
|
|
|
_insertedEpisodes.Where(e => e.SeasonNumber > 0 && e.EpisodeNumber > 0).All(e => e.AbsoluteEpisodeNumber > 0).Should().BeTrue();
|
|
|
|
|
_updatedEpisodes.Should().BeEmpty();
|
|
|
|
|
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
|
|
|
|
.Returns(existingEpisodes);
|
|
|
|
|
|
|
|
|
|
Subject.RefreshEpisodeInfo(GetAnimeSeries(), episodes);
|
|
|
|
|
|
|
|
|
|
_insertedEpisodes.Should().BeEmpty();
|
|
|
|
|
_updatedEpisodes.All(e => e.AbsoluteEpisodeNumber > 0).Should().BeTrue();
|
|
|
|
|
_deletedEpisodes.Should().BeEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_get_new_season_and_episode_numbers_when_absolute_episode_number_match_found()
|
|
|
|
|
{
|
|
|
|
|
const Int32 expectedSeasonNumber = 10;
|
|
|
|
|
const Int32 expectedEpisodeNumber = 5;
|
|
|
|
|
const Int32 expectedAbsoluteNumber = 3;
|
|
|
|
|
|
|
|
|
|
var episode = Builder<Episode>.CreateNew()
|
|
|
|
|
.With(e => e.SeasonNumber = expectedSeasonNumber)
|
|
|
|
|
.With(e => e.EpisodeNumber = expectedEpisodeNumber)
|
|
|
|
|
.With(e => e.AbsoluteEpisodeNumber = expectedAbsoluteNumber)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
GivenAnimeEpisodes(new List<Episode> { episode });
|
|
|
|
|
|
|
|
|
|
var existingEpisode = episode.JsonClone();
|
|
|
|
|
existingEpisode.SeasonNumber = 1;
|
|
|
|
|
existingEpisode.EpisodeNumber = 1;
|
|
|
|
|
existingEpisode.AbsoluteEpisodeNumber = 1;
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
|
|
|
|
.Returns(new List<Episode>{ existingEpisode });
|
|
|
|
|
|
|
|
|
|
Subject.RefreshEpisodeInfo(GetAnimeSeries(), new List<Episode> { episode });
|
|
|
|
|
|
|
|
|
|
_insertedEpisodes.Should().BeEmpty();
|
|
|
|
|
_deletedEpisodes.Should().BeEmpty();
|
|
|
|
|
|
|
|
|
|
_updatedEpisodes.First().SeasonNumber.Should().Be(expectedSeasonNumber);
|
|
|
|
|
_updatedEpisodes.First().EpisodeNumber.Should().Be(expectedEpisodeNumber);
|
|
|
|
|
_updatedEpisodes.First().AbsoluteEpisodeNumber.Should().Be(expectedAbsoluteNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_prefer_absolute_match_over_season_and_epsiode_match()
|
|
|
|
|
{
|
|
|
|
|
var episodes = Builder<Episode>.CreateListOfSize(2)
|
|
|
|
|
.Build()
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
episodes[0].AbsoluteEpisodeNumber = 0;
|
|
|
|
|
episodes[0].SeasonNumber.Should().NotBe(episodes[1].SeasonNumber);
|
|
|
|
|
episodes[0].EpisodeNumber.Should().NotBe(episodes[1].EpisodeNumber);
|
|
|
|
|
episodes[0].AbsoluteEpisodeNumber.Should().NotBe(episodes[1].AbsoluteEpisodeNumber);
|
|
|
|
|
|
|
|
|
|
GivenAnimeEpisodes(episodes);
|
|
|
|
|
|
|
|
|
|
var existingEpisode = new Episode
|
|
|
|
|
{
|
|
|
|
|
SeasonNumber = episodes[0].SeasonNumber,
|
|
|
|
|
EpisodeNumber = episodes[0].EpisodeNumber,
|
|
|
|
|
AbsoluteEpisodeNumber = episodes[1].AbsoluteEpisodeNumber
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
|
|
|
|
.Returns(new List<Episode> { existingEpisode });
|
|
|
|
|
|
|
|
|
|
Subject.RefreshEpisodeInfo(GetAnimeSeries(), episodes);
|
|
|
|
|
|
|
|
|
|
_updatedEpisodes.First().SeasonNumber.Should().Be(episodes[1].SeasonNumber);
|
|
|
|
|
_updatedEpisodes.First().EpisodeNumber.Should().Be(episodes[1].EpisodeNumber);
|
|
|
|
|
_updatedEpisodes.First().AbsoluteEpisodeNumber.Should().Be(episodes[1].AbsoluteEpisodeNumber);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|