2011-05-22 18:53:21 +02:00
|
|
|
|
// ReSharper disable RedundantUsingDirective
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using AutoMoq;
|
|
|
|
|
using FizzWare.NBuilder;
|
2011-06-02 23:06:46 +02:00
|
|
|
|
using FluentAssertions;
|
2011-05-22 18:53:21 +02:00
|
|
|
|
using Moq;
|
2011-06-02 23:06:46 +02:00
|
|
|
|
using NUnit.Framework;
|
2011-05-22 18:53:21 +02:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2011-06-15 04:31:41 +02:00
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
2011-05-22 18:53:21 +02:00
|
|
|
|
using NzbDrone.Core.Repository;
|
2011-05-19 05:55:35 +02:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-06-18 04:00:44 +02:00
|
|
|
|
using PetaPoco;
|
2011-05-22 18:53:21 +02:00
|
|
|
|
using TvdbLib.Data;
|
|
|
|
|
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2011-05-19 05:55:35 +02:00
|
|
|
|
// ReSharper disable InconsistentNaming
|
2011-05-22 18:53:21 +02:00
|
|
|
|
public class SeriesProviderTest : TestBase
|
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void Map_path_to_series()
|
|
|
|
|
{
|
|
|
|
|
//Arrange
|
|
|
|
|
var fakeSeries = Builder<TvdbSeries>.CreateNew()
|
|
|
|
|
.With(f => f.SeriesName = "The Simpsons")
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var fakeSearch = Builder<TvdbSearchResult>.CreateNew()
|
|
|
|
|
.With(s => s.Id = fakeSeries.Id)
|
|
|
|
|
.With(s => s.SeriesName = fakeSeries.SeriesName)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
2011-06-18 04:00:44 +02:00
|
|
|
|
mocker.GetMock<IDatabase>()
|
|
|
|
|
.Setup(f => f.Exists<Series>(It.IsAny<String>()))
|
2011-05-22 18:53:21 +02:00
|
|
|
|
.Returns(false);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<TvDbProvider>()
|
|
|
|
|
.Setup(f => f.GetSeries(It.IsAny<String>()))
|
|
|
|
|
.Returns(fakeSearch);
|
|
|
|
|
mocker.GetMock<TvDbProvider>()
|
|
|
|
|
.Setup(f => f.GetSeries(fakeSeries.Id, false))
|
|
|
|
|
.Returns(fakeSeries)
|
|
|
|
|
.Verifiable();
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
|
|
|
|
|
var mappedSeries = mocker.Resolve<SeriesProvider>().MapPathToSeries(@"D:\TV Shows\The Simpsons");
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
mocker.GetMock<TvDbProvider>().VerifyAll();
|
|
|
|
|
Assert.AreEqual(fakeSeries, mappedSeries);
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-15 04:31:41 +02:00
|
|
|
|
[TestCase(true)]
|
|
|
|
|
[TestCase(false)]
|
|
|
|
|
public void Add_new_series(bool useSeasonFolder)
|
2011-05-22 18:53:21 +02:00
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
2011-06-16 08:33:01 +02:00
|
|
|
|
|
2011-06-15 04:31:41 +02:00
|
|
|
|
mocker.GetMock<ConfigProvider>()
|
|
|
|
|
.Setup(c => c.UseSeasonFolder).Returns(useSeasonFolder);
|
2011-06-16 08:33:01 +02:00
|
|
|
|
|
2011-06-15 04:31:41 +02:00
|
|
|
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
2011-05-22 18:53:21 +02:00
|
|
|
|
|
|
|
|
|
|
2011-06-14 07:52:12 +02:00
|
|
|
|
|
|
|
|
|
|
2011-05-22 18:53:21 +02: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);
|
|
|
|
|
|
|
|
|
|
|
2011-06-15 04:31:41 +02:00
|
|
|
|
|
2011-05-22 18:53:21 +02:00
|
|
|
|
//Assert
|
|
|
|
|
var series = seriesProvider.GetAllSeries();
|
2011-06-02 23:06:46 +02:00
|
|
|
|
series.Should().HaveCount(1);
|
2011-05-22 18:53:21 +02:00
|
|
|
|
Assert.AreEqual(path, series.First().Path);
|
|
|
|
|
Assert.AreEqual(tvDbId, series.First().SeriesId);
|
|
|
|
|
Assert.AreEqual(qualityProfileId, series.First().QualityProfileId);
|
2011-06-15 04:31:41 +02:00
|
|
|
|
series.First().SeasonFolder.Should().Be(useSeasonFolder);
|
2011-05-22 18:53:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void find_series_empty_repo()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
2011-06-18 03:46:22 +02:00
|
|
|
|
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
2011-05-22 18:53:21 +02:00
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var seriesProvider = mocker.Resolve<SeriesProvider>();
|
|
|
|
|
var series = seriesProvider.FindSeries("My Title");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
Assert.IsNull(series);
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-18 05:36:22 +02:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
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-05-22 18:53:21 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void find_series_empty_match()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
2011-06-18 03:46:22 +02:00
|
|
|
|
var emptyRepository = MockLib.GetEmptyDatabase();
|
2011-05-22 18:53:21 +02:00
|
|
|
|
mocker.SetConstant(emptyRepository);
|
2011-06-18 03:46:22 +02:00
|
|
|
|
emptyRepository.Insert(MockLib.GetFakeSeries(1, "MyTitle"));
|
2011-05-22 18:53:21 +02:00
|
|
|
|
//Act
|
|
|
|
|
var seriesProvider = mocker.Resolve<SeriesProvider>();
|
|
|
|
|
var series = seriesProvider.FindSeries("WrongTitle");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
Assert.IsNull(series);
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-15 04:31:41 +02:00
|
|
|
|
|
|
|
|
|
[TestCase("The Test", "Test")]
|
|
|
|
|
[TestCase("Through the Wormhole", "Through.the.Wormhole")]
|
2011-05-22 18:53:21 +02:00
|
|
|
|
public void find_series_match(string title, string searchTitle)
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
2011-06-15 04:31:41 +02:00
|
|
|
|
var emptyRepository = MockLib.GetEmptyDatabase();
|
2011-05-22 18:53:21 +02:00
|
|
|
|
mocker.SetConstant(emptyRepository);
|
2011-06-15 04:31:41 +02:00
|
|
|
|
emptyRepository.Insert(MockLib.GetFakeSeries(1, title));
|
2011-05-22 18:53:21 +02:00
|
|
|
|
//Act
|
|
|
|
|
var seriesProvider = mocker.Resolve<SeriesProvider>();
|
|
|
|
|
var series = seriesProvider.FindSeries(searchTitle);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
Assert.IsNotNull(series);
|
|
|
|
|
Assert.AreEqual(title, series.Title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void is_monitored()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
2011-06-16 08:33:01 +02:00
|
|
|
|
var db = MockLib.GetEmptyDatabase();
|
|
|
|
|
mocker.SetConstant(db);
|
2011-05-22 18:53:21 +02:00
|
|
|
|
|
2011-06-16 08:33:01 +02:00
|
|
|
|
mocker.SetConstant(db);
|
2011-05-22 18:53:21 +02:00
|
|
|
|
|
2011-06-16 08:33:01 +02:00
|
|
|
|
db.Insert(Builder<Series>.CreateNew()
|
2011-05-22 18:53:21 +02:00
|
|
|
|
.With(c => c.Monitored = true)
|
|
|
|
|
.With(c => c.SeriesId = 12)
|
|
|
|
|
.Build());
|
|
|
|
|
|
2011-06-17 04:48:24 +02:00
|
|
|
|
db.Insert(Builder<Series>.CreateNew()
|
|
|
|
|
.With(c => c.Monitored = false)
|
|
|
|
|
.With(c => c.SeriesId = 11)
|
|
|
|
|
.Build());
|
2011-05-22 18:53:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Act, Assert
|
|
|
|
|
var provider = mocker.Resolve<SeriesProvider>();
|
|
|
|
|
Assert.IsTrue(provider.IsMonitored(12));
|
|
|
|
|
Assert.IsFalse(provider.IsMonitored(11));
|
|
|
|
|
Assert.IsFalse(provider.IsMonitored(1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2011-04-23 00:24:05 +02:00
|
|
|
|
} |