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 AutoMoq;
|
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
using TvdbLib.Data;
|
|
|
|
|
|
2011-10-21 01:42:17 +02:00
|
|
|
|
namespace NzbDrone.Core.Test.ProviderTests
|
2011-09-30 06:40:00 +02:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
2011-11-13 08:27:16 +01:00
|
|
|
|
public class EpisodeProviderTest_DeleteInvalidEpisodes : CoreTest
|
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;
|
|
|
|
|
|
|
|
|
|
var tvDbSeries = Builder<TvdbSeries>.CreateNew().With(
|
|
|
|
|
c => c.Episodes =
|
|
|
|
|
new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
|
2011-10-18 23:46:06 +02:00
|
|
|
|
All()
|
|
|
|
|
.With(l => l.Language = new TvdbLanguage(0, "eng", "a"))
|
2011-09-30 06:40:00 +02:00
|
|
|
|
.Build())
|
|
|
|
|
).With(c => c.Id = seriesId).Build();
|
|
|
|
|
|
|
|
|
|
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 = tvDbSeries.Episodes.First().Id)
|
2011-09-30 06:40:00 +02:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
|
|
var db = MockLib.GetEmptyDatabase();
|
|
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
|
|
db.Insert(fakeSeries);
|
|
|
|
|
db.Insert(fakeEpisode);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
mocker.Resolve<EpisodeProvider>().DeleteInvalidEpisodes(fakeSeries, tvDbSeries);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
var result = db.Fetch<Episode>();
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
var tvDbSeries = Builder<TvdbSeries>.CreateNew().With(
|
|
|
|
|
c => c.Episodes =
|
|
|
|
|
new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
|
2011-10-18 23:46:06 +02:00
|
|
|
|
All()
|
|
|
|
|
.With(l => l.Language = new TvdbLanguage(0, "eng", "a"))
|
2011-09-30 06:40:00 +02:00
|
|
|
|
.Build())
|
|
|
|
|
).With(c => c.Id = seriesId).Build();
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
|
|
var db = MockLib.GetEmptyDatabase();
|
|
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
|
|
db.Insert(fakeSeries);
|
|
|
|
|
db.Insert(fakeEpisode);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
mocker.Resolve<EpisodeProvider>().DeleteInvalidEpisodes(fakeSeries, tvDbSeries);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
var tvDbSeries = Builder<TvdbSeries>.CreateNew().With(
|
|
|
|
|
c => c.Episodes =
|
|
|
|
|
new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
|
2011-10-18 23:46:06 +02:00
|
|
|
|
All()
|
|
|
|
|
.With(l => l.Language = new TvdbLanguage(0, "eng", "a"))
|
2011-09-30 06:40:00 +02:00
|
|
|
|
.Build())
|
|
|
|
|
).With(c => c.Id = seriesId).Build();
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
|
|
var db = MockLib.GetEmptyDatabase();
|
|
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
|
|
db.Insert(fakeSeries);
|
|
|
|
|
db.Insert(fakeEpisode);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
mocker.Resolve<EpisodeProvider>().DeleteInvalidEpisodes(fakeSeries, tvDbSeries);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
var tvDbSeries = Builder<TvdbSeries>.CreateNew().With(
|
|
|
|
|
c => c.Episodes =
|
|
|
|
|
new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
|
2011-10-18 23:46:06 +02:00
|
|
|
|
All()
|
|
|
|
|
.With(l => l.Language = new TvdbLanguage(0, "eng", "a"))
|
2011-09-30 06:40:00 +02:00
|
|
|
|
.Build())
|
|
|
|
|
).With(c => c.Id = seriesId).Build();
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
|
|
var db = MockLib.GetEmptyDatabase();
|
|
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
|
|
db.Insert(fakeSeries);
|
2011-09-30 18:32:57 +02:00
|
|
|
|
db.Insert(fakeEpisode);
|
2011-09-30 06:40:00 +02:00
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
mocker.Resolve<EpisodeProvider>().DeleteInvalidEpisodes(fakeSeries, tvDbSeries);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
var tvDbSeries = Builder<TvdbSeries>.CreateNew().With(
|
|
|
|
|
c => c.Episodes =
|
|
|
|
|
new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
|
2011-10-18 23:46:06 +02:00
|
|
|
|
All()
|
|
|
|
|
.With(l => l.Language = new TvdbLanguage(0, "eng", "a"))
|
2011-09-30 06:40:00 +02:00
|
|
|
|
.Build())
|
|
|
|
|
).With(c => c.Id = seriesId).Build();
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
|
|
var db = MockLib.GetEmptyDatabase();
|
|
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
|
|
db.Insert(fakeSeries);
|
|
|
|
|
db.Insert(fakeEpisode);
|
|
|
|
|
db.Insert(otherFakeSeries);
|
|
|
|
|
db.Insert(otherFakeEpisode);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
mocker.Resolve<EpisodeProvider>().DeleteInvalidEpisodes(fakeSeries, tvDbSeries);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
var result = db.Fetch<Episode>();
|
|
|
|
|
result.Should().HaveCount(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|