2011-06-18 08:29:38 +00:00
|
|
|
|
using System;
|
2011-05-22 16:53:21 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using AutoMoq;
|
|
|
|
|
using FizzWare.NBuilder;
|
2011-06-02 21:06:46 +00:00
|
|
|
|
using FluentAssertions;
|
2011-05-22 16:53:21 +00:00
|
|
|
|
using Moq;
|
2011-06-02 21:06:46 +00:00
|
|
|
|
using NUnit.Framework;
|
2011-05-22 16:53:21 +00:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2011-06-15 02:31:41 +00:00
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
2011-05-22 16:53:21 +00:00
|
|
|
|
using NzbDrone.Core.Repository;
|
2011-06-18 04:39:02 +00:00
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
2011-05-19 03:55:35 +00:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-05-22 16:53:21 +00:00
|
|
|
|
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
|
namespace NzbDrone.Core.Test
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class SeriesProviderTest : TestBase
|
|
|
|
|
{
|
2011-06-15 02:31:41 +00:00
|
|
|
|
[TestCase(true)]
|
|
|
|
|
[TestCase(false)]
|
|
|
|
|
public void Add_new_series(bool useSeasonFolder)
|
2011-05-22 16:53:21 +00:00
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
2011-06-16 06:33:01 +00:00
|
|
|
|
|
2011-06-15 02:31:41 +00:00
|
|
|
|
mocker.GetMock<ConfigProvider>()
|
|
|
|
|
.Setup(c => c.UseSeasonFolder).Returns(useSeasonFolder);
|
2011-06-16 06:33:01 +00:00
|
|
|
|
|
2011-06-20 07:13:17 +00:00
|
|
|
|
var db = MockLib.GetEmptyDatabase();
|
|
|
|
|
mocker.SetConstant(db);
|
2011-06-14 05:52:12 +00:00
|
|
|
|
|
2011-06-20 07:13:17 +00:00
|
|
|
|
var fakeProfiles = Builder<QualityProfile>.CreateListOfSize(2).Build();
|
2011-06-14 05:52:12 +00:00
|
|
|
|
|
2011-06-20 07:13:17 +00:00
|
|
|
|
db.InsertMany(fakeProfiles);
|
|
|
|
|
|
2011-05-22 16:53:21 +00:00
|
|
|
|
const string path = "C:\\Test\\";
|
|
|
|
|
const int tvDbId = 1234;
|
|
|
|
|
const int qualityProfileId = 2;
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var seriesProvider = mocker.Resolve<SeriesProvider>();
|
|
|
|
|
seriesProvider.AddSeries(path, tvDbId, qualityProfileId);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
var series = seriesProvider.GetAllSeries();
|
2011-06-02 21:06:46 +00:00
|
|
|
|
series.Should().HaveCount(1);
|
2011-05-22 16:53:21 +00:00
|
|
|
|
Assert.AreEqual(path, series.First().Path);
|
|
|
|
|
Assert.AreEqual(tvDbId, series.First().SeriesId);
|
|
|
|
|
Assert.AreEqual(qualityProfileId, series.First().QualityProfileId);
|
2011-06-15 02:31:41 +00:00
|
|
|
|
series.First().SeasonFolder.Should().Be(useSeasonFolder);
|
2011-05-22 16:53:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void find_series_empty_repo()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
2011-06-18 01:46:22 +00:00
|
|
|
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
2011-05-22 16:53:21 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var seriesProvider = mocker.Resolve<SeriesProvider>();
|
|
|
|
|
var series = seriesProvider.FindSeries("My Title");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
Assert.IsNull(series);
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-18 03:36:22 +00:00
|
|
|
|
[Test]
|
2011-06-19 05:56:52 +00:00
|
|
|
|
[ExpectedException(typeof(InvalidOperationException), ExpectedMessage = "Sequence contains no elements")]
|
2011-06-18 03:36:22 +00:00
|
|
|
|
public void Get_series_invalid_series_id_should_return_null()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var seriesProvider = mocker.Resolve<SeriesProvider>();
|
|
|
|
|
var series = seriesProvider.GetSeries(2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
Assert.IsNull(series);
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-18 04:39:02 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void Get_series_by_id()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
var db = MockLib.GetEmptyDatabase();
|
|
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
2011-06-18 08:29:38 +00:00
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
|
|
|
|
.With(c => c.QualityProfileId = 1)
|
2011-06-20 07:40:45 +00:00
|
|
|
|
.With(c => c.EpisodeCount = 0)
|
|
|
|
|
.With(c => c.EpisodeFileCount = 0)
|
|
|
|
|
.With(c => c.SeasonCount = 0)
|
2011-06-18 08:29:38 +00:00
|
|
|
|
.Build();
|
2011-06-18 04:39:02 +00:00
|
|
|
|
var fakeQuality = Builder<QualityProfile>.CreateNew().Build();
|
|
|
|
|
|
2011-06-18 08:29:38 +00:00
|
|
|
|
db.Insert(fakeSeries);
|
2011-06-18 04:39:02 +00:00
|
|
|
|
db.Insert(fakeQuality);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
mocker.Resolve<QualityProvider>();
|
|
|
|
|
var series = mocker.Resolve<SeriesProvider>().GetSeries(1);
|
|
|
|
|
|
|
|
|
|
//Assert
|
2011-06-18 08:29:38 +00:00
|
|
|
|
series.ShouldHave().AllPropertiesBut(s => s.QualityProfile, s => s.SeriesId).EqualTo(fakeSeries);
|
2011-06-18 04:39:02 +00:00
|
|
|
|
series.QualityProfile.Should().NotBeNull();
|
2011-06-18 08:29:38 +00:00
|
|
|
|
series.QualityProfile.ShouldHave().Properties(q => q.Name, q => q.SonicAllowed, q => q.Cutoff, q => q.SonicAllowed).EqualTo(fakeQuality);
|
2011-06-20 06:28:42 +00:00
|
|
|
|
|
2011-06-18 04:39:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-18 07:17:47 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void Find_series_by_cleanName_mapped()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
var db = MockLib.GetEmptyDatabase();
|
|
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
|
|
|
|
.With(c => c.QualityProfileId = 1)
|
|
|
|
|
.With(c => c.CleanTitle = "laworder")
|
|
|
|
|
.Build();
|
|
|
|
|
var fakeQuality = Builder<QualityProfile>.CreateNew().Build();
|
|
|
|
|
|
|
|
|
|
var id = db.Insert(fakeSeries);
|
|
|
|
|
db.Insert(fakeQuality);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
mocker.Resolve<QualityProvider>();
|
|
|
|
|
mocker.GetMock<SceneMappingProvider>().Setup(s => s.GetSeriesId("laworder")).Returns(1);
|
|
|
|
|
|
|
|
|
|
var series = mocker.Resolve<SeriesProvider>().FindSeries("laworder");
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
series.ShouldHave().AllPropertiesBut(s => s.QualityProfile, s => s.SeriesId);
|
|
|
|
|
series.QualityProfile.Should().NotBeNull();
|
|
|
|
|
series.QualityProfile.ShouldHave().Properties(q => q.Name, q => q.SonicAllowed, q => q.Cutoff, q => q.AllowedString);
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-22 16:53:21 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void find_series_empty_match()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
2011-06-18 01:46:22 +00:00
|
|
|
|
var emptyRepository = MockLib.GetEmptyDatabase();
|
2011-05-22 16:53:21 +00:00
|
|
|
|
mocker.SetConstant(emptyRepository);
|
2011-06-18 01:46:22 +00:00
|
|
|
|
emptyRepository.Insert(MockLib.GetFakeSeries(1, "MyTitle"));
|
2011-05-22 16:53:21 +00:00
|
|
|
|
//Act
|
|
|
|
|
var seriesProvider = mocker.Resolve<SeriesProvider>();
|
|
|
|
|
var series = seriesProvider.FindSeries("WrongTitle");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
Assert.IsNull(series);
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-15 02:31:41 +00:00
|
|
|
|
[TestCase("The Test", "Test")]
|
|
|
|
|
[TestCase("Through the Wormhole", "Through.the.Wormhole")]
|
2011-05-22 16:53:21 +00:00
|
|
|
|
public void find_series_match(string title, string searchTitle)
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
2011-06-15 02:31:41 +00:00
|
|
|
|
var emptyRepository = MockLib.GetEmptyDatabase();
|
2011-05-22 16:53:21 +00:00
|
|
|
|
mocker.SetConstant(emptyRepository);
|
2011-06-15 02:31:41 +00:00
|
|
|
|
emptyRepository.Insert(MockLib.GetFakeSeries(1, title));
|
2011-06-18 07:17:47 +00:00
|
|
|
|
emptyRepository.Insert(Builder<QualityProfile>.CreateNew().Build());
|
|
|
|
|
mocker.Resolve<QualityProvider>();
|
|
|
|
|
|
2011-05-22 16:53:21 +00:00
|
|
|
|
//Act
|
|
|
|
|
var seriesProvider = mocker.Resolve<SeriesProvider>();
|
|
|
|
|
var series = seriesProvider.FindSeries(searchTitle);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
Assert.IsNotNull(series);
|
|
|
|
|
Assert.AreEqual(title, series.Title);
|
2011-06-18 07:17:47 +00:00
|
|
|
|
series.QualityProfile.Should().NotBeNull();
|
|
|
|
|
series.QualityProfile.ShouldHave().Properties(q => q.Name, q => q.SonicAllowed, q => q.Cutoff, q => q.AllowedString);
|
2011-05-22 16:53:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void is_monitored()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
2011-06-16 06:33:01 +00:00
|
|
|
|
var db = MockLib.GetEmptyDatabase();
|
|
|
|
|
mocker.SetConstant(db);
|
2011-05-22 16:53:21 +00:00
|
|
|
|
|
2011-06-16 06:33:01 +00:00
|
|
|
|
mocker.SetConstant(db);
|
2011-05-22 16:53:21 +00:00
|
|
|
|
|
2011-06-16 06:33:01 +00:00
|
|
|
|
db.Insert(Builder<Series>.CreateNew()
|
2011-05-22 16:53:21 +00:00
|
|
|
|
.With(c => c.Monitored = true)
|
|
|
|
|
.With(c => c.SeriesId = 12)
|
|
|
|
|
.Build());
|
|
|
|
|
|
2011-06-17 02:48:24 +00:00
|
|
|
|
db.Insert(Builder<Series>.CreateNew()
|
|
|
|
|
.With(c => c.Monitored = false)
|
|
|
|
|
.With(c => c.SeriesId = 11)
|
|
|
|
|
.Build());
|
2011-05-22 16:53:21 +00:00
|
|
|
|
|
2011-06-20 07:13:17 +00:00
|
|
|
|
db.InsertMany(Builder<QualityProfile>.CreateListOfSize(3).Build());
|
2011-05-22 16:53:21 +00:00
|
|
|
|
|
|
|
|
|
//Act, Assert
|
|
|
|
|
var provider = mocker.Resolve<SeriesProvider>();
|
2011-06-23 06:56:17 +00:00
|
|
|
|
provider.IsMonitored(12).Should().BeTrue();
|
2011-05-22 16:53:21 +00:00
|
|
|
|
Assert.IsFalse(provider.IsMonitored(11));
|
|
|
|
|
Assert.IsFalse(provider.IsMonitored(1));
|
|
|
|
|
}
|
2011-06-20 07:13:17 +00:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Get_Series_With_Count()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
var db = MockLib.GetEmptyDatabase();
|
|
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
|
|
var fakeQuality = Builder<QualityProfile>.CreateNew().Build();
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().With(e => e.QualityProfileId = fakeQuality.QualityProfileId).Build();
|
2011-07-10 02:45:31 +00:00
|
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(10)
|
|
|
|
|
.WhereAll().Have(e => e.SeriesId = fakeSeries.SeriesId)
|
|
|
|
|
.Have(e => e.Ignored = false)
|
|
|
|
|
.Have(e => e.AirDate = DateTime.Today)
|
|
|
|
|
.WhereTheFirst(5)
|
|
|
|
|
.Have(e => e.EpisodeFileId = 0)
|
|
|
|
|
.WhereTheLast(2)
|
|
|
|
|
.Have(e => e.AirDate = DateTime.Today.AddDays(1))
|
|
|
|
|
.Build();
|
2011-06-20 07:13:17 +00:00
|
|
|
|
|
|
|
|
|
db.Insert(fakeSeries);
|
|
|
|
|
db.Insert(fakeQuality);
|
|
|
|
|
db.InsertMany(fakeEpisodes);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
mocker.Resolve<QualityProvider>();
|
2011-06-23 18:37:17 +00:00
|
|
|
|
var series = mocker.Resolve<SeriesProvider>().GetAllSeriesWithEpisodeCount();
|
2011-06-20 07:13:17 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
series.Should().HaveCount(1);
|
2011-07-10 02:45:31 +00:00
|
|
|
|
Assert.AreEqual(8, series[0].EpisodeCount);
|
|
|
|
|
Assert.AreEqual(3, series[0].EpisodeFileCount);
|
2011-06-20 07:13:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Get_Series_With_Count_AllIgnored()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
var db = MockLib.GetEmptyDatabase();
|
|
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
|
|
var fakeQuality = Builder<QualityProfile>.CreateNew().Build();
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().With(e => e.QualityProfileId = fakeQuality.QualityProfileId).Build();
|
|
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(10).WhereAll().Have(e => e.SeriesId = fakeSeries.SeriesId).Have(e => e.Ignored = true).WhereRandom(5).Have(e => e.EpisodeFileId = 0).Build();
|
|
|
|
|
|
|
|
|
|
db.Insert(fakeSeries);
|
|
|
|
|
db.Insert(fakeQuality);
|
|
|
|
|
db.InsertMany(fakeEpisodes);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
mocker.Resolve<QualityProvider>();
|
2011-06-23 18:37:17 +00:00
|
|
|
|
var series = mocker.Resolve<SeriesProvider>().GetAllSeriesWithEpisodeCount();
|
2011-06-20 07:13:17 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
series.Should().HaveCount(1);
|
|
|
|
|
Assert.AreEqual(0, series[0].EpisodeCount);
|
|
|
|
|
Assert.AreEqual(0, series[0].EpisodeFileCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Get_Series_With_Count_AllDownloaded()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
var db = MockLib.GetEmptyDatabase();
|
|
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
|
|
var fakeQuality = Builder<QualityProfile>.CreateNew().Build();
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().With(e => e.QualityProfileId = fakeQuality.QualityProfileId).Build();
|
2011-07-10 02:58:36 +00:00
|
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(10)
|
|
|
|
|
.WhereAll()
|
|
|
|
|
.Have(e => e.SeriesId = fakeSeries.SeriesId)
|
|
|
|
|
.Have(e => e.Ignored = false)
|
|
|
|
|
.Have(e => e.AirDate = DateTime.Today.AddDays(-1))
|
|
|
|
|
.Build();
|
2011-06-20 07:13:17 +00:00
|
|
|
|
|
|
|
|
|
db.Insert(fakeSeries);
|
|
|
|
|
db.Insert(fakeQuality);
|
|
|
|
|
db.InsertMany(fakeEpisodes);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
mocker.Resolve<QualityProvider>();
|
2011-06-23 18:37:17 +00:00
|
|
|
|
var series = mocker.Resolve<SeriesProvider>().GetAllSeriesWithEpisodeCount();
|
2011-06-20 07:13:17 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
series.Should().HaveCount(1);
|
|
|
|
|
Assert.AreEqual(10, series[0].EpisodeCount);
|
|
|
|
|
Assert.AreEqual(10, series[0].EpisodeFileCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Get_Series_With_Count_Half_Ignored()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
var db = MockLib.GetEmptyDatabase();
|
|
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
|
|
var fakeQuality = Builder<QualityProfile>.CreateNew().Build();
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().With(e => e.QualityProfileId = fakeQuality.QualityProfileId).Build();
|
|
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(10)
|
2011-07-10 02:58:36 +00:00
|
|
|
|
.WhereAll()
|
|
|
|
|
.Have(e => e.SeriesId = fakeSeries.SeriesId)
|
|
|
|
|
.Have(e => e.AirDate = DateTime.Today.AddDays(-1))
|
|
|
|
|
.WhereTheFirst(5)
|
|
|
|
|
.Have(e => e.Ignored = false)
|
|
|
|
|
.WhereTheLast(5)
|
|
|
|
|
.Have(e => e.Ignored = true)
|
2011-06-20 07:13:17 +00:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
db.Insert(fakeSeries);
|
|
|
|
|
db.Insert(fakeQuality);
|
|
|
|
|
db.InsertMany(fakeEpisodes);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
mocker.Resolve<QualityProvider>();
|
2011-06-23 18:37:17 +00:00
|
|
|
|
var series = mocker.Resolve<SeriesProvider>().GetAllSeriesWithEpisodeCount();
|
2011-06-20 07:13:17 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
series.Should().HaveCount(1);
|
|
|
|
|
Assert.AreEqual(5, series[0].EpisodeCount);
|
|
|
|
|
Assert.AreEqual(5, series[0].EpisodeFileCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Get_Single_Series()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
var db = MockLib.GetEmptyDatabase();
|
|
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
|
|
var fakeQuality = Builder<QualityProfile>.CreateNew().Build();
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
|
|
|
|
.With(e => e.QualityProfileId = fakeQuality.QualityProfileId)
|
|
|
|
|
.With(e => e.SeriesId = 1)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
db.Insert(fakeSeries);
|
|
|
|
|
db.Insert(fakeQuality);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
mocker.Resolve<QualityProvider>();
|
|
|
|
|
var series = mocker.Resolve<SeriesProvider>().GetSeries(1);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
series.QualityProfile.Should().NotBeNull();
|
|
|
|
|
series.QualityProfileId.Should().Be(fakeQuality.QualityProfileId);
|
|
|
|
|
}
|
2011-05-22 16:53:21 +00:00
|
|
|
|
}
|
2011-04-22 22:24:05 +00:00
|
|
|
|
} |