2011-05-22 16:53:21 +00:00
|
|
|
|
// ReSharper disable RedundantUsingDirective
|
2011-10-20 23:42:17 +00:00
|
|
|
|
|
2011-05-22 16:53:21 +00:00
|
|
|
|
using System;
|
2011-04-19 00:12:06 +00:00
|
|
|
|
using System.Collections.Generic;
|
2011-04-25 20:21:52 +00:00
|
|
|
|
using System.Net;
|
2011-04-19 00:12:06 +00:00
|
|
|
|
using System.ServiceModel.Syndication;
|
2011-11-14 00:22:18 +00:00
|
|
|
|
|
2011-06-18 02:00:44 +00:00
|
|
|
|
using FluentAssertions;
|
2011-06-02 21:06:46 +00:00
|
|
|
|
using NUnit.Framework;
|
2012-02-11 00:48:20 +00:00
|
|
|
|
using NzbDrone.Common;
|
2011-05-20 04:18:51 +00:00
|
|
|
|
using NzbDrone.Core.Model;
|
2011-01-29 06:10:22 +00:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2011-04-04 03:50:12 +00:00
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
2011-04-19 00:12:06 +00:00
|
|
|
|
using NzbDrone.Core.Providers.Indexer;
|
2011-05-19 03:55:35 +00:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-11-14 00:22:18 +00:00
|
|
|
|
using NzbDrone.Test.Common.AutoMoq;
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
2011-10-20 23:42:17 +00:00
|
|
|
|
namespace NzbDrone.Core.Test.ProviderTests
|
2011-01-29 06:10:22 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2011-04-19 00:12:06 +00:00
|
|
|
|
// ReSharper disable InconsistentNaming
|
2011-11-13 07:27:16 +00:00
|
|
|
|
public class IndexerProviderTest : CoreTest
|
2011-01-29 06:10:22 +00:00
|
|
|
|
{
|
2011-04-19 00:12:06 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void Init_indexer_test()
|
|
|
|
|
{
|
2013-01-19 23:55:58 +00:00
|
|
|
|
WithRealDb();
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
2013-01-19 05:14:12 +00:00
|
|
|
|
Mocker.SetConstant<IEnumerable<IndexerBase>>(new List<IndexerBase> { Mocker.Resolve<MockIndexer>() });
|
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
var indexerProvider = Mocker.Resolve<IndexerProvider>();
|
2011-05-27 02:12:28 +00:00
|
|
|
|
var settings = indexerProvider.GetSettings(typeof(MockIndexer));
|
|
|
|
|
settings.Enable = true;
|
|
|
|
|
indexerProvider.SaveSettings(settings);
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
2013-01-19 18:19:29 +00:00
|
|
|
|
|
2011-07-08 05:41:08 +00:00
|
|
|
|
indexerProvider.All();
|
2011-06-02 21:06:46 +00:00
|
|
|
|
|
|
|
|
|
|
2011-07-08 05:41:08 +00:00
|
|
|
|
indexerProvider.All().Should().HaveCount(1);
|
2011-06-02 21:06:46 +00:00
|
|
|
|
indexerProvider.GetEnabledIndexers().Should().HaveCount(1);
|
2011-04-22 19:16:52 +00:00
|
|
|
|
}
|
2011-05-26 04:25:59 +00:00
|
|
|
|
|
|
|
|
|
[Test]
|
2011-05-27 02:12:28 +00:00
|
|
|
|
public void Init_indexer_with_disabled_job()
|
2011-05-26 04:25:59 +00:00
|
|
|
|
{
|
2013-01-19 23:55:58 +00:00
|
|
|
|
WithRealDb();
|
2011-05-26 04:25:59 +00:00
|
|
|
|
|
2013-01-19 05:14:12 +00:00
|
|
|
|
Mocker.SetConstant<IEnumerable<IndexerBase>>(new List<IndexerBase> { Mocker.Resolve<MockIndexer>() });
|
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
var indexerProvider = Mocker.Resolve<IndexerProvider>();
|
2013-01-19 05:14:12 +00:00
|
|
|
|
|
2011-05-27 02:12:28 +00:00
|
|
|
|
var settings = indexerProvider.GetSettings(typeof(MockIndexer));
|
|
|
|
|
settings.Enable = false;
|
|
|
|
|
indexerProvider.SaveSettings(settings);
|
2011-05-26 04:25:59 +00:00
|
|
|
|
|
2013-01-19 18:19:29 +00:00
|
|
|
|
|
2011-06-02 21:06:46 +00:00
|
|
|
|
|
2011-07-08 05:41:08 +00:00
|
|
|
|
indexerProvider.All().Should().HaveCount(1);
|
2011-06-02 21:06:46 +00:00
|
|
|
|
indexerProvider.GetEnabledIndexers().Should().BeEmpty();
|
2011-05-26 04:25:59 +00:00
|
|
|
|
}
|
2012-04-14 22:33:58 +00:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Init_indexer_should_enable_indexer_that_is_enabled_by_default()
|
|
|
|
|
{
|
2013-01-19 23:55:58 +00:00
|
|
|
|
WithRealDb();
|
2012-04-14 22:33:58 +00:00
|
|
|
|
|
2013-01-19 05:14:12 +00:00
|
|
|
|
Mocker.SetConstant<IEnumerable<IndexerBase>>(new List<IndexerBase> { Mocker.Resolve<DefaultEnabledIndexer>() });
|
|
|
|
|
|
2012-04-14 22:33:58 +00:00
|
|
|
|
var indexerProvider = Mocker.Resolve<IndexerProvider>();
|
2013-01-19 05:14:12 +00:00
|
|
|
|
|
2012-04-14 22:33:58 +00:00
|
|
|
|
|
2013-01-19 18:19:29 +00:00
|
|
|
|
|
2012-04-14 22:33:58 +00:00
|
|
|
|
indexerProvider.All();
|
|
|
|
|
indexerProvider.All().Should().HaveCount(1);
|
|
|
|
|
indexerProvider.GetEnabledIndexers().Should().HaveCount(1);
|
|
|
|
|
indexerProvider.GetSettings(typeof(DefaultEnabledIndexer)).Enable.Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Init_indexer_should_not_enable_indexer_that_is_not_enabled_by_default()
|
|
|
|
|
{
|
2013-01-19 23:55:58 +00:00
|
|
|
|
WithRealDb();
|
2012-04-14 22:33:58 +00:00
|
|
|
|
|
2013-01-19 05:14:12 +00:00
|
|
|
|
Mocker.SetConstant<IEnumerable<IndexerBase>>(new List<IndexerBase> { Mocker.Resolve<MockIndexer>() });
|
|
|
|
|
|
2012-04-14 22:33:58 +00:00
|
|
|
|
var indexerProvider = Mocker.Resolve<IndexerProvider>();
|
2013-01-19 05:14:12 +00:00
|
|
|
|
|
2012-04-14 22:33:58 +00:00
|
|
|
|
|
2013-01-19 18:19:29 +00:00
|
|
|
|
|
2012-04-14 22:33:58 +00:00
|
|
|
|
indexerProvider.All();
|
|
|
|
|
indexerProvider.All().Should().HaveCount(1);
|
|
|
|
|
indexerProvider.GetEnabledIndexers().Should().HaveCount(0);
|
|
|
|
|
indexerProvider.GetSettings(typeof(MockIndexer)).Enable.Should().BeFalse();
|
|
|
|
|
}
|
2011-04-19 00:12:06 +00:00
|
|
|
|
}
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
2011-05-20 04:21:18 +00:00
|
|
|
|
public class MockIndexer : IndexerBase
|
2011-04-19 00:12:06 +00:00
|
|
|
|
{
|
2011-05-26 04:25:59 +00:00
|
|
|
|
public MockIndexer(HttpProvider httpProvider, ConfigProvider configProvider)
|
|
|
|
|
: base(httpProvider, configProvider)
|
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
|
|
|
|
|
2012-02-01 01:37:36 +00:00
|
|
|
|
public override bool IsConfigured
|
|
|
|
|
{
|
|
|
|
|
get { return true; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-29 06:49:38 +00:00
|
|
|
|
protected override NetworkCredential Credentials
|
|
|
|
|
{
|
|
|
|
|
get { return null; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override IList<string> GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber)
|
2011-05-26 04:25:59 +00:00
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-29 06:49:38 +00:00
|
|
|
|
protected override IList<string> GetDailyEpisodeSearchUrls(string seriesTitle, DateTime date)
|
2011-04-25 20:21:52 +00:00
|
|
|
|
{
|
2011-11-29 06:49:38 +00:00
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override IList<string> GetSeasonSearchUrls(string seriesTitle, int seasonNumber)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override IList<string> GetPartialSeasonSearchUrls(string seriesTitle, int seasonNumber, int episodeWildcard)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
2011-04-25 20:21:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
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-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
|
|
|
|
}
|
2012-05-02 19:02:39 +00:00
|
|
|
|
|
|
|
|
|
protected override string NzbInfoUrl(SyndicationItem item)
|
|
|
|
|
{
|
2012-05-02 22:42:21 +00:00
|
|
|
|
return item.Links[0].Uri.ToString();
|
2012-05-02 19:02:39 +00:00
|
|
|
|
}
|
2011-01-29 06:10:22 +00:00
|
|
|
|
}
|
2011-04-25 17:48:16 +00:00
|
|
|
|
|
2011-05-20 04:21:18 +00:00
|
|
|
|
public class TestUrlIndexer : IndexerBase
|
2011-04-25 17:48:16 +00:00
|
|
|
|
{
|
2011-05-26 04:25:59 +00:00
|
|
|
|
public TestUrlIndexer(HttpProvider httpProvider, ConfigProvider configProvider)
|
|
|
|
|
: base(httpProvider, configProvider)
|
2011-04-25 17:48:16 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "All Urls"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override string[] Urls
|
|
|
|
|
{
|
2012-12-10 04:50:05 +00:00
|
|
|
|
get { return new[] { "http://rss.nzbs.com/rss.php?cat=TV" }; }
|
2011-04-25 17:48:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-01 01:37:36 +00:00
|
|
|
|
public override bool IsConfigured
|
|
|
|
|
{
|
|
|
|
|
get { return true; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-29 06:49:38 +00:00
|
|
|
|
protected override IList<string> GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override IList<string> GetDailyEpisodeSearchUrls(string seriesTitle, DateTime date)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override IList<string> GetSeasonSearchUrls(string seriesTitle, int seasonNumber)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override IList<string> GetPartialSeasonSearchUrls(string seriesTitle, int seasonNumber, int episodeWildcard)
|
2011-05-26 04:25:59 +00:00
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-25 17:48:16 +00:00
|
|
|
|
protected override string NzbDownloadUrl(SyndicationItem item)
|
|
|
|
|
{
|
|
|
|
|
return "http://google.com";
|
|
|
|
|
}
|
2012-05-02 19:02:39 +00:00
|
|
|
|
|
|
|
|
|
protected override string NzbInfoUrl(SyndicationItem item)
|
|
|
|
|
{
|
|
|
|
|
return "http://google.com";
|
|
|
|
|
}
|
2011-04-25 17:48:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-20 04:21:18 +00:00
|
|
|
|
public class CustomParserIndexer : IndexerBase
|
2011-04-25 20:21:52 +00:00
|
|
|
|
{
|
2011-05-26 04:25:59 +00:00
|
|
|
|
public CustomParserIndexer(HttpProvider httpProvider, ConfigProvider configProvider)
|
|
|
|
|
: base(httpProvider, configProvider)
|
2011-04-25 20:21:52 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "Custom parser"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override string[] Urls
|
|
|
|
|
{
|
|
|
|
|
get { return new[] { "http://www.google.com" }; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-01 01:37:36 +00:00
|
|
|
|
public override bool IsConfigured
|
|
|
|
|
{
|
|
|
|
|
get { return true; }
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-29 06:49:38 +00:00
|
|
|
|
protected override IList<string> GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override IList<string> GetDailyEpisodeSearchUrls(string seriesTitle, DateTime date)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override IList<string> GetSeasonSearchUrls(string seriesTitle, int seasonNumber)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override IList<string> GetPartialSeasonSearchUrls(string seriesTitle, int seasonNumber, int episodeWildcard)
|
2011-05-26 04:25:59 +00:00
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-25 20:21:52 +00:00
|
|
|
|
protected override string NzbDownloadUrl(SyndicationItem item)
|
|
|
|
|
{
|
|
|
|
|
return "http://www.google.com";
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-02 19:02:39 +00:00
|
|
|
|
protected override string NzbInfoUrl(SyndicationItem item)
|
|
|
|
|
{
|
|
|
|
|
return "http://www.google.com";
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-18 02:00:44 +00:00
|
|
|
|
protected override EpisodeParseResult CustomParser(SyndicationItem item, EpisodeParseResult currentResult)
|
2011-04-25 20:21:52 +00:00
|
|
|
|
{
|
2011-05-20 04:18:51 +00:00
|
|
|
|
if (currentResult == null) currentResult = new EpisodeParseResult();
|
2011-05-28 19:23:35 +00:00
|
|
|
|
currentResult.Language = LanguageType.Finnish;
|
2011-04-25 20:21:52 +00:00
|
|
|
|
return currentResult;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-01 01:37:36 +00:00
|
|
|
|
public class NotConfiguredIndexer : IndexerBase
|
|
|
|
|
{
|
|
|
|
|
public NotConfiguredIndexer(HttpProvider httpProvider, ConfigProvider configProvider)
|
|
|
|
|
: base(httpProvider, configProvider)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "NotConfiguredIndexer"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override string[] Urls
|
|
|
|
|
{
|
2012-12-10 04:50:05 +00:00
|
|
|
|
get { return new[] { "http://rss.nzbs.com/rss.php?cat=TV" }; }
|
2012-02-01 01:37:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool IsConfigured
|
|
|
|
|
{
|
|
|
|
|
get { return false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override IList<string> GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override IList<string> GetDailyEpisodeSearchUrls(string seriesTitle, DateTime date)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override IList<string> GetSeasonSearchUrls(string seriesTitle, int seasonNumber)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override IList<string> GetPartialSeasonSearchUrls(string seriesTitle, int seasonNumber, int episodeWildcard)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override string NzbDownloadUrl(SyndicationItem item)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
2012-05-02 19:02:39 +00:00
|
|
|
|
|
|
|
|
|
protected override string NzbInfoUrl(SyndicationItem item)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
2012-02-01 01:37:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-04-14 22:33:58 +00:00
|
|
|
|
public class DefaultEnabledIndexer : IndexerBase
|
|
|
|
|
{
|
|
|
|
|
public DefaultEnabledIndexer(HttpProvider httpProvider, ConfigProvider configProvider)
|
|
|
|
|
: base(httpProvider, configProvider)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override string[] Urls
|
|
|
|
|
{
|
|
|
|
|
get { return new[] { "www.google.com" }; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool IsConfigured
|
|
|
|
|
{
|
|
|
|
|
get { return true; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override NetworkCredential Credentials
|
|
|
|
|
{
|
|
|
|
|
get { return null; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override IList<string> GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override IList<string> GetDailyEpisodeSearchUrls(string seriesTitle, DateTime date)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override IList<string> GetSeasonSearchUrls(string seriesTitle, int seasonNumber)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override IList<string> GetPartialSeasonSearchUrls(string seriesTitle, int seasonNumber, int episodeWildcard)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "Mocked Indexer"; }
|
|
|
|
|
}
|
2012-05-02 19:02:39 +00:00
|
|
|
|
|
2012-04-14 22:33:58 +00:00
|
|
|
|
protected override string NzbDownloadUrl(SyndicationItem item)
|
|
|
|
|
{
|
|
|
|
|
return item.Links[0].Uri.ToString();
|
|
|
|
|
}
|
2012-05-02 19:02:39 +00:00
|
|
|
|
|
|
|
|
|
protected override string NzbInfoUrl(SyndicationItem item)
|
|
|
|
|
{
|
|
|
|
|
return item.Links[1].Uri.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-14 22:33:58 +00:00
|
|
|
|
public override bool EnabledByDefault
|
|
|
|
|
{
|
|
|
|
|
get { return true; }
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-04-10 02:44:01 +00:00
|
|
|
|
}
|