2011-05-22 18:53:21 +02:00
|
|
|
|
// ReSharper disable RedundantUsingDirective
|
|
|
|
|
using System;
|
2011-04-19 02:12:06 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
2011-04-25 22:21:52 +02:00
|
|
|
|
using System.Net;
|
2011-04-19 02:12:06 +02:00
|
|
|
|
using System.ServiceModel.Syndication;
|
|
|
|
|
using AutoMoq;
|
|
|
|
|
using FizzWare.NBuilder;
|
2011-01-29 07:10:22 +01:00
|
|
|
|
using MbUnit.Framework;
|
|
|
|
|
using Moq;
|
2011-05-20 06:18:51 +02:00
|
|
|
|
using NzbDrone.Core.Model;
|
2011-01-29 07:10:22 +01:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2011-04-04 05:50:12 +02:00
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
2011-04-29 08:06:13 +02:00
|
|
|
|
using NzbDrone.Core.Providers.ExternalNotification;
|
2011-04-19 02:12:06 +02:00
|
|
|
|
using NzbDrone.Core.Providers.Indexer;
|
2011-01-29 07:10:22 +01:00
|
|
|
|
using NzbDrone.Core.Repository;
|
2011-04-25 22:21:52 +02:00
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
2011-05-19 05:55:35 +02:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-01-29 07:10:22 +01:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2011-04-19 02:12:06 +02:00
|
|
|
|
// ReSharper disable InconsistentNaming
|
2011-05-19 05:55:35 +02:00
|
|
|
|
public class IndexerProviderTest : TestBase
|
2011-01-29 07:10:22 +01:00
|
|
|
|
{
|
|
|
|
|
[Test]
|
2011-05-20 06:18:51 +02:00
|
|
|
|
[Row("nzbsorg.xml", 0)]
|
|
|
|
|
[Row("nzbsrus.xml", 6)]
|
|
|
|
|
[Row("newzbin.xml", 1)]
|
|
|
|
|
[Row("nzbmatrix.xml", 1)]
|
|
|
|
|
public void parse_feed_xml(string fileName, int warns)
|
2011-01-29 07:10:22 +01:00
|
|
|
|
{
|
2011-04-19 02:12:06 +02:00
|
|
|
|
var mocker = new AutoMoqer();
|
2011-01-29 07:10:22 +01:00
|
|
|
|
|
2011-04-19 02:12:06 +02:00
|
|
|
|
mocker.GetMock<HttpProvider>()
|
2011-04-25 22:21:52 +02:00
|
|
|
|
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
|
2011-04-25 20:16:38 +02:00
|
|
|
|
.Returns(File.OpenRead(".\\Files\\Rss\\" + fileName));
|
2011-01-29 07:10:22 +01:00
|
|
|
|
|
2011-04-19 02:12:06 +02:00
|
|
|
|
var fakeSettings = Builder<IndexerSetting>.CreateNew().Build();
|
|
|
|
|
mocker.GetMock<IndexerProvider>()
|
|
|
|
|
.Setup(c => c.GetSettings(It.IsAny<Type>()))
|
|
|
|
|
.Returns(fakeSettings);
|
|
|
|
|
|
2011-05-20 06:21:18 +02:00
|
|
|
|
var parseResults = mocker.Resolve<MockIndexer>().Fetch();
|
2011-04-25 19:48:16 +02:00
|
|
|
|
|
|
|
|
|
|
2011-05-20 06:18:51 +02:00
|
|
|
|
Assert.IsNotEmpty(parseResults);
|
|
|
|
|
ExceptionVerification.ExcpectedWarns(warns);
|
2011-04-25 19:48:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-25 22:21:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
[Row("Adventure.Inc.S03E19.DVDRip.XviD-OSiTV", 3, 19, QualityTypes.DVD)]
|
2011-05-20 06:18:51 +02:00
|
|
|
|
public void custome_parser_partial_success(string title, int season, int episode, QualityTypes quality)
|
2011-04-25 22:21:52 +02:00
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
2011-05-19 05:55:35 +02:00
|
|
|
|
const string summary = "My fake summary";
|
2011-04-25 22:21:52 +02:00
|
|
|
|
|
|
|
|
|
var fakeSettings = Builder<IndexerSetting>.CreateNew().Build();
|
|
|
|
|
mocker.GetMock<IndexerProvider>()
|
|
|
|
|
.Setup(c => c.GetSettings(It.IsAny<Type>()))
|
|
|
|
|
.Returns(fakeSettings);
|
|
|
|
|
|
|
|
|
|
var fakeRssItem = Builder<SyndicationItem>.CreateNew()
|
|
|
|
|
.With(c => c.Title = new TextSyndicationContent(title))
|
|
|
|
|
.With(c => c.Summary = new TextSyndicationContent(summary))
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var result = mocker.Resolve<CustomParserIndexer>().ParseFeed(fakeRssItem);
|
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(result);
|
|
|
|
|
Assert.AreEqual(summary, result.EpisodeTitle);
|
2011-05-20 06:18:51 +02:00
|
|
|
|
Assert.AreEqual(season, result.SeasonNumber);
|
|
|
|
|
Assert.AreEqual(episode, result.Episodes[0]);
|
|
|
|
|
Assert.AreEqual(quality, result.Quality);
|
2011-04-25 22:21:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
[Row("Adventure.Inc.DVDRip.XviD-OSiTV")]
|
2011-05-20 06:18:51 +02:00
|
|
|
|
public void custome_parser_full_parse(string title)
|
2011-04-25 22:21:52 +02:00
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
2011-05-20 06:18:51 +02:00
|
|
|
|
const string summary = "My fake summary";
|
2011-04-25 22:21:52 +02:00
|
|
|
|
|
|
|
|
|
var fakeSettings = Builder<IndexerSetting>.CreateNew().Build();
|
|
|
|
|
mocker.GetMock<IndexerProvider>()
|
|
|
|
|
.Setup(c => c.GetSettings(It.IsAny<Type>()))
|
|
|
|
|
.Returns(fakeSettings);
|
|
|
|
|
|
|
|
|
|
var fakeRssItem = Builder<SyndicationItem>.CreateNew()
|
|
|
|
|
.With(c => c.Title = new TextSyndicationContent(title))
|
2011-05-20 06:18:51 +02:00
|
|
|
|
.With(c => c.Summary = new TextSyndicationContent(summary))
|
2011-04-25 22:21:52 +02:00
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var result = mocker.Resolve<CustomParserIndexer>().ParseFeed(fakeRssItem);
|
|
|
|
|
|
2011-05-20 06:18:51 +02:00
|
|
|
|
Assert.IsNotNull(result);
|
|
|
|
|
Assert.AreEqual(summary, result.EpisodeTitle);
|
2011-05-19 05:55:35 +02:00
|
|
|
|
ExceptionVerification.ExcpectedWarns(1);
|
2011-04-25 22:21:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-04-25 19:48:16 +02:00
|
|
|
|
[Test]
|
|
|
|
|
public void downloadFeed()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
mocker.SetConstant(new HttpProvider());
|
|
|
|
|
|
|
|
|
|
var fakeSettings = Builder<IndexerSetting>.CreateNew().Build();
|
|
|
|
|
mocker.GetMock<IndexerProvider>()
|
|
|
|
|
.Setup(c => c.GetSettings(It.IsAny<Type>()))
|
|
|
|
|
.Returns(fakeSettings);
|
|
|
|
|
|
|
|
|
|
mocker.Resolve<TestUrlIndexer>().Fetch();
|
2011-05-20 06:18:51 +02:00
|
|
|
|
|
|
|
|
|
ExceptionVerification.IgnoreWarns();
|
2011-04-19 02:12:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Init_indexer_test()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
|
|
mocker.SetConstant(MockLib.GetEmptyRepository());
|
2011-01-29 07:10:22 +01:00
|
|
|
|
|
|
|
|
|
//Act
|
2011-04-19 02:12:06 +02:00
|
|
|
|
var indexerProvider = mocker.Resolve<IndexerProvider>();
|
2011-05-20 06:21:18 +02:00
|
|
|
|
indexerProvider.InitializeIndexers(new List<IndexerBase> { mocker.Resolve<MockIndexer>() });
|
2011-04-22 08:23:29 +02:00
|
|
|
|
var indexers = indexerProvider.All();
|
2011-01-29 07:10:22 +01:00
|
|
|
|
|
|
|
|
|
//Assert
|
2011-04-19 02:12:06 +02:00
|
|
|
|
Assert.Count(1, indexers);
|
2011-01-29 07:10:22 +01:00
|
|
|
|
}
|
2011-04-22 21:16:52 +02:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void unmapped_series_shouldnt_call_any_providers()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer(MockBehavior.Strict);
|
|
|
|
|
mocker.GetMock<SeriesProvider>()
|
|
|
|
|
.Setup(c => c.FindSeries(It.IsAny<String>()))
|
|
|
|
|
.Returns<Series>(null);
|
|
|
|
|
|
2011-05-20 06:21:18 +02:00
|
|
|
|
var indexer = mocker.Resolve<MockIndexer>();
|
2011-05-20 06:18:51 +02:00
|
|
|
|
//indexer.ProcessItem(new SyndicationItem { Title = new TextSyndicationContent("Adventure.Inc.S01E18.DVDRip.XviD-OSiTV") });
|
2011-04-22 21:16:52 +02:00
|
|
|
|
}
|
2011-04-19 02:12:06 +02:00
|
|
|
|
}
|
2011-01-29 07:10:22 +01:00
|
|
|
|
|
2011-05-20 06:21:18 +02:00
|
|
|
|
public class MockIndexer : IndexerBase
|
2011-04-19 02:12:06 +02:00
|
|
|
|
{
|
2011-05-20 06:21:18 +02:00
|
|
|
|
public MockIndexer(HttpProvider httpProvider, ConfigProvider configProvider, IndexerProvider indexerProvider)
|
2011-05-20 06:18:51 +02:00
|
|
|
|
: base(httpProvider, configProvider, indexerProvider)
|
2011-01-29 07:10:22 +01:00
|
|
|
|
{
|
2011-04-19 02:12:06 +02:00
|
|
|
|
}
|
2011-01-29 07:10:22 +01:00
|
|
|
|
|
2011-04-21 03:26:13 +02:00
|
|
|
|
protected override string[] Urls
|
2011-04-19 02:12:06 +02:00
|
|
|
|
{
|
|
|
|
|
get { return new[] { "www.google.com" }; }
|
|
|
|
|
}
|
2011-01-29 07:10:22 +01:00
|
|
|
|
|
2011-04-25 22:21:52 +02:00
|
|
|
|
protected override NetworkCredential Credentials
|
|
|
|
|
{
|
|
|
|
|
get { return null; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-19 02:12:06 +02:00
|
|
|
|
public override string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "Mocked Indexer"; }
|
|
|
|
|
}
|
2011-01-29 07:10:22 +01:00
|
|
|
|
|
|
|
|
|
|
2011-04-19 02:12:06 +02:00
|
|
|
|
protected override string NzbDownloadUrl(SyndicationItem item)
|
|
|
|
|
{
|
|
|
|
|
return item.Links[0].Uri.ToString();
|
2011-01-29 07:10:22 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-04-25 19:48:16 +02:00
|
|
|
|
|
2011-05-20 06:21:18 +02:00
|
|
|
|
public class TestUrlIndexer : IndexerBase
|
2011-04-25 19:48:16 +02:00
|
|
|
|
{
|
2011-05-20 06:18:51 +02:00
|
|
|
|
public TestUrlIndexer(HttpProvider httpProvider, ConfigProvider configProvider, IndexerProvider indexerProvider)
|
|
|
|
|
: base(httpProvider, configProvider, indexerProvider)
|
2011-04-25 19:48:16 +02:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "All Urls"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override string[] Urls
|
|
|
|
|
{
|
|
|
|
|
get { return new[] { "http://rss.nzbmatrix.com/rss.php?cat=TV" }; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override string NzbDownloadUrl(SyndicationItem item)
|
|
|
|
|
{
|
|
|
|
|
return "http://google.com";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-20 06:21:18 +02:00
|
|
|
|
public class CustomParserIndexer : IndexerBase
|
2011-04-25 22:21:52 +02:00
|
|
|
|
{
|
2011-05-20 06:18:51 +02:00
|
|
|
|
public CustomParserIndexer(HttpProvider httpProvider, ConfigProvider configProvider, IndexerProvider indexerProvider)
|
|
|
|
|
: base(httpProvider, configProvider, indexerProvider)
|
2011-04-25 22:21:52 +02:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "Custom parser"; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-20 06:18:51 +02:00
|
|
|
|
|
2011-05-01 10:04:44 +02:00
|
|
|
|
|
2011-04-25 22:21:52 +02:00
|
|
|
|
protected override string[] Urls
|
|
|
|
|
{
|
|
|
|
|
get { return new[] { "http://www.google.com" }; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override string NzbDownloadUrl(SyndicationItem item)
|
|
|
|
|
{
|
|
|
|
|
return "http://www.google.com";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override Model.EpisodeParseResult CustomParser(SyndicationItem item, Model.EpisodeParseResult currentResult)
|
|
|
|
|
{
|
2011-05-20 06:18:51 +02:00
|
|
|
|
if (currentResult == null) currentResult = new EpisodeParseResult();
|
2011-04-25 22:21:52 +02:00
|
|
|
|
currentResult.EpisodeTitle = item.Summary.Text;
|
|
|
|
|
return currentResult;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-10 04:44:01 +02:00
|
|
|
|
}
|