2011-04-19 00:12:06 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
2011-04-25 20:21:52 +00:00
|
|
|
|
using System.Net;
|
2011-04-19 00:12:06 +00:00
|
|
|
|
using System.ServiceModel.Syndication;
|
|
|
|
|
using AutoMoq;
|
|
|
|
|
using FizzWare.NBuilder;
|
2011-01-29 06:10:22 +00:00
|
|
|
|
using MbUnit.Framework;
|
|
|
|
|
using Moq;
|
|
|
|
|
using NzbDrone.Core.Providers;
|
2011-04-04 03:50:12 +00:00
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
2011-04-29 06:06:13 +00:00
|
|
|
|
using NzbDrone.Core.Providers.ExternalNotification;
|
2011-04-19 00:12:06 +00:00
|
|
|
|
using NzbDrone.Core.Providers.Indexer;
|
2011-01-29 06:10:22 +00:00
|
|
|
|
using NzbDrone.Core.Repository;
|
2011-04-25 20:21:52 +00:00
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
2011-05-19 03:55:35 +00:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2011-04-19 00:12:06 +00:00
|
|
|
|
// ReSharper disable InconsistentNaming
|
2011-05-19 03:55:35 +00:00
|
|
|
|
public class IndexerProviderTest : TestBase
|
2011-01-29 06:10:22 +00:00
|
|
|
|
{
|
|
|
|
|
[Test]
|
2011-04-25 17:48:16 +00:00
|
|
|
|
[Row("nzbsorg.xml")]
|
|
|
|
|
[Row("nzbsrus.xml")]
|
|
|
|
|
[Row("newzbin.xml")]
|
|
|
|
|
[Row("nzbmatrix.xml")]
|
|
|
|
|
public void parse_feed_xml(string fileName)
|
2011-01-29 06:10:22 +00:00
|
|
|
|
{
|
2011-04-19 00:12:06 +00:00
|
|
|
|
var mocker = new AutoMoqer();
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
2011-04-19 00:12:06 +00:00
|
|
|
|
mocker.GetMock<HttpProvider>()
|
2011-04-25 20:21:52 +00:00
|
|
|
|
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
|
2011-04-25 18:16:38 +00:00
|
|
|
|
.Returns(File.OpenRead(".\\Files\\Rss\\" + fileName));
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
2011-04-19 00:12:06 +00:00
|
|
|
|
var fakeSettings = Builder<IndexerSetting>.CreateNew().Build();
|
|
|
|
|
mocker.GetMock<IndexerProvider>()
|
|
|
|
|
.Setup(c => c.GetSettings(It.IsAny<Type>()))
|
|
|
|
|
.Returns(fakeSettings);
|
|
|
|
|
|
2011-04-25 17:48:16 +00:00
|
|
|
|
var exceptions = mocker.Resolve<MockIndexerProvider>().Fetch();
|
|
|
|
|
|
|
|
|
|
foreach (var exception in exceptions)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(exception.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Assert.IsEmpty(exceptions);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-25 20:21:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
[Row("Adventure.Inc.S03E19.DVDRip.XviD-OSiTV", 3, 19, QualityTypes.DVD)]
|
|
|
|
|
public void parse_feed_test_success(string title, int season, int episode, QualityTypes quality)
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
2011-05-19 03:55:35 +00:00
|
|
|
|
const string summary = "My fake summary";
|
2011-04-25 20:21:52 +00:00
|
|
|
|
|
|
|
|
|
var fakeSettings = Builder<IndexerSetting>.CreateNew().Build();
|
|
|
|
|
mocker.GetMock<IndexerProvider>()
|
|
|
|
|
.Setup(c => c.GetSettings(It.IsAny<Type>()))
|
|
|
|
|
.Returns(fakeSettings);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<SeriesProvider>()
|
|
|
|
|
.Setup(c => c.FindSeries(It.IsAny<String>()))
|
|
|
|
|
.Returns(Builder<Series>.CreateNew().Build());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
[Row("Adventure.Inc.DVDRip.XviD-OSiTV")]
|
|
|
|
|
public void parse_feed_test_fail(string title)
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var fakeSettings = Builder<IndexerSetting>.CreateNew().Build();
|
|
|
|
|
mocker.GetMock<IndexerProvider>()
|
|
|
|
|
.Setup(c => c.GetSettings(It.IsAny<Type>()))
|
|
|
|
|
.Returns(fakeSettings);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<SeriesProvider>(MockBehavior.Strict);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var fakeRssItem = Builder<SyndicationItem>.CreateNew()
|
|
|
|
|
.With(c => c.Title = new TextSyndicationContent(title))
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var result = mocker.Resolve<CustomParserIndexer>().ParseFeed(fakeRssItem);
|
|
|
|
|
|
|
|
|
|
Assert.IsNull(result);
|
2011-05-19 03:55:35 +00:00
|
|
|
|
ExceptionVerification.ExcpectedWarns(1);
|
2011-04-25 20:21:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-04-25 17:48:16 +00: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-04-19 00:12:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Init_indexer_test()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
|
|
|
|
|
mocker.SetConstant(MockLib.GetEmptyRepository());
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
|
|
|
|
//Act
|
2011-04-19 00:12:06 +00:00
|
|
|
|
var indexerProvider = mocker.Resolve<IndexerProvider>();
|
2011-05-19 03:55:35 +00:00
|
|
|
|
indexerProvider.InitializeIndexers(new List<IndexerProviderBase> { mocker.Resolve<MockIndexerProvider>() });
|
2011-04-22 06:23:29 +00:00
|
|
|
|
var indexers = indexerProvider.All();
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2011-04-19 00:12:06 +00:00
|
|
|
|
Assert.Count(1, indexers);
|
2011-01-29 06:10:22 +00:00
|
|
|
|
}
|
2011-04-22 19:16:52 +00: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);
|
|
|
|
|
|
|
|
|
|
var indexer = mocker.Resolve<MockIndexerProvider>();
|
|
|
|
|
indexer.ProcessItem(new SyndicationItem { Title = new TextSyndicationContent("Adventure.Inc.S01E18.DVDRip.XviD-OSiTV") });
|
|
|
|
|
}
|
2011-04-19 00:12:06 +00:00
|
|
|
|
}
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
2011-04-19 00:12:06 +00:00
|
|
|
|
public class MockIndexerProvider : IndexerProviderBase
|
|
|
|
|
{
|
2011-04-29 06:06:13 +00:00
|
|
|
|
public MockIndexerProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider,
|
|
|
|
|
EpisodeProvider episodeProvider, ConfigProvider configProvider,
|
|
|
|
|
HttpProvider httpProvider, IndexerProvider indexerProvider,
|
|
|
|
|
HistoryProvider historyProvider, SabProvider sabProvider, IEnumerable<ExternalNotificationProviderBase> externalNotificationProvider)
|
|
|
|
|
: base(seriesProvider, seasonProvider, episodeProvider,
|
|
|
|
|
configProvider, httpProvider, indexerProvider, historyProvider,
|
|
|
|
|
sabProvider, externalNotificationProvider)
|
2011-01-29 06:10:22 +00:00
|
|
|
|
{
|
2011-04-19 00:12:06 +00:00
|
|
|
|
}
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
2011-04-21 01:26:13 +00:00
|
|
|
|
protected override string[] Urls
|
2011-04-19 00:12:06 +00:00
|
|
|
|
{
|
|
|
|
|
get { return new[] { "www.google.com" }; }
|
|
|
|
|
}
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
2011-04-25 20:21:52 +00:00
|
|
|
|
protected override NetworkCredential Credentials
|
|
|
|
|
{
|
|
|
|
|
get { return null; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-19 00:12:06 +00:00
|
|
|
|
public override string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "Mocked Indexer"; }
|
|
|
|
|
}
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
2011-05-01 08:04:44 +00:00
|
|
|
|
public override bool SupportsBacklog
|
|
|
|
|
{
|
|
|
|
|
get { return false; }
|
|
|
|
|
}
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
2011-04-19 00:12:06 +00:00
|
|
|
|
protected override string NzbDownloadUrl(SyndicationItem item)
|
|
|
|
|
{
|
|
|
|
|
return item.Links[0].Uri.ToString();
|
2011-01-29 06:10:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-04-25 17:48:16 +00:00
|
|
|
|
|
|
|
|
|
public class TestUrlIndexer : IndexerProviderBase
|
|
|
|
|
{
|
2011-04-29 06:06:13 +00:00
|
|
|
|
public TestUrlIndexer(SeriesProvider seriesProvider, SeasonProvider seasonProvider,
|
|
|
|
|
EpisodeProvider episodeProvider, ConfigProvider configProvider,
|
|
|
|
|
HttpProvider httpProvider, IndexerProvider indexerProvider,
|
|
|
|
|
HistoryProvider historyProvider, SabProvider sabProvider, IEnumerable<ExternalNotificationProviderBase> externalNotificationProvider)
|
|
|
|
|
: base(seriesProvider, seasonProvider, episodeProvider,
|
|
|
|
|
configProvider, httpProvider, indexerProvider, historyProvider,
|
|
|
|
|
sabProvider, externalNotificationProvider)
|
2011-04-25 17:48:16 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "All Urls"; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-01 08:04:44 +00:00
|
|
|
|
public override bool SupportsBacklog
|
|
|
|
|
{
|
|
|
|
|
get { return false; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-25 17:48:16 +00:00
|
|
|
|
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-04-25 20:21:52 +00:00
|
|
|
|
public class CustomParserIndexer : IndexerProviderBase
|
|
|
|
|
{
|
2011-04-29 06:06:13 +00:00
|
|
|
|
public CustomParserIndexer(SeriesProvider seriesProvider, SeasonProvider seasonProvider,
|
|
|
|
|
EpisodeProvider episodeProvider, ConfigProvider configProvider,
|
|
|
|
|
HttpProvider httpProvider, IndexerProvider indexerProvider,
|
|
|
|
|
HistoryProvider historyProvider, SabProvider sabProvider, IEnumerable<ExternalNotificationProviderBase> externalNotificationProvider)
|
|
|
|
|
: base(seriesProvider, seasonProvider, episodeProvider,
|
|
|
|
|
configProvider, httpProvider, indexerProvider, historyProvider,
|
|
|
|
|
sabProvider, externalNotificationProvider)
|
2011-04-25 20:21:52 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "Custom parser"; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-01 08:04:44 +00:00
|
|
|
|
public override bool SupportsBacklog
|
|
|
|
|
{
|
|
|
|
|
get { return false; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-25 20:21:52 +00: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)
|
|
|
|
|
{
|
|
|
|
|
currentResult.EpisodeTitle = item.Summary.Text;
|
|
|
|
|
return currentResult;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-10 02:44:01 +00:00
|
|
|
|
}
|