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