2010-09-27 03:22:44 +03:00
|
|
|
using System;
|
2010-09-28 03:27:02 +03:00
|
|
|
using System.Collections;
|
2010-09-27 03:22:44 +03:00
|
|
|
using System.Collections.Generic;
|
2010-09-28 06:04:39 +03:00
|
|
|
using System.IO;
|
2010-09-27 03:22:44 +03:00
|
|
|
using System.Text;
|
2010-09-28 03:27:02 +03:00
|
|
|
using FizzWare.NBuilder;
|
2010-09-27 03:22:44 +03:00
|
|
|
using Gallio.Framework;
|
|
|
|
using MbUnit.Framework;
|
|
|
|
using MbUnit.Framework.ContractVerifiers;
|
|
|
|
using Moq;
|
2010-09-28 03:27:02 +03:00
|
|
|
using Ninject;
|
|
|
|
using Ninject.Moq;
|
2010-09-28 07:25:41 +03:00
|
|
|
using NzbDrone.Core.Providers;
|
2010-09-28 03:27:02 +03:00
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
using SubSonic.Repository;
|
|
|
|
using TvdbLib.Data;
|
2010-10-01 03:09:22 +03:00
|
|
|
using System.Linq;
|
2010-09-27 03:22:44 +03:00
|
|
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
namespace NzbDrone.Core.Test
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public class SeriesTest
|
|
|
|
{
|
|
|
|
[Test]
|
2010-10-04 04:00:50 +03:00
|
|
|
public void Map_path_to_series()
|
2010-09-27 03:22:44 +03:00
|
|
|
{
|
|
|
|
//Arrange
|
2010-10-02 22:01:43 +03:00
|
|
|
TvdbSeries fakeSeries = Builder<TvdbSeries>.CreateNew().With(f => f.SeriesName = "The Simpsons").Build();
|
2010-10-04 04:00:50 +03:00
|
|
|
var fakeSearch = Builder<TvdbSearchResult>.CreateNew().Build();
|
|
|
|
fakeSearch.Id = fakeSeries.Id;
|
|
|
|
fakeSearch.SeriesName = fakeSeries.SeriesName;
|
2010-10-02 22:01:43 +03:00
|
|
|
|
|
|
|
var moqData = new Mock<IRepository>();
|
|
|
|
var moqTvdb = new Mock<ITvDbProvider>();
|
|
|
|
|
|
|
|
moqData.Setup(f => f.Exists<Series>(c => c.TvdbId == It.IsAny<long>())).Returns(false);
|
2010-10-01 03:09:22 +03:00
|
|
|
|
2010-10-04 04:00:50 +03:00
|
|
|
moqTvdb.Setup(f => f.GetSeries(It.IsAny<String>())).Returns(fakeSearch);
|
2010-10-02 22:01:43 +03:00
|
|
|
moqTvdb.Setup(f => f.GetSeries(fakeSeries.Id, It.IsAny<TvdbLanguage>())).Returns(fakeSeries);
|
|
|
|
|
|
|
|
var kernel = new MockingKernel();
|
|
|
|
kernel.Bind<IRepository>().ToConstant(moqData.Object);
|
|
|
|
kernel.Bind<ITvDbProvider>().ToConstant(moqTvdb.Object);
|
|
|
|
kernel.Bind<ISeriesProvider>().To<SeriesProvider>();
|
|
|
|
|
|
|
|
//Act
|
|
|
|
var seriesController = kernel.Get<ISeriesProvider>();
|
2010-10-04 04:00:50 +03:00
|
|
|
var mappedSeries = seriesController.MapPathToSeries(@"D:\TV Shows\The Simpsons");
|
2010-10-02 22:01:43 +03:00
|
|
|
|
|
|
|
//Assert
|
2010-10-04 04:00:50 +03:00
|
|
|
Assert.AreEqual(fakeSeries, mappedSeries);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
[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" })]
|
|
|
|
public void Test_Parse_Success(string postTitle, string title)
|
|
|
|
{
|
|
|
|
var result = SeriesProvider.ParseTitle(postTitle);
|
|
|
|
Assert.AreEqual(title, result, postTitle);
|
2010-10-02 22:01:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
2010-10-01 03:09:22 +03:00
|
|
|
[Description("This test confirms that the tvdb id stored in the db is preserved rather than being replaced by an auto incrementing value")]
|
|
|
|
public void tvdbid_is_preserved([RandomNumbers(Minimum = 100, Maximum = 999, Count = 1)] int tvdbId)
|
|
|
|
{
|
|
|
|
//Arrange
|
|
|
|
var sonicRepo = MockLib.GetEmptyRepository();
|
|
|
|
var series = Builder<Series>.CreateNew().With(c => c.TvdbId = tvdbId).Build();
|
|
|
|
|
|
|
|
//Act
|
|
|
|
var addId = sonicRepo.Add(series);
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
Assert.AreEqual(tvdbId, addId);
|
|
|
|
var allSeries = sonicRepo.All<Series>();
|
|
|
|
Assert.IsNotEmpty(allSeries);
|
|
|
|
Assert.AreEqual(tvdbId, allSeries.First().TvdbId);
|
|
|
|
}
|
2010-10-02 22:01:43 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
[Row(new object[] { "CAPITAL", "capital", true })]
|
|
|
|
[Row(new object[] { "Something!!", "Something", true })]
|
|
|
|
[Row(new object[] { "Simpsons 2000", "Simpsons", true })]
|
|
|
|
[Row(new object[] { "Simp222sons", "Simpsons", true })]
|
|
|
|
[Row(new object[] { "Simpsons", "The Simpsons", true })]
|
|
|
|
[Row(new object[] { "Law and order", "Law & order", true })]
|
|
|
|
[Row(new object[] { "xxAndxx", "xxxx", false })]
|
|
|
|
[Row(new object[] { "Andxx", "xx", false })]
|
|
|
|
[Row(new object[] { "xxAnd", "xx", false })]
|
|
|
|
[Row(new object[] { "Thexx", "xx", false })]
|
|
|
|
[Row(new object[] { "Thexx", "xx", false })]
|
|
|
|
[Row(new object[] { "xxThexx", "xxxxx", false })]
|
|
|
|
[Row(new object[] { "Simpsons The", "Simpsons", true })]
|
|
|
|
public void Name_match_test(string a, string b, bool match)
|
|
|
|
{
|
2010-10-04 04:00:50 +03:00
|
|
|
bool result = TvDbProvider.IsTitleMatch(a, b);
|
2010-10-02 22:01:43 +03:00
|
|
|
|
|
|
|
Assert.AreEqual(match, result, "{0} , {1}", a, b);
|
|
|
|
}
|
2010-09-27 03:22:44 +03:00
|
|
|
}
|
|
|
|
}
|