1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2026-04-25 22:46:31 -04:00
Files
Sonarr/src/NzbDrone.Core.Test/TvTests/RefreshEpisodeServiceFixture.cs
T
Mark McDowall 193672b652 Anime!
New: Anime support
New: pull alternate names from thexem.de
New: Search using all alternate names (if rage ID is unavailable)
New: Show scene mapping information when hovering over episode number
New: Full season searching for anime (searches for each episode)
New: animezb.com anime indexer
New: Treat BD as bluray

Fixed: Parsing of 2 digit absolute episode numbers
Fixed: Loading series details page for series that start with period
Fixed: Return 0 results when manual search fails, instead of an error
Fixed: animezb URL
2014-07-02 07:33:51 -07:00

191 lines
7.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.MetadataSource;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.TvTests
{
[TestFixture]
public class RefreshEpisodeServiceFixture : CoreTest<RefreshEpisodeService>
{
private List<Episode> _insertedEpisodes;
private List<Episode> _updatedEpisodes;
private List<Episode> _deletedEpisodes;
private Tuple<Series, List<Episode>> _gameOfThrones;
[TestFixtureSetUp]
public void TestFixture()
{
_gameOfThrones = Mocker.Resolve<TraktProxy>().GetSeriesInfo(121361);//Game of thrones
// Remove specials.
_gameOfThrones.Item2.RemoveAll(v => v.SeasonNumber == 0);
}
private List<Episode> GetEpisodes()
{
return _gameOfThrones.Item2.JsonClone();
}
private Series GetSeries()
{
var series = _gameOfThrones.Item1.JsonClone();
series.Seasons = new List<Season>();
return series;
}
[SetUp]
public void Setup()
{
_insertedEpisodes = new List<Episode>();
_updatedEpisodes = new List<Episode>();
_deletedEpisodes = new List<Episode>();
Mocker.GetMock<IEpisodeService>().Setup(c => c.InsertMany(It.IsAny<List<Episode>>()))
.Callback<List<Episode>>(e => _insertedEpisodes = e);
Mocker.GetMock<IEpisodeService>().Setup(c => c.UpdateMany(It.IsAny<List<Episode>>()))
.Callback<List<Episode>>(e => _updatedEpisodes = e);
Mocker.GetMock<IEpisodeService>().Setup(c => c.DeleteMany(It.IsAny<List<Episode>>()))
.Callback<List<Episode>>(e => _deletedEpisodes = e);
}
[Test]
public void should_create_all_when_no_existing_episodes()
{
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(new List<Episode>());
Subject.RefreshEpisodeInfo(GetSeries(), GetEpisodes());
_insertedEpisodes.Should().HaveSameCount(GetEpisodes());
_updatedEpisodes.Should().BeEmpty();
_deletedEpisodes.Should().BeEmpty();
}
[Test]
public void should_update_all_when_all_existing_episodes()
{
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(GetEpisodes());
Subject.RefreshEpisodeInfo(GetSeries(), GetEpisodes());
_insertedEpisodes.Should().BeEmpty();
_updatedEpisodes.Should().HaveSameCount(GetEpisodes());
_deletedEpisodes.Should().BeEmpty();
}
[Test]
public void should_delete_all_when_all_existing_episodes_are_gone_from_trakt()
{
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(GetEpisodes());
Subject.RefreshEpisodeInfo(GetSeries(), new List<Episode>());
_insertedEpisodes.Should().BeEmpty();
_updatedEpisodes.Should().BeEmpty();
_deletedEpisodes.Should().HaveSameCount(GetEpisodes());
}
[Test]
public void should_delete_duplicated_episodes_based_on_season_episode_number()
{
var duplicateEpisodes = GetEpisodes().Skip(5).Take(2).ToList();
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(GetEpisodes().Union(duplicateEpisodes).ToList());
Subject.RefreshEpisodeInfo(GetSeries(), GetEpisodes());
_insertedEpisodes.Should().BeEmpty();
_updatedEpisodes.Should().HaveSameCount(GetEpisodes());
_deletedEpisodes.Should().HaveSameCount(duplicateEpisodes);
}
[Test]
public void should_not_change_monitored_status_for_existing_episodes()
{
var series = GetSeries();
series.Seasons = new List<Season>();
series.Seasons.Add(new Season { SeasonNumber = 1, Monitored = false });
var episodes = GetEpisodes();
episodes.ForEach(e => e.Monitored = true);
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(episodes);
Subject.RefreshEpisodeInfo(series, GetEpisodes());
_updatedEpisodes.Should().HaveSameCount(GetEpisodes());
_updatedEpisodes.Should().OnlyContain(e => e.Monitored == true);
}
[Test]
public void should_remove_duplicate_remote_episodes_before_processing()
{
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(new List<Episode>());
var episodes = Builder<Episode>.CreateListOfSize(5)
.TheFirst(2)
.With(e => e.SeasonNumber = 1)
.With(e => e.EpisodeNumber = 1)
.Build()
.ToList();
Subject.RefreshEpisodeInfo(GetSeries(), episodes);
_insertedEpisodes.Should().HaveCount(episodes.Count - 1);
_updatedEpisodes.Should().BeEmpty();
_deletedEpisodes.Should().BeEmpty();
}
[Test]
public void should_not_set_absolute_episode_number_for_non_anime()
{
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(new List<Episode>());
Subject.RefreshEpisodeInfo(GetSeries(), GetEpisodes());
_insertedEpisodes.All(e => e.AbsoluteEpisodeNumber == 0).Should().BeTrue();
}
[Test]
[Ignore]
public void should_set_absolute_episode_number()
{
//TODO: Only run this against an anime series
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(new List<Episode>());
Subject.RefreshEpisodeInfo(GetSeries(), GetEpisodes());
var season1 = _insertedEpisodes.Where(e => e.SeasonNumber == 1 && e.EpisodeNumber > 0);
var season2episode1 = _insertedEpisodes.Single(e => e.SeasonNumber == 2 && e.EpisodeNumber == 1);
season2episode1.AbsoluteEpisodeNumber.Should().Be(season1.Count() + 1);
_insertedEpisodes.Where(e => e.SeasonNumber > 0 && e.EpisodeNumber > 0).All(e => e.AbsoluteEpisodeNumber > 0).Should().BeTrue();
_updatedEpisodes.Should().BeEmpty();
_deletedEpisodes.Should().BeEmpty();
}
}
}