2011-05-22 19:53:21 +03:00
|
|
|
// ReSharper disable RedundantUsingDirective
|
2011-10-21 02:42:17 +03:00
|
|
|
|
2011-05-22 19:53:21 +03:00
|
|
|
using System;
|
2011-04-19 03:12:06 +03:00
|
|
|
using System.Collections.Generic;
|
2011-04-25 23:21:52 +03:00
|
|
|
using System.Net;
|
2011-04-19 03:12:06 +03:00
|
|
|
using System.ServiceModel.Syndication;
|
2011-06-18 05:00:44 +03:00
|
|
|
using FluentAssertions;
|
2013-02-21 10:07:34 +03:00
|
|
|
using Moq;
|
2011-06-03 00:06:46 +03:00
|
|
|
using NUnit.Framework;
|
2012-02-11 03:48:20 +03:00
|
|
|
using NzbDrone.Common;
|
2013-02-24 09:48:52 +03:00
|
|
|
using NzbDrone.Core.Configuration;
|
2013-02-21 10:07:34 +03:00
|
|
|
using NzbDrone.Core.Indexers;
|
2011-05-20 07:18:51 +03:00
|
|
|
using NzbDrone.Core.Model;
|
2011-01-29 08:10:22 +02:00
|
|
|
using NzbDrone.Core.Providers;
|
2011-04-04 06:50:12 +03:00
|
|
|
using NzbDrone.Core.Providers.Core;
|
2011-05-19 06:55:35 +03:00
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-11-14 03:22:18 +03:00
|
|
|
using NzbDrone.Test.Common.AutoMoq;
|
2011-01-29 08:10:22 +02:00
|
|
|
|
2013-02-21 10:07:34 +03:00
|
|
|
namespace NzbDrone.Core.Test.Indexers
|
2011-01-29 08:10:22 +02:00
|
|
|
{
|
|
|
|
[TestFixture]
|
2011-04-19 03:12:06 +03:00
|
|
|
// ReSharper disable InconsistentNaming
|
2013-02-21 19:38:31 +03:00
|
|
|
public class IndexerServiceTest : CoreTest<IndexerService>
|
2011-01-29 08:10:22 +02:00
|
|
|
{
|
2011-04-19 03:12:06 +03:00
|
|
|
[Test]
|
2013-02-23 05:16:45 +03:00
|
|
|
public void should_insert_indexer_in_repository_when_it_doesnt_exist()
|
2011-04-19 03:12:06 +03:00
|
|
|
{
|
2013-01-19 08:14:12 +03:00
|
|
|
Mocker.SetConstant<IEnumerable<IndexerBase>>(new List<IndexerBase> { Mocker.Resolve<MockIndexer>() });
|
|
|
|
|
2013-02-23 05:16:45 +03:00
|
|
|
Subject.Init();
|
2011-06-03 00:06:46 +03:00
|
|
|
|
2013-02-21 10:07:34 +03:00
|
|
|
Mocker.GetMock<IIndexerRepository>()
|
|
|
|
.Verify(v => v.Insert(It.IsAny<Indexer>()), Times.Once());
|
2011-04-22 22:16:52 +03:00
|
|
|
}
|
2011-05-26 07:25:59 +03:00
|
|
|
|
|
|
|
[Test]
|
2013-02-21 10:07:34 +03:00
|
|
|
public void getEnabled_should_not_return_any_when_no_indexers_are_enabled()
|
2011-05-26 07:25:59 +03:00
|
|
|
{
|
2013-01-19 08:14:12 +03:00
|
|
|
Mocker.SetConstant<IEnumerable<IndexerBase>>(new List<IndexerBase> { Mocker.Resolve<MockIndexer>() });
|
|
|
|
|
2013-02-21 10:07:34 +03:00
|
|
|
Mocker.GetMock<IIndexerRepository>()
|
|
|
|
.Setup(s => s.All())
|
2013-02-26 06:58:57 +03:00
|
|
|
.Returns(new List<Indexer> {new Indexer {Id = 1, Type = "", Enable = false, Name = "Fake Indexer"}});
|
2013-01-19 08:14:12 +03:00
|
|
|
|
2013-02-21 19:38:31 +03:00
|
|
|
Subject.GetEnabledIndexers().Should().BeEmpty();
|
2011-05-26 07:25:59 +03:00
|
|
|
}
|
2012-04-15 01:33:58 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Init_indexer_should_enable_indexer_that_is_enabled_by_default()
|
|
|
|
{
|
2013-01-19 08:14:12 +03:00
|
|
|
Mocker.SetConstant<IEnumerable<IndexerBase>>(new List<IndexerBase> { Mocker.Resolve<DefaultEnabledIndexer>() });
|
|
|
|
|
2013-02-23 05:16:45 +03:00
|
|
|
Subject.Init();
|
2013-01-19 08:14:12 +03:00
|
|
|
|
2013-02-21 10:07:34 +03:00
|
|
|
Mocker.GetMock<IIndexerRepository>()
|
|
|
|
.Verify(v => v.Insert(It.Is<Indexer>(indexer => indexer.Enable)), Times.Once());
|
2012-04-15 01:33:58 +03:00
|
|
|
|
2013-02-21 10:07:34 +03:00
|
|
|
Mocker.GetMock<IIndexerRepository>()
|
|
|
|
.Verify(v => v.Insert(It.Is<Indexer>(indexer => !indexer.Enable)), Times.Never());
|
2012-04-15 01:33:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Init_indexer_should_not_enable_indexer_that_is_not_enabled_by_default()
|
|
|
|
{
|
2013-01-19 08:14:12 +03:00
|
|
|
Mocker.SetConstant<IEnumerable<IndexerBase>>(new List<IndexerBase> { Mocker.Resolve<MockIndexer>() });
|
|
|
|
|
2013-02-23 05:16:45 +03:00
|
|
|
Subject.Init();
|
2013-01-19 08:14:12 +03:00
|
|
|
|
2013-02-21 10:07:34 +03:00
|
|
|
Mocker.GetMock<IIndexerRepository>()
|
|
|
|
.Verify(v => v.Insert(It.Is<Indexer>(indexer => indexer.Enable)), Times.Never());
|
2012-04-15 01:33:58 +03:00
|
|
|
|
2013-02-21 10:07:34 +03:00
|
|
|
Mocker.GetMock<IIndexerRepository>()
|
|
|
|
.Verify(v => v.Insert(It.Is<Indexer>(indexer => !indexer.Enable)), Times.Once());
|
2012-04-15 01:33:58 +03:00
|
|
|
}
|
2011-04-19 03:12:06 +03:00
|
|
|
}
|
2011-01-29 08:10:22 +02:00
|
|
|
|
2011-05-20 07:21:18 +03:00
|
|
|
public class MockIndexer : IndexerBase
|
2011-04-19 03:12:06 +03:00
|
|
|
{
|
2013-02-24 22:57:33 +03:00
|
|
|
public MockIndexer(HttpProvider httpProvider, IConfigService configService)
|
2013-02-24 09:48:52 +03:00
|
|
|
: base(httpProvider, configService)
|
2011-01-29 08:10:22 +02:00
|
|
|
{
|
2011-04-19 03:12:06 +03:00
|
|
|
}
|
2011-01-29 08:10:22 +02:00
|
|
|
|
2011-04-21 04:26:13 +03:00
|
|
|
protected override string[] Urls
|
2011-04-19 03:12:06 +03:00
|
|
|
{
|
|
|
|
get { return new[] { "www.google.com" }; }
|
|
|
|
}
|
2011-01-29 08:10:22 +02:00
|
|
|
|
2012-02-01 04:37:36 +03:00
|
|
|
public override bool IsConfigured
|
|
|
|
{
|
|
|
|
get { return true; }
|
|
|
|
}
|
|
|
|
|
2011-11-29 09:49:38 +03:00
|
|
|
protected override NetworkCredential Credentials
|
|
|
|
{
|
|
|
|
get { return null; }
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override IList<string> GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber)
|
2011-05-26 07:25:59 +03:00
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
2011-11-29 09:49:38 +03:00
|
|
|
protected override IList<string> GetDailyEpisodeSearchUrls(string seriesTitle, DateTime date)
|
2011-04-25 23:21:52 +03:00
|
|
|
{
|
2011-11-29 09:49:38 +03: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 23:21:52 +03:00
|
|
|
}
|
|
|
|
|
2011-04-19 03:12:06 +03:00
|
|
|
public override string Name
|
|
|
|
{
|
|
|
|
get { return "Mocked Indexer"; }
|
|
|
|
}
|
2011-01-29 08:10:22 +02:00
|
|
|
|
2011-04-19 03:12:06 +03:00
|
|
|
protected override string NzbDownloadUrl(SyndicationItem item)
|
|
|
|
{
|
|
|
|
return item.Links[0].Uri.ToString();
|
2011-01-29 08:10:22 +02:00
|
|
|
}
|
2012-05-02 22:02:39 +03:00
|
|
|
|
|
|
|
protected override string NzbInfoUrl(SyndicationItem item)
|
|
|
|
{
|
2012-05-03 01:42:21 +03:00
|
|
|
return item.Links[0].Uri.ToString();
|
2012-05-02 22:02:39 +03:00
|
|
|
}
|
2011-01-29 08:10:22 +02:00
|
|
|
}
|
2011-04-25 20:48:16 +03:00
|
|
|
|
2011-05-20 07:21:18 +03:00
|
|
|
public class TestUrlIndexer : IndexerBase
|
2011-04-25 20:48:16 +03:00
|
|
|
{
|
2013-02-24 22:57:33 +03:00
|
|
|
public TestUrlIndexer(HttpProvider httpProvider, IConfigService configService)
|
2013-02-24 09:48:52 +03:00
|
|
|
: base(httpProvider, configService)
|
2011-04-25 20:48:16 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string Name
|
|
|
|
{
|
|
|
|
get { return "All Urls"; }
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override string[] Urls
|
|
|
|
{
|
2012-12-10 07:50:05 +03:00
|
|
|
get { return new[] { "http://rss.nzbs.com/rss.php?cat=TV" }; }
|
2011-04-25 20:48:16 +03:00
|
|
|
}
|
|
|
|
|
2012-02-01 04:37:36 +03:00
|
|
|
public override bool IsConfigured
|
|
|
|
{
|
|
|
|
get { return true; }
|
|
|
|
}
|
|
|
|
|
2011-11-29 09:49:38 +03: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 07:25:59 +03:00
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
2011-04-25 20:48:16 +03:00
|
|
|
protected override string NzbDownloadUrl(SyndicationItem item)
|
|
|
|
{
|
|
|
|
return "http://google.com";
|
|
|
|
}
|
2012-05-02 22:02:39 +03:00
|
|
|
|
|
|
|
protected override string NzbInfoUrl(SyndicationItem item)
|
|
|
|
{
|
|
|
|
return "http://google.com";
|
|
|
|
}
|
2011-04-25 20:48:16 +03:00
|
|
|
}
|
|
|
|
|
2011-05-20 07:21:18 +03:00
|
|
|
public class CustomParserIndexer : IndexerBase
|
2011-04-25 23:21:52 +03:00
|
|
|
{
|
2013-02-24 22:57:33 +03:00
|
|
|
public CustomParserIndexer(HttpProvider httpProvider, IConfigService configService)
|
2013-02-24 09:48:52 +03:00
|
|
|
: base(httpProvider, configService)
|
2011-04-25 23:21:52 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string Name
|
|
|
|
{
|
|
|
|
get { return "Custom parser"; }
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override string[] Urls
|
|
|
|
{
|
|
|
|
get { return new[] { "http://www.google.com" }; }
|
|
|
|
}
|
|
|
|
|
2012-02-01 04:37:36 +03:00
|
|
|
public override bool IsConfigured
|
|
|
|
{
|
|
|
|
get { return true; }
|
|
|
|
}
|
|
|
|
|
2011-11-29 09:49:38 +03: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 07:25:59 +03:00
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
2011-04-25 23:21:52 +03:00
|
|
|
protected override string NzbDownloadUrl(SyndicationItem item)
|
|
|
|
{
|
|
|
|
return "http://www.google.com";
|
|
|
|
}
|
|
|
|
|
2012-05-02 22:02:39 +03:00
|
|
|
protected override string NzbInfoUrl(SyndicationItem item)
|
|
|
|
{
|
|
|
|
return "http://www.google.com";
|
|
|
|
}
|
|
|
|
|
2011-06-18 05:00:44 +03:00
|
|
|
protected override EpisodeParseResult CustomParser(SyndicationItem item, EpisodeParseResult currentResult)
|
2011-04-25 23:21:52 +03:00
|
|
|
{
|
2011-05-20 07:18:51 +03:00
|
|
|
if (currentResult == null) currentResult = new EpisodeParseResult();
|
2011-05-28 22:23:35 +03:00
|
|
|
currentResult.Language = LanguageType.Finnish;
|
2011-04-25 23:21:52 +03:00
|
|
|
return currentResult;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-01 04:37:36 +03:00
|
|
|
public class NotConfiguredIndexer : IndexerBase
|
|
|
|
{
|
2013-02-24 22:57:33 +03:00
|
|
|
public NotConfiguredIndexer(HttpProvider httpProvider, IConfigService configService)
|
2013-02-24 09:48:52 +03:00
|
|
|
: base(httpProvider, configService)
|
2012-02-01 04:37:36 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string Name
|
|
|
|
{
|
|
|
|
get { return "NotConfiguredIndexer"; }
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override string[] Urls
|
|
|
|
{
|
2012-12-10 07:50:05 +03:00
|
|
|
get { return new[] { "http://rss.nzbs.com/rss.php?cat=TV" }; }
|
2012-02-01 04:37:36 +03: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 22:02:39 +03:00
|
|
|
|
|
|
|
protected override string NzbInfoUrl(SyndicationItem item)
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
2012-02-01 04:37:36 +03:00
|
|
|
}
|
|
|
|
|
2012-04-15 01:33:58 +03:00
|
|
|
public class DefaultEnabledIndexer : IndexerBase
|
|
|
|
{
|
2013-02-24 22:57:33 +03:00
|
|
|
public DefaultEnabledIndexer(HttpProvider httpProvider, IConfigService configService)
|
2013-02-24 09:48:52 +03:00
|
|
|
: base(httpProvider, configService)
|
2012-04-15 01:33:58 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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 22:02:39 +03:00
|
|
|
|
2012-04-15 01:33:58 +03:00
|
|
|
protected override string NzbDownloadUrl(SyndicationItem item)
|
|
|
|
{
|
|
|
|
return item.Links[0].Uri.ToString();
|
|
|
|
}
|
2012-05-02 22:02:39 +03:00
|
|
|
|
|
|
|
protected override string NzbInfoUrl(SyndicationItem item)
|
|
|
|
{
|
|
|
|
return item.Links[1].Uri.ToString();
|
|
|
|
}
|
|
|
|
|
2012-04-15 01:33:58 +03:00
|
|
|
public override bool EnabledByDefault
|
|
|
|
{
|
|
|
|
get { return true; }
|
|
|
|
}
|
|
|
|
}
|
2011-04-10 05:44:01 +03:00
|
|
|
}
|