sonarr-repo-only/NzbDrone.Core.Test/IndexerProviderTest.cs

169 lines
4.8 KiB
C#
Raw Normal View History

2011-05-22 16:53:21 +00:00
// ReSharper disable RedundantUsingDirective
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.ServiceModel.Syndication;
using AutoMoq;
using FizzWare.NBuilder;
using Moq;
2011-06-02 21:06:46 +00:00
using NUnit.Framework;
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.Providers.ExternalNotification;
using NzbDrone.Core.Providers.Indexer;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
using NzbDrone.Core.Test.Framework;
2011-06-02 21:06:46 +00:00
using FluentAssertions;
namespace NzbDrone.Core.Test
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class IndexerProviderTest : TestBase
{
[Test]
public void Init_indexer_test()
{
var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository());
//Act
var indexerProvider = mocker.Resolve<IndexerProvider>();
indexerProvider.InitializeIndexers(new List<IndexerBase> { mocker.Resolve<MockIndexer>() });
var settings = indexerProvider.GetSettings(typeof(MockIndexer));
settings.Enable = true;
indexerProvider.SaveSettings(settings);
//Assert
2011-06-02 21:06:46 +00:00
indexerProvider.GetAllISettings();
indexerProvider.GetAllISettings().Should().HaveCount(1);
indexerProvider.GetEnabledIndexers().Should().HaveCount(1);
2011-04-22 19:16:52 +00:00
}
[Test]
public void Init_indexer_with_disabled_job()
{
var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository());
//Act
var indexerProvider = mocker.Resolve<IndexerProvider>();
indexerProvider.InitializeIndexers(new List<IndexerBase> { mocker.Resolve<MockIndexer>() });
var settings = indexerProvider.GetSettings(typeof(MockIndexer));
settings.Enable = false;
indexerProvider.SaveSettings(settings);
//Assert
2011-06-02 21:06:46 +00:00
indexerProvider.GetAllISettings().Should().HaveCount(1);
indexerProvider.GetEnabledIndexers().Should().BeEmpty();
}
}
public class MockIndexer : IndexerBase
{
public MockIndexer(HttpProvider httpProvider, ConfigProvider configProvider)
: base(httpProvider, configProvider)
{
}
protected override string[] Urls
{
get { return new[] { "www.google.com" }; }
}
protected override IList<string> GetSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber)
{
throw new NotImplementedException();
}
protected override NetworkCredential Credentials
{
get { return null; }
}
public override string Name
{
get { return "Mocked Indexer"; }
}
protected override string NzbDownloadUrl(SyndicationItem item)
{
return item.Links[0].Uri.ToString();
}
}
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.nzbmatrix.com/rss.php?cat=TV" }; }
}
protected override IList<string> GetSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber)
{
throw new NotImplementedException();
}
protected override string NzbDownloadUrl(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"; }
}
2011-05-20 04:18:51 +00:00
protected override string[] Urls
{
get { return new[] { "http://www.google.com" }; }
}
protected override IList<string> GetSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber)
{
throw new NotImplementedException();
}
protected override string NzbDownloadUrl(SyndicationItem item)
{
return "http://www.google.com";
}
protected override Model.EpisodeParseResult CustomParser(SyndicationItem item, Model.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;
}
}
2011-04-10 02:44:01 +00:00
}