1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-28 02:40:01 +00:00
Radarr/NzbDrone.Core.Test/Indexers/IndexerServiceTest.cs

367 lines
11 KiB
C#
Raw Normal View History

2011-05-22 16:53:21 +00:00
// ReSharper disable RedundantUsingDirective
2011-05-22 16:53:21 +00:00
using System;
using System.Collections.Generic;
using System.Net;
using System.ServiceModel.Syndication;
2011-06-18 02:00:44 +00:00
using FluentAssertions;
2013-02-21 07:07:34 +00:00
using Moq;
2011-06-02 21:06:46 +00:00
using NUnit.Framework;
2012-02-11 00:48:20 +00:00
using NzbDrone.Common;
2013-02-21 07:07:34 +00:00
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Indexers.Providers;
2011-05-20 04:18:51 +00:00
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
2011-04-04 03:50:12 +00:00
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.AutoMoq;
2013-02-21 07:07:34 +00:00
namespace NzbDrone.Core.Test.Indexers
{
[TestFixture]
// ReSharper disable InconsistentNaming
2013-02-21 07:07:34 +00:00
public class IndexerServiceTest : CoreTest
{
[Test]
public void Init_indexer_test()
{
2013-01-19 05:14:12 +00:00
Mocker.SetConstant<IEnumerable<IndexerBase>>(new List<IndexerBase> { Mocker.Resolve<MockIndexer>() });
2013-02-21 07:07:34 +00:00
//Mocker.GetMock<IIndexerRepository>()
// .Setup(s => s.Find(typeof(MockIndexer)))
// .Returns()
2013-02-21 07:07:34 +00:00
Mocker.Resolve<IndexerService>();
2011-06-02 21:06:46 +00:00
2013-02-21 07:07:34 +00:00
Mocker.GetMock<IIndexerRepository>()
.Verify(v => v.Insert(It.IsAny<Indexer>()), Times.Once());
2011-04-22 19:16:52 +00:00
}
[Test]
2013-02-21 07:07:34 +00:00
public void getEnabled_should_not_return_any_when_no_indexers_are_enabled()
{
2013-01-19 05:14:12 +00:00
Mocker.SetConstant<IEnumerable<IndexerBase>>(new List<IndexerBase> { Mocker.Resolve<MockIndexer>() });
2013-02-21 07:07:34 +00:00
Mocker.GetMock<IIndexerRepository>()
.Setup(s => s.All())
.Returns(new List<Indexer> {new Indexer {OID = 1, Type = "", Enable = false, Name = "Fake Indexer"}});
2013-01-19 05:14:12 +00:00
2013-02-21 07:07:34 +00:00
Mocker.Resolve<IndexerService>().GetEnabledIndexers().Should().BeEmpty();
}
[Test]
public void Init_indexer_should_enable_indexer_that_is_enabled_by_default()
{
2013-01-19 05:14:12 +00:00
Mocker.SetConstant<IEnumerable<IndexerBase>>(new List<IndexerBase> { Mocker.Resolve<DefaultEnabledIndexer>() });
2013-02-21 07:07:34 +00:00
Mocker.Resolve<IndexerService>();
2013-01-19 05:14:12 +00:00
2013-02-21 07:07:34 +00:00
Mocker.GetMock<IIndexerRepository>()
.Verify(v => v.Insert(It.Is<Indexer>(indexer => indexer.Enable)), Times.Once());
2013-02-21 07:07:34 +00:00
Mocker.GetMock<IIndexerRepository>()
.Verify(v => v.Insert(It.Is<Indexer>(indexer => !indexer.Enable)), Times.Never());
}
[Test]
public void Init_indexer_should_not_enable_indexer_that_is_not_enabled_by_default()
{
2013-01-19 05:14:12 +00:00
Mocker.SetConstant<IEnumerable<IndexerBase>>(new List<IndexerBase> { Mocker.Resolve<MockIndexer>() });
2013-02-21 07:07:34 +00:00
Mocker.Resolve<IndexerService>();
2013-01-19 05:14:12 +00:00
2013-02-21 07:07:34 +00:00
Mocker.GetMock<IIndexerRepository>()
.Verify(v => v.Insert(It.Is<Indexer>(indexer => indexer.Enable)), Times.Never());
2013-02-21 07:07:34 +00:00
Mocker.GetMock<IIndexerRepository>()
.Verify(v => v.Insert(It.Is<Indexer>(indexer => !indexer.Enable)), Times.Once());
}
}
public class MockIndexer : IndexerBase
{
public MockIndexer(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"; }
}
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[0].Uri.ToString();
2012-05-02 19:02:39 +00:00
}
}
public class TestUrlIndexer : IndexerBase
{
public TestUrlIndexer(HttpProvider httpProvider, ConfigProvider configProvider)
: base(httpProvider, configProvider)
{
}
public override string Name
{
get { return "All Urls"; }
}
protected override string[] Urls
{
get { return new[] { "http://rss.nzbs.com/rss.php?cat=TV" }; }
}
public override bool IsConfigured
{
get { return true; }
}
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)
{
return "http://google.com";
}
2012-05-02 19:02:39 +00:00
protected override string NzbInfoUrl(SyndicationItem item)
{
return "http://google.com";
}
}
public class CustomParserIndexer : IndexerBase
{
public CustomParserIndexer(HttpProvider httpProvider, ConfigProvider configProvider)
: base(httpProvider, configProvider)
{
}
public override string Name
{
get { return "Custom parser"; }
}
protected override string[] Urls
{
get { return new[] { "http://www.google.com" }; }
}
public override bool IsConfigured
{
get { return true; }
}
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)
{
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-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;
return currentResult;
}
}
public class NotConfiguredIndexer : IndexerBase
{
public NotConfiguredIndexer(HttpProvider httpProvider, ConfigProvider configProvider)
: base(httpProvider, configProvider)
{
}
public override string Name
{
get { return "NotConfiguredIndexer"; }
}
protected override string[] Urls
{
get { return new[] { "http://rss.nzbs.com/rss.php?cat=TV" }; }
}
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();
}
}
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
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();
}
public override bool EnabledByDefault
{
get { return true; }
}
}
2011-04-10 02:44:01 +00:00
}