2013-08-01 02:02:36 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2013-09-11 06:33:47 +00:00
|
|
|
|
using System.Linq;
|
2013-08-04 05:45:46 +00:00
|
|
|
|
using FizzWare.NBuilder;
|
2013-08-01 02:02:36 +00:00
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<Episode> GetEpisodes()
|
|
|
|
|
{
|
|
|
|
|
return _gameOfThrones.Item2.JsonClone();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Series GetSeries()
|
|
|
|
|
{
|
2013-09-13 03:50:12 +00:00
|
|
|
|
var series = _gameOfThrones.Item1.JsonClone();
|
|
|
|
|
series.Seasons = new List<Season>();
|
|
|
|
|
|
|
|
|
|
return series;
|
2013-08-01 02:02:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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());
|
2013-08-04 05:45:46 +00:00
|
|
|
|
}
|
2013-08-01 02:02:36 +00:00
|
|
|
|
|
2013-09-11 06:33:47 +00:00
|
|
|
|
[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);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-04 05:45:46 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void should_update_tvdb_episode_id_when_it_changes()
|
|
|
|
|
{
|
|
|
|
|
var existingEpisode = Builder<Episode>
|
|
|
|
|
.CreateNew()
|
|
|
|
|
.With(e => e.TvDbEpisodeId = 55)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var newEpisode = Builder<Episode>
|
|
|
|
|
.CreateNew()
|
|
|
|
|
.With(e => e.TvDbEpisodeId = 99)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
existingEpisode.ShouldHave().AllPropertiesBut(e => e.TvDbEpisodeId).EqualTo(newEpisode);
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
|
|
|
|
.Returns(new List<Episode> { existingEpisode });
|
|
|
|
|
|
|
|
|
|
Subject.RefreshEpisodeInfo(GetSeries(), new List<Episode> { newEpisode });
|
|
|
|
|
|
|
|
|
|
_insertedEpisodes.Should().BeEmpty();
|
|
|
|
|
_updatedEpisodes.Should().Contain(e => e.TvDbEpisodeId == newEpisode.TvDbEpisodeId);
|
|
|
|
|
_deletedEpisodes.Should().BeEmpty();
|
2013-08-01 02:02:36 +00:00
|
|
|
|
}
|
2013-09-13 03:50:12 +00:00
|
|
|
|
|
|
|
|
|
[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);
|
|
|
|
|
}
|
2013-08-01 02:02:36 +00:00
|
|
|
|
}
|
|
|
|
|
} |