mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 21:43:33 -07:00
Adding some structure to NzbDrone.Core.Test
This commit is contained in:
parent
ae1a32b874
commit
e5c4f34e0e
41 changed files with 1673 additions and 1745 deletions
163
NzbDrone.Core.Test/ProviderTests/IndexerProviderTest.cs
Normal file
163
NzbDrone.Core.Test/ProviderTests/IndexerProviderTest.cs
Normal file
|
@ -0,0 +1,163 @@
|
|||
// ReSharper disable RedundantUsingDirective
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.ServiceModel.Syndication;
|
||||
using AutoMoq;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Model;
|
||||
using NzbDrone.Core.Model.Search;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
using NzbDrone.Core.Providers.Indexer;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests
|
||||
{
|
||||
[TestFixture]
|
||||
// ReSharper disable InconsistentNaming
|
||||
public class IndexerProviderTest : TestBase
|
||||
{
|
||||
[Test]
|
||||
public void Init_indexer_test()
|
||||
{
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
||||
|
||||
//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
|
||||
indexerProvider.All();
|
||||
|
||||
|
||||
indexerProvider.All().Should().HaveCount(1);
|
||||
indexerProvider.GetEnabledIndexers().Should().HaveCount(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Init_indexer_with_disabled_job()
|
||||
{
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
||||
|
||||
//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
|
||||
|
||||
indexerProvider.All().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(SearchModel searchModel)
|
||||
{
|
||||
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(SearchModel searchModel)
|
||||
{
|
||||
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"; }
|
||||
}
|
||||
|
||||
protected override string[] Urls
|
||||
{
|
||||
get { return new[] { "http://www.google.com" }; }
|
||||
}
|
||||
|
||||
protected override IList<string> GetSearchUrls(SearchModel searchModel)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override string NzbDownloadUrl(SyndicationItem item)
|
||||
{
|
||||
return "http://www.google.com";
|
||||
}
|
||||
|
||||
protected override EpisodeParseResult CustomParser(SyndicationItem item, EpisodeParseResult currentResult)
|
||||
{
|
||||
if (currentResult == null) currentResult = new EpisodeParseResult();
|
||||
currentResult.Language = LanguageType.Finnish;
|
||||
return currentResult;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue