2011-06-18 11:29:38 +03:00
|
|
|
using System;
|
2011-05-22 19:53:21 +03:00
|
|
|
using System.Linq;
|
2011-11-14 03:22:18 +03:00
|
|
|
|
2011-05-22 19:53:21 +03:00
|
|
|
using FizzWare.NBuilder;
|
2011-06-03 00:06:46 +03:00
|
|
|
using FluentAssertions;
|
2011-05-22 19:53:21 +03:00
|
|
|
using Moq;
|
2011-06-03 00:06:46 +03:00
|
|
|
using NUnit.Framework;
|
2011-05-22 19:53:21 +03:00
|
|
|
using NzbDrone.Core.Providers;
|
2011-06-15 05:31:41 +03:00
|
|
|
using NzbDrone.Core.Providers.Core;
|
2011-05-22 19:53:21 +03:00
|
|
|
using NzbDrone.Core.Repository;
|
2011-06-18 07:39:02 +03:00
|
|
|
using NzbDrone.Core.Repository.Quality;
|
2011-05-19 06:55:35 +03:00
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-11-14 03:22:18 +03:00
|
|
|
using NzbDrone.Test.Common.AutoMoq;
|
2011-05-22 19:53:21 +03:00
|
|
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
2011-10-21 02:42:17 +03:00
|
|
|
namespace NzbDrone.Core.Test.ProviderTests
|
2011-05-22 19:53:21 +03:00
|
|
|
{
|
|
|
|
[TestFixture]
|
2011-11-13 10:27:16 +03:00
|
|
|
public class SeriesProviderTest : CoreTest
|
2011-05-22 19:53:21 +03:00
|
|
|
{
|
2011-06-15 05:31:41 +03:00
|
|
|
[TestCase(true)]
|
|
|
|
[TestCase(false)]
|
|
|
|
public void Add_new_series(bool useSeasonFolder)
|
2011-05-22 19:53:21 +03:00
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer();
|
2011-06-16 09:33:01 +03:00
|
|
|
|
2011-06-15 05:31:41 +03:00
|
|
|
mocker.GetMock<ConfigProvider>()
|
|
|
|
.Setup(c => c.UseSeasonFolder).Returns(useSeasonFolder);
|
2011-06-16 09:33:01 +03:00
|
|
|
|
2011-11-23 08:58:26 +03:00
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
2011-06-20 10:13:17 +03:00
|
|
|
mocker.SetConstant(db);
|
2011-06-14 08:52:12 +03:00
|
|
|
|
2011-06-20 10:13:17 +03:00
|
|
|
var fakeProfiles = Builder<QualityProfile>.CreateListOfSize(2).Build();
|
2011-06-14 08:52:12 +03:00
|
|
|
|
2011-06-20 10:13:17 +03:00
|
|
|
db.InsertMany(fakeProfiles);
|
2011-10-19 00:46:06 +03:00
|
|
|
|
2011-05-22 19:53:21 +03: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-03 00:06:46 +03:00
|
|
|
series.Should().HaveCount(1);
|
2011-05-22 19:53:21 +03:00
|
|
|
Assert.AreEqual(path, series.First().Path);
|
|
|
|
Assert.AreEqual(tvDbId, series.First().SeriesId);
|
|
|
|
Assert.AreEqual(qualityProfileId, series.First().QualityProfileId);
|
2011-06-15 05:31:41 +03:00
|
|
|
series.First().SeasonFolder.Should().Be(useSeasonFolder);
|
2011-05-22 19:53:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void find_series_empty_repo()
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer();
|
2011-11-23 08:58:26 +03:00
|
|
|
mocker.SetConstant(TestDbHelper.GetEmptyDatabase());
|
2011-05-22 19:53:21 +03:00
|
|
|
|
|
|
|
//Act
|
|
|
|
var seriesProvider = mocker.Resolve<SeriesProvider>();
|
|
|
|
var series = seriesProvider.FindSeries("My Title");
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
Assert.IsNull(series);
|
|
|
|
}
|
|
|
|
|
2011-06-18 06:36:22 +03:00
|
|
|
[Test]
|
2011-06-19 08:56:52 +03:00
|
|
|
[ExpectedException(typeof(InvalidOperationException), ExpectedMessage = "Sequence contains no elements")]
|
2011-06-18 06:36:22 +03:00
|
|
|
public void Get_series_invalid_series_id_should_return_null()
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer();
|
2011-11-23 08:58:26 +03:00
|
|
|
mocker.SetConstant(TestDbHelper.GetEmptyDatabase());
|
2011-06-18 06:36:22 +03:00
|
|
|
|
|
|
|
//Act
|
|
|
|
var seriesProvider = mocker.Resolve<SeriesProvider>();
|
|
|
|
var series = seriesProvider.GetSeries(2);
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
Assert.IsNull(series);
|
|
|
|
}
|
|
|
|
|
2011-06-18 07:39:02 +03:00
|
|
|
[Test]
|
|
|
|
public void Get_series_by_id()
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
2011-11-23 08:58:26 +03:00
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
2011-06-18 07:39:02 +03:00
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
2011-06-18 11:29:38 +03:00
|
|
|
var fakeSeries = Builder<Series>.CreateNew()
|
|
|
|
.With(c => c.QualityProfileId = 1)
|
2011-06-20 10:40:45 +03:00
|
|
|
.With(c => c.EpisodeCount = 0)
|
|
|
|
.With(c => c.EpisodeFileCount = 0)
|
|
|
|
.With(c => c.SeasonCount = 0)
|
2011-06-18 11:29:38 +03:00
|
|
|
.Build();
|
2011-06-18 07:39:02 +03:00
|
|
|
var fakeQuality = Builder<QualityProfile>.CreateNew().Build();
|
|
|
|
|
2011-06-18 11:29:38 +03:00
|
|
|
db.Insert(fakeSeries);
|
2011-06-18 07:39:02 +03:00
|
|
|
db.Insert(fakeQuality);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
mocker.Resolve<QualityProvider>();
|
|
|
|
var series = mocker.Resolve<SeriesProvider>().GetSeries(1);
|
|
|
|
|
|
|
|
//Assert
|
2011-09-28 20:56:30 +03:00
|
|
|
series.ShouldHave().AllPropertiesBut(s => s.QualityProfile, s => s.SeriesId, s => s.NextAiring).EqualTo(fakeSeries);
|
2011-06-18 07:39:02 +03:00
|
|
|
series.QualityProfile.Should().NotBeNull();
|
2011-06-18 11:29:38 +03:00
|
|
|
series.QualityProfile.ShouldHave().Properties(q => q.Name, q => q.SonicAllowed, q => q.Cutoff, q => q.SonicAllowed).EqualTo(fakeQuality);
|
2011-06-20 09:28:42 +03:00
|
|
|
|
2011-06-18 07:39:02 +03:00
|
|
|
}
|
|
|
|
|
2011-06-18 10:17:47 +03:00
|
|
|
[Test]
|
|
|
|
public void Find_series_by_cleanName_mapped()
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
2011-11-23 08:58:26 +03:00
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
2011-06-18 10:17:47 +03:00
|
|
|
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 19:53:21 +03:00
|
|
|
[Test]
|
|
|
|
public void find_series_empty_match()
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer();
|
2011-11-23 08:58:26 +03:00
|
|
|
var emptyRepository = TestDbHelper.GetEmptyDatabase();
|
2011-05-22 19:53:21 +03:00
|
|
|
mocker.SetConstant(emptyRepository);
|
2011-11-23 08:58:26 +03:00
|
|
|
emptyRepository.Insert(TestDbHelper.GetFakeSeries(1, "MyTitle"));
|
2011-05-22 19:53:21 +03:00
|
|
|
//Act
|
|
|
|
var seriesProvider = mocker.Resolve<SeriesProvider>();
|
|
|
|
var series = seriesProvider.FindSeries("WrongTitle");
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
Assert.IsNull(series);
|
|
|
|
}
|
|
|
|
|
2011-06-15 05:31:41 +03:00
|
|
|
[TestCase("The Test", "Test")]
|
|
|
|
[TestCase("Through the Wormhole", "Through.the.Wormhole")]
|
2011-05-22 19:53:21 +03:00
|
|
|
public void find_series_match(string title, string searchTitle)
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer();
|
2011-11-23 08:58:26 +03:00
|
|
|
var emptyRepository = TestDbHelper.GetEmptyDatabase();
|
2011-05-22 19:53:21 +03:00
|
|
|
mocker.SetConstant(emptyRepository);
|
2011-11-23 08:58:26 +03:00
|
|
|
emptyRepository.Insert(TestDbHelper.GetFakeSeries(1, title));
|
2011-06-18 10:17:47 +03:00
|
|
|
emptyRepository.Insert(Builder<QualityProfile>.CreateNew().Build());
|
|
|
|
mocker.Resolve<QualityProvider>();
|
|
|
|
|
2011-05-22 19:53:21 +03:00
|
|
|
//Act
|
|
|
|
var seriesProvider = mocker.Resolve<SeriesProvider>();
|
|
|
|
var series = seriesProvider.FindSeries(searchTitle);
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
Assert.IsNotNull(series);
|
|
|
|
Assert.AreEqual(title, series.Title);
|
2011-06-18 10:17:47 +03:00
|
|
|
series.QualityProfile.Should().NotBeNull();
|
|
|
|
series.QualityProfile.ShouldHave().Properties(q => q.Name, q => q.SonicAllowed, q => q.Cutoff, q => q.AllowedString);
|
2011-05-22 19:53:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void is_monitored()
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
2011-11-23 08:58:26 +03:00
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
2011-06-16 09:33:01 +03:00
|
|
|
mocker.SetConstant(db);
|
2011-05-22 19:53:21 +03:00
|
|
|
|
2011-06-16 09:33:01 +03:00
|
|
|
mocker.SetConstant(db);
|
2011-05-22 19:53:21 +03:00
|
|
|
|
2011-06-16 09:33:01 +03:00
|
|
|
db.Insert(Builder<Series>.CreateNew()
|
2011-05-22 19:53:21 +03:00
|
|
|
.With(c => c.Monitored = true)
|
|
|
|
.With(c => c.SeriesId = 12)
|
|
|
|
.Build());
|
|
|
|
|
2011-06-17 05:48:24 +03:00
|
|
|
db.Insert(Builder<Series>.CreateNew()
|
|
|
|
.With(c => c.Monitored = false)
|
|
|
|
.With(c => c.SeriesId = 11)
|
|
|
|
.Build());
|
2011-05-22 19:53:21 +03:00
|
|
|
|
2011-06-20 10:13:17 +03:00
|
|
|
db.InsertMany(Builder<QualityProfile>.CreateListOfSize(3).Build());
|
2011-05-22 19:53:21 +03:00
|
|
|
|
|
|
|
//Act, Assert
|
|
|
|
var provider = mocker.Resolve<SeriesProvider>();
|
2011-06-23 09:56:17 +03:00
|
|
|
provider.IsMonitored(12).Should().BeTrue();
|
2011-05-22 19:53:21 +03:00
|
|
|
Assert.IsFalse(provider.IsMonitored(11));
|
|
|
|
Assert.IsFalse(provider.IsMonitored(1));
|
|
|
|
}
|
2011-06-20 10:13:17 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Get_Series_With_Count()
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
2011-11-23 08:58:26 +03:00
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
2011-06-20 10:13:17 +03:00
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
var fakeQuality = Builder<QualityProfile>.CreateNew().Build();
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().With(e => e.QualityProfileId = fakeQuality.QualityProfileId).Build();
|
2011-07-10 05:45:31 +03:00
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(10)
|
2011-10-19 00:46:06 +03:00
|
|
|
.All().With(e => e.SeriesId = fakeSeries.SeriesId)
|
|
|
|
.With(e => e.Ignored = false)
|
|
|
|
.With(e => e.AirDate = DateTime.Today)
|
|
|
|
.TheFirst(5)
|
|
|
|
.With(e => e.EpisodeFileId = 0)
|
2011-10-23 08:39:14 +03:00
|
|
|
.TheLast(2)
|
2011-10-19 00:46:06 +03:00
|
|
|
.With(e => e.AirDate = DateTime.Today.AddDays(1))
|
2011-07-10 05:45:31 +03:00
|
|
|
.Build();
|
2011-06-20 10:13:17 +03:00
|
|
|
|
|
|
|
db.Insert(fakeSeries);
|
|
|
|
db.Insert(fakeQuality);
|
|
|
|
db.InsertMany(fakeEpisodes);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
mocker.Resolve<QualityProvider>();
|
2011-06-23 21:37:17 +03:00
|
|
|
var series = mocker.Resolve<SeriesProvider>().GetAllSeriesWithEpisodeCount();
|
2011-06-20 10:13:17 +03:00
|
|
|
|
|
|
|
//Assert
|
|
|
|
series.Should().HaveCount(1);
|
2011-07-10 05:45:31 +03:00
|
|
|
Assert.AreEqual(8, series[0].EpisodeCount);
|
|
|
|
Assert.AreEqual(3, series[0].EpisodeFileCount);
|
2011-06-20 10:13:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Get_Series_With_Count_AllIgnored()
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
2011-11-23 08:58:26 +03:00
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
2011-06-20 10:13:17 +03:00
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
var fakeQuality = Builder<QualityProfile>.CreateNew().Build();
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().With(e => e.QualityProfileId = fakeQuality.QualityProfileId).Build();
|
2011-10-23 08:39:14 +03:00
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(10).All().With(e => e.SeriesId = fakeSeries.SeriesId).With(e => e.Ignored = true).Random(5).With(e => e.EpisodeFileId = 0).Build();
|
2011-06-20 10:13:17 +03:00
|
|
|
|
|
|
|
db.Insert(fakeSeries);
|
|
|
|
db.Insert(fakeQuality);
|
|
|
|
db.InsertMany(fakeEpisodes);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
mocker.Resolve<QualityProvider>();
|
2011-06-23 21:37:17 +03:00
|
|
|
var series = mocker.Resolve<SeriesProvider>().GetAllSeriesWithEpisodeCount();
|
2011-06-20 10:13:17 +03: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);
|
2011-11-23 08:58:26 +03:00
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
2011-06-20 10:13:17 +03:00
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
var fakeQuality = Builder<QualityProfile>.CreateNew().Build();
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().With(e => e.QualityProfileId = fakeQuality.QualityProfileId).Build();
|
2011-07-10 05:58:36 +03:00
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(10)
|
2011-10-19 00:46:06 +03:00
|
|
|
.All()
|
|
|
|
.With(e => e.SeriesId = fakeSeries.SeriesId)
|
|
|
|
.With(e => e.Ignored = false)
|
|
|
|
.With(e => e.AirDate = DateTime.Today.AddDays(-1))
|
2011-07-10 05:58:36 +03:00
|
|
|
.Build();
|
2011-06-20 10:13:17 +03:00
|
|
|
|
|
|
|
db.Insert(fakeSeries);
|
|
|
|
db.Insert(fakeQuality);
|
|
|
|
db.InsertMany(fakeEpisodes);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
mocker.Resolve<QualityProvider>();
|
2011-06-23 21:37:17 +03:00
|
|
|
var series = mocker.Resolve<SeriesProvider>().GetAllSeriesWithEpisodeCount();
|
2011-06-20 10:13:17 +03: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);
|
2011-11-23 08:58:26 +03:00
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
2011-06-20 10:13:17 +03:00
|
|
|
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-10-19 00:46:06 +03:00
|
|
|
.All()
|
|
|
|
.With(e => e.SeriesId = fakeSeries.SeriesId)
|
|
|
|
.With(e => e.AirDate = DateTime.Today.AddDays(-1))
|
|
|
|
.TheFirst(5)
|
|
|
|
.With(e => e.Ignored = false)
|
2011-10-23 08:39:14 +03:00
|
|
|
.TheLast(5)
|
2011-10-19 00:46:06 +03:00
|
|
|
.With(e => e.Ignored = true)
|
2011-06-20 10:13:17 +03:00
|
|
|
.Build();
|
|
|
|
|
|
|
|
db.Insert(fakeSeries);
|
|
|
|
db.Insert(fakeQuality);
|
|
|
|
db.InsertMany(fakeEpisodes);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
mocker.Resolve<QualityProvider>();
|
2011-06-23 21:37:17 +03:00
|
|
|
var series = mocker.Resolve<SeriesProvider>().GetAllSeriesWithEpisodeCount();
|
2011-06-20 10:13:17 +03: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);
|
2011-11-23 08:58:26 +03:00
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
2011-06-20 10:13:17 +03:00
|
|
|
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-07-29 04:03:24 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void SeriesPathExists_exact_match()
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
2011-11-23 08:58:26 +03:00
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
2011-07-29 04:03:24 +03:00
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
var path = @"C:\Test\TV\30 Rock";
|
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
2011-10-19 00:46:06 +03:00
|
|
|
.All()
|
|
|
|
.With(c => c.QualityProfileId = 1)
|
|
|
|
.TheFirst(1)
|
|
|
|
.With(c => c.Path = path)
|
2011-07-29 04:03:24 +03:00
|
|
|
.Build();
|
|
|
|
var fakeQuality = Builder<QualityProfile>.CreateNew().Build();
|
|
|
|
|
|
|
|
db.InsertMany(fakeSeries);
|
|
|
|
db.Insert(fakeQuality);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
mocker.Resolve<QualityProvider>();
|
|
|
|
//mocker.GetMock<IDatabase>().Setup(s => s.Fetch<Series, QualityProfile>(It.IsAny<string>())).Returns(
|
2011-10-19 00:46:06 +03:00
|
|
|
//fakeSeries.ToList());
|
2011-07-29 04:03:24 +03:00
|
|
|
|
|
|
|
var result = mocker.Resolve<SeriesProvider>().SeriesPathExists(path);
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().BeTrue();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void SeriesPathExists_match()
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
2011-11-23 08:58:26 +03:00
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
2011-07-29 04:03:24 +03:00
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
var path = @"C:\Test\TV\30 Rock";
|
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
2011-10-19 00:46:06 +03:00
|
|
|
.All()
|
|
|
|
.With(c => c.QualityProfileId = 1)
|
|
|
|
.TheFirst(1)
|
|
|
|
.With(c => c.Path = path)
|
2011-07-29 04:03:24 +03:00
|
|
|
.Build();
|
|
|
|
var fakeQuality = Builder<QualityProfile>.CreateNew().Build();
|
|
|
|
|
|
|
|
db.InsertMany(fakeSeries);
|
|
|
|
db.Insert(fakeQuality);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
mocker.Resolve<QualityProvider>();
|
|
|
|
//mocker.GetMock<IDatabase>().Setup(s => s.Fetch<Series, QualityProfile>(It.IsAny<string>())).Returns(
|
|
|
|
//fakeSeries.ToList());
|
|
|
|
|
|
|
|
var result = mocker.Resolve<SeriesProvider>().SeriesPathExists(path.ToUpper());
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().BeTrue();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void SeriesPathExists_match_alt()
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
2011-11-23 08:58:26 +03:00
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
2011-07-29 04:03:24 +03:00
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
var path = @"C:\Test\TV\The Simpsons";
|
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
2011-10-19 00:46:06 +03:00
|
|
|
.All()
|
|
|
|
.With(c => c.QualityProfileId = 1)
|
|
|
|
.TheFirst(1)
|
|
|
|
.With(c => c.Path = path)
|
2011-07-29 04:03:24 +03:00
|
|
|
.Build();
|
|
|
|
var fakeQuality = Builder<QualityProfile>.CreateNew().Build();
|
|
|
|
|
|
|
|
db.InsertMany(fakeSeries);
|
|
|
|
db.Insert(fakeQuality);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
mocker.Resolve<QualityProvider>();
|
|
|
|
//mocker.GetMock<IDatabase>().Setup(s => s.Fetch<Series, QualityProfile>(It.IsAny<string>())).Returns(
|
|
|
|
//fakeSeries.ToList());
|
|
|
|
|
|
|
|
var result = mocker.Resolve<SeriesProvider>().SeriesPathExists(@"c:\Test\Tv\the sIMpsons");
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().BeTrue();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void SeriesPathExists_match_false()
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
2011-11-23 08:58:26 +03:00
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
2011-07-29 04:03:24 +03:00
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
var path = @"C:\Test\TV\30 Rock";
|
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
2011-10-19 00:46:06 +03:00
|
|
|
.All()
|
|
|
|
.With(c => c.QualityProfileId = 1)
|
|
|
|
.TheFirst(1)
|
|
|
|
.With(c => c.Path = path)
|
2011-07-29 04:03:24 +03:00
|
|
|
.Build();
|
|
|
|
var fakeQuality = Builder<QualityProfile>.CreateNew().Build();
|
|
|
|
|
|
|
|
db.InsertMany(fakeSeries);
|
|
|
|
db.Insert(fakeQuality);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
mocker.Resolve<QualityProvider>();
|
|
|
|
//mocker.GetMock<IDatabase>().Setup(s => s.Fetch<Series, QualityProfile>(It.IsAny<string>())).Returns(
|
|
|
|
//fakeSeries.ToList());
|
|
|
|
|
|
|
|
var result = mocker.Resolve<SeriesProvider>().SeriesPathExists(@"C:\Test\TV\Not A match");
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().BeFalse();
|
|
|
|
}
|
2011-09-28 20:56:30 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Get_Series_NextAiring_Today()
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
2011-11-23 08:58:26 +03:00
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
2011-09-28 20:56:30 +03:00
|
|
|
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(2)
|
2011-10-19 00:46:06 +03:00
|
|
|
.All()
|
|
|
|
.With(e => e.SeriesId = fakeSeries.SeriesId)
|
|
|
|
.With(e => e.Ignored = false)
|
|
|
|
.With(e => e.AirDate = DateTime.Today.AddDays(1))
|
|
|
|
.TheFirst(1)
|
|
|
|
.With(e => e.AirDate = DateTime.Today)
|
2011-09-28 20:56:30 +03:00
|
|
|
.Build();
|
|
|
|
|
|
|
|
db.Insert(fakeSeries);
|
|
|
|
db.Insert(fakeQuality);
|
|
|
|
db.InsertMany(fakeEpisodes);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
mocker.Resolve<QualityProvider>();
|
|
|
|
var series = mocker.Resolve<SeriesProvider>().GetAllSeriesWithEpisodeCount();
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
series.Should().HaveCount(1);
|
|
|
|
series[0].NextAiring.Should().Be(DateTime.Today);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Get_Series_NextAiring_Tomorrow_Last_Aired_Yesterday()
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
2011-11-23 08:58:26 +03:00
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
2011-09-28 20:56:30 +03:00
|
|
|
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(2)
|
2011-10-19 00:46:06 +03:00
|
|
|
.All()
|
|
|
|
.With(e => e.SeriesId = fakeSeries.SeriesId)
|
|
|
|
.With(e => e.Ignored = false)
|
|
|
|
.With(e => e.AirDate = DateTime.Today.AddDays(1))
|
|
|
|
.TheFirst(1)
|
|
|
|
.With(e => e.AirDate = DateTime.Today.AddDays(-1))
|
2011-09-28 20:56:30 +03:00
|
|
|
.Build();
|
|
|
|
|
|
|
|
db.Insert(fakeSeries);
|
|
|
|
db.Insert(fakeQuality);
|
|
|
|
db.InsertMany(fakeEpisodes);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
mocker.Resolve<QualityProvider>();
|
|
|
|
var series = mocker.Resolve<SeriesProvider>().GetAllSeriesWithEpisodeCount();
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
series.Should().HaveCount(1);
|
|
|
|
series[0].NextAiring.Should().Be(DateTime.Today.AddDays(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Get_Series_NextAiring_Unknown()
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
2011-11-23 08:58:26 +03:00
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
2011-09-28 20:56:30 +03:00
|
|
|
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(2)
|
2011-10-19 00:46:06 +03:00
|
|
|
.All()
|
|
|
|
.With(e => e.SeriesId = fakeSeries.SeriesId)
|
|
|
|
.With(e => e.AirDate = null)
|
|
|
|
.With(e => e.Ignored = false)
|
2011-09-28 20:56:30 +03:00
|
|
|
.Build();
|
|
|
|
|
|
|
|
db.Insert(fakeSeries);
|
|
|
|
db.Insert(fakeQuality);
|
|
|
|
db.InsertMany(fakeEpisodes);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
mocker.Resolve<QualityProvider>();
|
|
|
|
var series = mocker.Resolve<SeriesProvider>().GetAllSeriesWithEpisodeCount();
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
series.Should().HaveCount(1);
|
|
|
|
series[0].NextAiring.Should().NotHaveValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Get_Series_NextAiring_1_month()
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
2011-11-23 08:58:26 +03:00
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
2011-09-28 20:56:30 +03:00
|
|
|
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(2)
|
2011-10-19 00:46:06 +03:00
|
|
|
.All()
|
|
|
|
.With(e => e.SeriesId = fakeSeries.SeriesId)
|
|
|
|
.With(e => e.Ignored = false)
|
|
|
|
.With(e => e.AirDate = DateTime.Today.AddMonths(1))
|
|
|
|
.TheFirst(1)
|
|
|
|
.With(e => e.AirDate = DateTime.Today.AddDays(-1))
|
2011-09-28 20:56:30 +03:00
|
|
|
.Build();
|
|
|
|
|
|
|
|
db.Insert(fakeSeries);
|
|
|
|
db.Insert(fakeQuality);
|
|
|
|
db.InsertMany(fakeEpisodes);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
mocker.Resolve<QualityProvider>();
|
|
|
|
var series = mocker.Resolve<SeriesProvider>().GetAllSeriesWithEpisodeCount();
|
|
|
|
|
2011-10-04 02:38:22 +03:00
|
|
|
//Assert
|
|
|
|
series.Should().HaveCount(1);
|
|
|
|
series[0].NextAiring.Should().Be(DateTime.Today.AddMonths(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Get_Series_NextAiring_skip_ignored()
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
2011-11-23 08:58:26 +03:00
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
2011-10-04 02:38:22 +03:00
|
|
|
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(2)
|
2011-10-19 00:46:06 +03:00
|
|
|
.All()
|
|
|
|
.With(e => e.SeriesId = fakeSeries.SeriesId)
|
|
|
|
.With(e => e.AirDate = DateTime.Today.AddMonths(1))
|
|
|
|
.With(e => e.Ignored = false)
|
|
|
|
.TheFirst(1)
|
|
|
|
.With(e => e.AirDate = DateTime.Today.AddDays(1))
|
|
|
|
.With(e => e.Ignored = true)
|
2011-10-04 02:38:22 +03:00
|
|
|
.Build();
|
|
|
|
|
|
|
|
db.Insert(fakeSeries);
|
|
|
|
db.Insert(fakeQuality);
|
|
|
|
db.InsertMany(fakeEpisodes);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
mocker.Resolve<QualityProvider>();
|
|
|
|
var series = mocker.Resolve<SeriesProvider>().GetAllSeriesWithEpisodeCount();
|
|
|
|
|
2011-09-28 20:56:30 +03:00
|
|
|
//Assert
|
|
|
|
series.Should().HaveCount(1);
|
|
|
|
series[0].NextAiring.Should().Be(DateTime.Today.AddMonths(1));
|
|
|
|
}
|
2011-10-21 02:36:47 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void SearchForSeries_should_return_results_that_start_with_query()
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
2011-11-23 08:58:26 +03:00
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
2011-10-21 02:36:47 +03:00
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
var fakeQuality = Builder<QualityProfile>.CreateNew().Build();
|
|
|
|
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
2011-10-23 08:39:14 +03:00
|
|
|
.All()
|
|
|
|
.With(e => e.QualityProfileId = fakeQuality.QualityProfileId)
|
2011-10-21 02:36:47 +03:00
|
|
|
.Build();
|
|
|
|
|
|
|
|
db.InsertMany(fakeSeries);
|
|
|
|
db.Insert(fakeQuality);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
var series = mocker.Resolve<SeriesProvider>().SearchForSeries("Titl");
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
series.Should().HaveCount(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2011-10-21 09:06:36 +03:00
|
|
|
public void SearchForSeries_should_return_results_that_contain_the_query()
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
2011-11-23 08:58:26 +03:00
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
2011-10-21 09:06:36 +03:00
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
var fakeQuality = Builder<QualityProfile>.CreateNew().Build();
|
|
|
|
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
2011-10-23 08:39:14 +03:00
|
|
|
.All()
|
|
|
|
.With(e => e.QualityProfileId = fakeQuality.QualityProfileId)
|
2011-10-21 09:06:36 +03:00
|
|
|
.Build();
|
|
|
|
|
|
|
|
db.InsertMany(fakeSeries);
|
|
|
|
db.Insert(fakeQuality);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
var series = mocker.Resolve<SeriesProvider>().SearchForSeries("itl");
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
series.Should().HaveCount(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void SearchForSeries_should_return_results_that_end_with_the_query()
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
2011-11-23 08:58:26 +03:00
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
2011-10-21 09:06:36 +03:00
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
var fakeQuality = Builder<QualityProfile>.CreateNew().Build();
|
|
|
|
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
2011-10-23 08:39:14 +03:00
|
|
|
.All()
|
|
|
|
.With(e => e.QualityProfileId = fakeQuality.QualityProfileId)
|
2011-10-21 09:06:36 +03:00
|
|
|
.Build();
|
|
|
|
|
|
|
|
db.InsertMany(fakeSeries);
|
|
|
|
db.Insert(fakeQuality);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
var series = mocker.Resolve<SeriesProvider>().SearchForSeries("2");
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
series.Should().HaveCount(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void SearchForSeries_should_not_return_results_that_do_not_contain_the_query()
|
2011-10-21 02:36:47 +03:00
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
2011-11-23 08:58:26 +03:00
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
2011-10-21 02:36:47 +03:00
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
var fakeQuality = Builder<QualityProfile>.CreateNew().Build();
|
|
|
|
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
2011-10-23 08:39:14 +03:00
|
|
|
.All()
|
|
|
|
.With(e => e.QualityProfileId = fakeQuality.QualityProfileId)
|
2011-10-21 02:36:47 +03:00
|
|
|
.Build();
|
|
|
|
|
|
|
|
db.InsertMany(fakeSeries);
|
|
|
|
db.Insert(fakeQuality);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
var series = mocker.Resolve<SeriesProvider>().SearchForSeries("NotATitle");
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
series.Should().HaveCount(0);
|
|
|
|
}
|
2011-12-08 11:44:22 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void SearchForSeries_should_return_results_when_query_has_special_characters()
|
|
|
|
{
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
var db = TestDbHelper.GetEmptyDatabase();
|
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
var fakeQuality = Builder<QualityProfile>.CreateNew().Build();
|
|
|
|
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
|
|
|
.All()
|
|
|
|
.With(e => e.QualityProfileId = fakeQuality.QualityProfileId)
|
|
|
|
.TheLast(1)
|
|
|
|
.With(s => s.Title = "It's Always Sunny")
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
db.InsertMany(fakeSeries);
|
|
|
|
db.Insert(fakeQuality);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
var series = mocker.Resolve<SeriesProvider>().SearchForSeries("it's");
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
series.Should().HaveCount(1);
|
|
|
|
}
|
2011-05-22 19:53:21 +03:00
|
|
|
}
|
2011-04-23 01:24:05 +03:00
|
|
|
} |