2010-09-27 02:22:44 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2011-04-10 04:44:01 +02:00
|
|
|
|
using System.Linq;
|
2011-04-07 05:34:48 +02:00
|
|
|
|
using AutoMoq;
|
2010-09-28 02:27:02 +02:00
|
|
|
|
using FizzWare.NBuilder;
|
2010-09-27 02:22:44 +02:00
|
|
|
|
using MbUnit.Framework;
|
|
|
|
|
using Moq;
|
2010-09-28 06:25:41 +02:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2010-10-21 03:49:23 +02:00
|
|
|
|
using NzbDrone.Core.Repository;
|
2011-04-05 07:30:13 +02:00
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
2010-09-28 02:27:02 +02:00
|
|
|
|
using SubSonic.Repository;
|
|
|
|
|
using TvdbLib.Data;
|
2010-09-27 02:22:44 +02:00
|
|
|
|
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
2011-04-10 04:44:01 +02:00
|
|
|
|
|
2010-09-27 02:22:44 +02:00
|
|
|
|
namespace NzbDrone.Core.Test
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2010-10-08 00:17:24 +02:00
|
|
|
|
// ReSharper disable InconsistentNaming
|
2010-10-05 08:21:18 +02:00
|
|
|
|
public class SeriesProviderTest
|
2010-09-27 02:22:44 +02:00
|
|
|
|
{
|
|
|
|
|
[Test]
|
2010-10-04 03:00:50 +02:00
|
|
|
|
public void Map_path_to_series()
|
2010-09-27 02:22:44 +02:00
|
|
|
|
{
|
|
|
|
|
//Arrange
|
2011-04-07 05:34:48 +02:00
|
|
|
|
var fakeSeries = Builder<TvdbSeries>.CreateNew()
|
|
|
|
|
.With(f => f.SeriesName = "The Simpsons")
|
|
|
|
|
.Build();
|
2010-10-02 21:01:43 +02:00
|
|
|
|
|
2011-04-07 05:34:48 +02:00
|
|
|
|
var fakeSearch = Builder<TvdbSearchResult>.CreateNew()
|
|
|
|
|
.With(s => s.Id = fakeSeries.Id)
|
|
|
|
|
.With(s => s.SeriesName = fakeSeries.SeriesName)
|
|
|
|
|
.Build();
|
2010-10-02 21:01:43 +02:00
|
|
|
|
|
2010-10-01 02:09:22 +02:00
|
|
|
|
|
2011-04-07 05:34:48 +02:00
|
|
|
|
var mocker = new AutoMoqer();
|
2010-10-02 21:01:43 +02:00
|
|
|
|
|
2011-04-07 05:34:48 +02:00
|
|
|
|
mocker.GetMock<IRepository>()
|
|
|
|
|
.Setup(f => f.Exists<Series>(c => c.SeriesId == It.IsAny<int>()))
|
|
|
|
|
.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();
|
2010-10-02 21:01:43 +02:00
|
|
|
|
|
|
|
|
|
//Act
|
2011-04-07 05:34:48 +02:00
|
|
|
|
|
|
|
|
|
var mappedSeries = mocker.Resolve<SeriesProvider>().MapPathToSeries(@"D:\TV Shows\The Simpsons");
|
2010-10-02 21:01:43 +02:00
|
|
|
|
|
|
|
|
|
//Assert
|
2011-04-07 05:34:48 +02:00
|
|
|
|
mocker.GetMock<TvDbProvider>().VerifyAll();
|
2010-10-04 03:00:50 +02:00
|
|
|
|
Assert.AreEqual(fakeSeries, mappedSeries);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-01 08:36:34 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void Add_new_series()
|
|
|
|
|
{
|
2011-04-08 06:03:46 +02:00
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
mocker.SetConstant(MockLib.GetEmptyRepository());
|
2011-04-01 08:36:34 +02:00
|
|
|
|
|
|
|
|
|
string path = "C:\\Test\\";
|
|
|
|
|
int tvDbId = 1234;
|
|
|
|
|
int qualityProfileId = 2;
|
|
|
|
|
|
|
|
|
|
//Act
|
2011-04-08 06:03:46 +02:00
|
|
|
|
var seriesProvider = mocker.Resolve<SeriesProvider>();
|
2011-04-01 08:36:34 +02:00
|
|
|
|
seriesProvider.AddSeries(path, tvDbId, qualityProfileId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
var series = seriesProvider.GetAllSeries();
|
|
|
|
|
Assert.IsNotEmpty(series);
|
|
|
|
|
Assert.Count(1, series);
|
|
|
|
|
Assert.AreEqual(path, series.First().Path);
|
|
|
|
|
Assert.AreEqual(tvDbId, series.First().SeriesId);
|
|
|
|
|
Assert.AreEqual(qualityProfileId, series.First().QualityProfileId);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-22 21:16:52 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void find_series_empty_repo()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
mocker.SetConstant(MockLib.GetEmptyRepository());
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var seriesProvider = mocker.Resolve<SeriesProvider>();
|
|
|
|
|
var series = seriesProvider.FindSeries("My Title");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
Assert.IsNull(series);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void find_series_empty_match()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
var emptyRepository = MockLib.GetEmptyRepository();
|
|
|
|
|
mocker.SetConstant(emptyRepository);
|
|
|
|
|
emptyRepository.Add<Series>(MockLib.GetFakeSeries(1, "MyTitle"));
|
|
|
|
|
//Act
|
|
|
|
|
var seriesProvider = mocker.Resolve<SeriesProvider>();
|
|
|
|
|
var series = seriesProvider.FindSeries("WrongTitle");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
Assert.IsNull(series);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
[Row("The Test", "Test")]
|
2011-04-22 22:14:02 +02:00
|
|
|
|
[Row("Through the Wormhole", "Through.the.Wormhole")]
|
2011-04-22 21:16:52 +02:00
|
|
|
|
public void find_series_match(string title, string searchTitle)
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
var emptyRepository = MockLib.GetEmptyRepository();
|
|
|
|
|
mocker.SetConstant(emptyRepository);
|
|
|
|
|
emptyRepository.Add<Series>(MockLib.GetFakeSeries(1, title));
|
|
|
|
|
//Act
|
|
|
|
|
var seriesProvider = mocker.Resolve<SeriesProvider>();
|
|
|
|
|
var series = seriesProvider.FindSeries(searchTitle);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
Assert.IsNotNull(series);
|
|
|
|
|
Assert.AreEqual(title, series.Title);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-01 08:36:34 +02:00
|
|
|
|
|
2010-10-04 03:00:50 +02:00
|
|
|
|
[Test]
|
2011-04-22 21:16:52 +02:00
|
|
|
|
[Row(new object[] { "That's Life - 2x03 -The Devil and Miss DeLucca", "That's Life" })]
|
|
|
|
|
[Row(new object[] { "Van.Duin.Op.Zn.Best.S02E05.DUTCH.WS.PDTV.XViD-DiFFERENT", "Van Duin Op Zn Best" })]
|
|
|
|
|
[Row(new object[] { "Dollhouse.S02E06.The.Left.Hand.720p.BluRay.x264-SiNNERS", "Dollhouse" })]
|
|
|
|
|
[Row(new object[] { "Heroes.S02.COMPLETE.German.PROPER.DVDRip.XviD-Prim3time", "Heroes" })]
|
2010-10-21 03:49:23 +02:00
|
|
|
|
[Ignore("should be updated to validate agains a remote episode instance rather than just the title string")]
|
2010-10-04 03:00:50 +02:00
|
|
|
|
public void Test_Parse_Success(string postTitle, string title)
|
|
|
|
|
{
|
2010-10-21 03:49:23 +02:00
|
|
|
|
var result = Parser.ParseEpisodeInfo(postTitle);
|
|
|
|
|
//Assert.AreEqual(title, result, postTitle);
|
2010-10-02 21:01:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-05 07:30:13 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void Test_is_monitored()
|
|
|
|
|
{
|
2011-04-08 06:03:46 +02:00
|
|
|
|
var mocker = new AutoMoqer();
|
2010-10-05 08:21:18 +02:00
|
|
|
|
|
2011-04-08 06:03:46 +02:00
|
|
|
|
mocker.SetConstant(MockLib.GetEmptyRepository());
|
|
|
|
|
|
|
|
|
|
mocker.Resolve<IRepository>().Add(Builder<Series>.CreateNew()
|
2011-04-10 04:44:01 +02:00
|
|
|
|
.With(c => c.Monitored = true)
|
|
|
|
|
.With(c => c.SeriesId = 12)
|
|
|
|
|
.Build());
|
2010-10-05 08:21:18 +02:00
|
|
|
|
|
2011-04-08 06:03:46 +02:00
|
|
|
|
mocker.Resolve<IRepository>().Add(Builder<Series>.CreateNew()
|
2011-04-10 04:44:01 +02:00
|
|
|
|
.With(c => c.Monitored = false)
|
|
|
|
|
.With(c => c.SeriesId = 11)
|
|
|
|
|
.Build());
|
2010-10-05 08:21:18 +02:00
|
|
|
|
|
|
|
|
|
|
2011-04-05 07:30:13 +02:00
|
|
|
|
//Act, Assert
|
2011-04-08 06:03:46 +02:00
|
|
|
|
var provider = mocker.Resolve<SeriesProvider>();
|
2011-04-05 07:30:13 +02:00
|
|
|
|
Assert.IsTrue(provider.IsMonitored(12));
|
|
|
|
|
Assert.IsFalse(provider.IsMonitored(11));
|
|
|
|
|
Assert.IsFalse(provider.IsMonitored(1));
|
|
|
|
|
}
|
2010-10-05 08:21:18 +02:00
|
|
|
|
|
|
|
|
|
|
2011-04-05 07:30:13 +02:00
|
|
|
|
[Test]
|
|
|
|
|
[Row(12, QualityTypes.TV, true)]
|
|
|
|
|
[Row(12, QualityTypes.Unknown, false)]
|
|
|
|
|
[Row(12, QualityTypes.Bluray1080, false)]
|
|
|
|
|
[Row(12, QualityTypes.Bluray720, false)]
|
|
|
|
|
[Row(12, QualityTypes.HDTV, false)]
|
|
|
|
|
[Row(12, QualityTypes.WEBDL, false)]
|
|
|
|
|
public void QualityWanted(int seriesId, QualityTypes qualityTypes, Boolean result)
|
|
|
|
|
{
|
|
|
|
|
var quality = Builder<QualityProfile>.CreateNew()
|
2011-04-22 21:16:52 +02:00
|
|
|
|
.With(q => q.Allowed = new List<QualityTypes> { QualityTypes.BDRip, QualityTypes.DVD, QualityTypes.TV })
|
2011-04-10 04:44:01 +02:00
|
|
|
|
.With(q => q.Cutoff = QualityTypes.DVD)
|
|
|
|
|
.Build();
|
2011-04-05 07:30:13 +02:00
|
|
|
|
|
2011-04-08 06:03:46 +02:00
|
|
|
|
var series = Builder<Series>.CreateNew()
|
2011-04-10 04:44:01 +02:00
|
|
|
|
.With(c => c.SeriesId = 12)
|
|
|
|
|
.With(c => c.QualityProfileId = quality.QualityProfileId)
|
|
|
|
|
.Build();
|
2011-04-05 07:30:13 +02:00
|
|
|
|
|
2011-04-08 06:03:46 +02:00
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
var emptyRepository = MockLib.GetEmptyRepository();
|
|
|
|
|
mocker.SetConstant(emptyRepository);
|
2011-04-05 07:30:13 +02:00
|
|
|
|
|
|
|
|
|
|
2011-04-08 06:03:46 +02:00
|
|
|
|
mocker.GetMock<QualityProvider>()
|
2011-04-10 04:44:01 +02:00
|
|
|
|
.Setup(c => c.Find(quality.QualityProfileId)).Returns(quality);
|
2011-04-05 07:30:13 +02:00
|
|
|
|
|
|
|
|
|
|
2011-04-08 06:03:46 +02:00
|
|
|
|
emptyRepository.Add(series);
|
2011-04-25 19:48:16 +02:00
|
|
|
|
emptyRepository.Add(quality);
|
2011-04-05 07:30:13 +02:00
|
|
|
|
|
2011-04-08 06:03:46 +02:00
|
|
|
|
//Act
|
|
|
|
|
var needed = mocker.Resolve<SeriesProvider>().QualityWanted(seriesId, qualityTypes);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(result, needed);
|
2011-04-05 07:30:13 +02:00
|
|
|
|
}
|
2010-09-27 02:22:44 +02:00
|
|
|
|
}
|
2011-04-23 00:24:05 +02:00
|
|
|
|
} |