2011-09-30 04:40:00 +00:00
|
|
|
|
// ReSharper disable RedundantUsingDirective
|
2011-10-20 23:42:17 +00:00
|
|
|
|
|
2011-09-30 04:40:00 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using NUnit.Framework;
|
2013-02-19 06:01:03 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2011-09-30 04:40:00 +00:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2012-10-17 00:08:47 +00:00
|
|
|
|
using TvdbLib.Data;
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
2013-02-19 06:01:03 +00:00
|
|
|
|
namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests
|
2011-09-30 04:40:00 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
2013-02-02 20:54:03 +00:00
|
|
|
|
public class EpisodeProviderTest_DeleteInvalidEpisodes : SqlCeTest
|
2011-09-30 04:40:00 +00:00
|
|
|
|
{
|
|
|
|
|
[Test]
|
2011-09-30 16:32:57 +00:00
|
|
|
|
public void Delete_None_Valid_TvDbEpisodeId()
|
2011-09-30 04:40:00 +00:00
|
|
|
|
{
|
|
|
|
|
//Setup
|
|
|
|
|
const int seriesId = 71663;
|
|
|
|
|
const int episodeCount = 10;
|
|
|
|
|
|
2012-02-28 05:50:56 +00:00
|
|
|
|
var tvDbSeries = Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
|
2011-10-18 21:46:06 +00:00
|
|
|
|
All()
|
2012-10-17 00:08:47 +00:00
|
|
|
|
.With(l => l.Language = new TvdbLanguage(0, "eng", "a"))
|
2012-02-28 05:50:56 +00:00
|
|
|
|
.Build();
|
2013-01-19 23:55:58 +00:00
|
|
|
|
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
|
|
|
|
.With(c => c.SeriesId = seriesId)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateNew()
|
|
|
|
|
.With(e => e.SeriesId = seriesId)
|
2012-02-28 05:50:56 +00:00
|
|
|
|
.With(e => e.TvDbEpisodeId = tvDbSeries.First().Id)
|
2011-09-30 04:40:00 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-19 23:55:58 +00:00
|
|
|
|
WithRealDb();
|
|
|
|
|
|
|
|
|
|
Db.Insert(fakeSeries);
|
|
|
|
|
Db.Insert(fakeEpisode);
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 02:05:15 +00:00
|
|
|
|
Mocker.Resolve<EpisodeService>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries);
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2013-01-19 23:55:58 +00:00
|
|
|
|
var result = Db.Fetch<Episode>();
|
2011-09-30 04:40:00 +00:00
|
|
|
|
result.Should().HaveCount(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2011-09-30 16:32:57 +00:00
|
|
|
|
public void Delete_None_TvDbEpisodeId_is_zero()
|
2011-09-30 04:40:00 +00:00
|
|
|
|
{
|
|
|
|
|
//Setup
|
|
|
|
|
const int seriesId = 71663;
|
|
|
|
|
const int episodeCount = 10;
|
|
|
|
|
|
2012-02-28 05:50:56 +00:00
|
|
|
|
var tvDbSeries = Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
|
|
|
|
|
All()
|
2012-10-17 00:08:47 +00:00
|
|
|
|
.With(l => l.Language = new TvdbLanguage(0, "eng", "a"))
|
2012-02-28 05:50:56 +00:00
|
|
|
|
.Build();
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
|
|
|
|
.With(c => c.SeriesId = seriesId)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateNew()
|
|
|
|
|
.With(e => e.SeriesId = seriesId)
|
2011-09-30 16:32:57 +00:00
|
|
|
|
.With(e => e.TvDbEpisodeId = 0)
|
2011-09-30 04:40:00 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-19 23:55:58 +00:00
|
|
|
|
WithRealDb();
|
|
|
|
|
|
|
|
|
|
Db.Insert(fakeSeries);
|
|
|
|
|
Db.Insert(fakeEpisode);
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 02:05:15 +00:00
|
|
|
|
Mocker.Resolve<EpisodeService>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries);
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2013-01-19 23:55:58 +00:00
|
|
|
|
var result = Db.Fetch<Episode>();
|
2011-09-30 16:32:57 +00:00
|
|
|
|
result.Should().HaveCount(1);
|
2011-09-30 04:40:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2011-09-30 16:32:57 +00:00
|
|
|
|
public void Delete_None_TvDbEpisodeId_is_null()
|
2011-09-30 04:40:00 +00:00
|
|
|
|
{
|
|
|
|
|
//Setup
|
|
|
|
|
const int seriesId = 71663;
|
|
|
|
|
const int episodeCount = 10;
|
|
|
|
|
|
2012-02-28 05:50:56 +00:00
|
|
|
|
var tvDbSeries = Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
|
|
|
|
|
All()
|
2012-10-17 00:08:47 +00:00
|
|
|
|
.With(l => l.Language = new TvdbLanguage(0, "eng", "a"))
|
2012-02-28 05:50:56 +00:00
|
|
|
|
.Build();
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
|
|
|
|
.With(c => c.SeriesId = seriesId)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateNew()
|
|
|
|
|
.With(e => e.SeriesId = seriesId)
|
2011-09-30 16:32:57 +00:00
|
|
|
|
.With(e => e.TvDbEpisodeId = null)
|
2011-09-30 04:40:00 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
2013-01-19 23:55:58 +00:00
|
|
|
|
WithRealDb();
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
2013-01-19 23:55:58 +00:00
|
|
|
|
Db.Insert(fakeSeries);
|
|
|
|
|
Db.Insert(fakeEpisode);
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 02:05:15 +00:00
|
|
|
|
Mocker.Resolve<EpisodeService>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries);
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2013-01-19 23:55:58 +00:00
|
|
|
|
var result = Db.Fetch<Episode>();
|
2011-09-30 16:32:57 +00:00
|
|
|
|
result.Should().HaveCount(1);
|
2011-09-30 04:40:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2011-09-30 16:32:57 +00:00
|
|
|
|
public void Delete_TvDbId()
|
2011-09-30 04:40:00 +00:00
|
|
|
|
{
|
|
|
|
|
//Setup
|
|
|
|
|
const int seriesId = 71663;
|
|
|
|
|
const int episodeCount = 10;
|
|
|
|
|
|
2012-02-28 05:50:56 +00:00
|
|
|
|
var tvDbSeries = Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
|
|
|
|
|
All()
|
2012-10-17 00:08:47 +00:00
|
|
|
|
.With(l => l.Language = new TvdbLanguage(0, "eng", "a"))
|
2012-02-28 05:50:56 +00:00
|
|
|
|
.Build();
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
|
|
|
|
.With(c => c.SeriesId = seriesId)
|
|
|
|
|
.Build();
|
|
|
|
|
|
2011-09-30 16:32:57 +00:00
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateNew()
|
2011-09-30 04:40:00 +00:00
|
|
|
|
.With(e => e.SeriesId = seriesId)
|
2011-09-30 16:32:57 +00:00
|
|
|
|
.With(e => e.SeasonNumber = 20)
|
2011-09-30 04:40:00 +00:00
|
|
|
|
.With(e => e.EpisodeNumber = 20)
|
|
|
|
|
.With(e => e.TvDbEpisodeId = 300)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-19 23:55:58 +00:00
|
|
|
|
WithRealDb();
|
|
|
|
|
|
|
|
|
|
Db.Insert(fakeSeries);
|
|
|
|
|
Db.Insert(fakeEpisode);
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 02:05:15 +00:00
|
|
|
|
Mocker.Resolve<EpisodeService>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries);
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2013-01-19 23:55:58 +00:00
|
|
|
|
var result = Db.Fetch<Episode>();
|
2011-09-30 16:32:57 +00:00
|
|
|
|
result.Should().HaveCount(0);
|
2011-09-30 04:40:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Other series, by season/episode + by tvdbid
|
|
|
|
|
[Test]
|
|
|
|
|
public void Delete_TvDbId_multiple_series()
|
|
|
|
|
{
|
|
|
|
|
//Setup
|
|
|
|
|
const int seriesId = 71663;
|
|
|
|
|
const int episodeCount = 10;
|
|
|
|
|
|
2012-02-28 05:50:56 +00:00
|
|
|
|
var tvDbSeries = Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
|
|
|
|
|
All()
|
2012-10-17 00:08:47 +00:00
|
|
|
|
.With(l => l.Language = new TvdbLanguage(0, "eng", "a"))
|
2012-02-28 05:50:56 +00:00
|
|
|
|
.Build();
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
|
|
|
|
.With(c => c.SeriesId = seriesId)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var fakeEpisode = Builder<Episode>.CreateNew()
|
|
|
|
|
.With(e => e.SeriesId = seriesId)
|
|
|
|
|
.With(e => e.SeasonNumber = 20)
|
|
|
|
|
.With(e => e.EpisodeNumber = 20)
|
|
|
|
|
.With(e => e.TvDbEpisodeId = 300)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
//Other Series
|
|
|
|
|
var otherFakeSeries = Builder<Series>.CreateNew()
|
|
|
|
|
.With(c => c.SeriesId = 12345)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var otherFakeEpisode = Builder<Episode>.CreateNew()
|
|
|
|
|
.With(e => e.SeriesId = 12345)
|
|
|
|
|
.With(e => e.SeasonNumber = 20)
|
|
|
|
|
.With(e => e.EpisodeNumber = 20)
|
|
|
|
|
.With(e => e.TvDbEpisodeId = 300)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-19 23:55:58 +00:00
|
|
|
|
WithRealDb();
|
|
|
|
|
|
|
|
|
|
Db.Insert(fakeSeries);
|
|
|
|
|
Db.Insert(fakeEpisode);
|
|
|
|
|
Db.Insert(otherFakeSeries);
|
|
|
|
|
Db.Insert(otherFakeEpisode);
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
2013-02-20 02:05:15 +00:00
|
|
|
|
Mocker.Resolve<EpisodeService>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries);
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2013-01-19 23:55:58 +00:00
|
|
|
|
var result = Db.Fetch<Episode>();
|
2011-09-30 04:40:00 +00:00
|
|
|
|
result.Should().HaveCount(1);
|
|
|
|
|
}
|
2013-01-19 23:55:58 +00:00
|
|
|
|
|
2012-02-28 05:50:56 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_do_anything_if_episode_list_is_empty()
|
|
|
|
|
{
|
|
|
|
|
WithStrictMocker();
|
|
|
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
|
2013-02-20 02:05:15 +00:00
|
|
|
|
Mocker.Resolve<EpisodeService>().DeleteEpisodesNotInTvdb(fakeSeries, new List<TvdbEpisode>());
|
2012-02-28 05:50:56 +00:00
|
|
|
|
}
|
2011-09-30 04:40:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|