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;
|
2011-11-14 00:22:18 +00:00
|
|
|
|
|
2011-09-30 04:40:00 +00:00
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-11-14 00:22:18 +00:00
|
|
|
|
using NzbDrone.Test.Common.AutoMoq;
|
2012-10-13 03:49:59 +00:00
|
|
|
|
using XemLib.Data;
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
2011-10-20 23:42:17 +00:00
|
|
|
|
namespace NzbDrone.Core.Test.ProviderTests
|
2011-09-30 04:40:00 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
2011-11-13 07:27:16 +00:00
|
|
|
|
public class EpisodeProviderTest_DeleteInvalidEpisodes : CoreTest
|
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-13 03:49:59 +00:00
|
|
|
|
.With(l => l.Language = "en")
|
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)
|
2012-02-28 05:50:56 +00:00
|
|
|
|
.With(e => e.TvDbEpisodeId = tvDbSeries.First().Id)
|
2011-09-30 04:40:00 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
2011-11-23 05:58:26 +00:00
|
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
2011-12-15 04:15:53 +00:00
|
|
|
|
Mocker.SetConstant(db);
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
db.Insert(fakeSeries);
|
|
|
|
|
db.Insert(fakeEpisode);
|
|
|
|
|
|
|
|
|
|
//Act
|
2011-12-15 04:15:53 +00:00
|
|
|
|
Mocker.Resolve<EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries);
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
var result = db.Fetch<Episode>();
|
|
|
|
|
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-13 03:49:59 +00:00
|
|
|
|
.With(l => l.Language = "en")
|
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();
|
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
2011-11-23 05:58:26 +00:00
|
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
2011-12-15 04:15:53 +00:00
|
|
|
|
Mocker.SetConstant(db);
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
db.Insert(fakeSeries);
|
|
|
|
|
db.Insert(fakeEpisode);
|
|
|
|
|
|
|
|
|
|
//Act
|
2011-12-15 04:15:53 +00:00
|
|
|
|
Mocker.Resolve<EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries);
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
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-13 03:49:59 +00:00
|
|
|
|
.With(l => l.Language = "en")
|
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();
|
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
2011-11-23 05:58:26 +00:00
|
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
2011-12-15 04:15:53 +00:00
|
|
|
|
Mocker.SetConstant(db);
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
db.Insert(fakeSeries);
|
|
|
|
|
db.Insert(fakeEpisode);
|
|
|
|
|
|
|
|
|
|
//Act
|
2011-12-15 04:15:53 +00:00
|
|
|
|
Mocker.Resolve<EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries);
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
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-13 03:49:59 +00:00
|
|
|
|
.With(l => l.Language = "en")
|
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();
|
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
2011-11-23 05:58:26 +00:00
|
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
2011-12-15 04:15:53 +00:00
|
|
|
|
Mocker.SetConstant(db);
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
db.Insert(fakeSeries);
|
2011-09-30 16:32:57 +00:00
|
|
|
|
db.Insert(fakeEpisode);
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
2011-12-15 04:15:53 +00:00
|
|
|
|
Mocker.Resolve<EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries);
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
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-13 03:49:59 +00:00
|
|
|
|
.With(l => l.Language = "en")
|
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();
|
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
2011-11-23 05:58:26 +00:00
|
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
2011-12-15 04:15:53 +00:00
|
|
|
|
Mocker.SetConstant(db);
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
db.Insert(fakeSeries);
|
|
|
|
|
db.Insert(fakeEpisode);
|
|
|
|
|
db.Insert(otherFakeSeries);
|
|
|
|
|
db.Insert(otherFakeEpisode);
|
|
|
|
|
|
|
|
|
|
//Act
|
2011-12-15 04:15:53 +00:00
|
|
|
|
Mocker.Resolve<EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, tvDbSeries);
|
2011-09-30 04:40:00 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
var result = db.Fetch<Episode>();
|
|
|
|
|
result.Should().HaveCount(1);
|
|
|
|
|
}
|
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();
|
|
|
|
|
|
|
|
|
|
Mocker.Resolve<EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, new List<TvdbEpisode>());
|
|
|
|
|
}
|
2011-09-30 04:40:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|