mirror of https://github.com/Radarr/Radarr
Cleaned up IndexerService and tests
This commit is contained in:
parent
5b50aa5d59
commit
563db453fc
|
@ -20,17 +20,13 @@ namespace NzbDrone.Core.Test.Indexers
|
|||
{
|
||||
[TestFixture]
|
||||
// ReSharper disable InconsistentNaming
|
||||
public class IndexerServiceTest : CoreTest
|
||||
public class IndexerServiceTest : CoreTest<IndexerService>
|
||||
{
|
||||
[Test]
|
||||
public void Init_indexer_test()
|
||||
{
|
||||
Mocker.SetConstant<IEnumerable<IndexerBase>>(new List<IndexerBase> { Mocker.Resolve<MockIndexer>() });
|
||||
|
||||
//Mocker.GetMock<IIndexerRepository>()
|
||||
// .Setup(s => s.Find(typeof(MockIndexer)))
|
||||
// .Returns()
|
||||
|
||||
Mocker.Resolve<IndexerService>();
|
||||
|
||||
Mocker.GetMock<IIndexerRepository>()
|
||||
|
@ -46,7 +42,7 @@ namespace NzbDrone.Core.Test.Indexers
|
|||
.Setup(s => s.All())
|
||||
.Returns(new List<Indexer> {new Indexer {OID = 1, Type = "", Enable = false, Name = "Fake Indexer"}});
|
||||
|
||||
Mocker.Resolve<IndexerService>().GetEnabledIndexers().Should().BeEmpty();
|
||||
Subject.GetEnabledIndexers().Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Indexers.Providers;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
using PetaPoco;
|
||||
|
||||
namespace NzbDrone.Core.Indexers
|
||||
|
@ -15,19 +16,41 @@ namespace NzbDrone.Core.Indexers
|
|||
Indexer GetSettings(Type type);
|
||||
}
|
||||
|
||||
public class IndexerService : IIndexerService
|
||||
public class IndexerService : IIndexerService, IInitializable
|
||||
{
|
||||
private readonly IIndexerRepository _indexerRepository;
|
||||
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
private readonly Logger _logger;
|
||||
|
||||
private IList<IndexerBase> _indexers;
|
||||
|
||||
public IndexerService(IIndexerRepository indexerRepository, IEnumerable<IndexerBase> indexers)
|
||||
public IndexerService(IIndexerRepository indexerRepository, IEnumerable<IndexerBase> indexers, Logger logger)
|
||||
{
|
||||
_indexerRepository = indexerRepository;
|
||||
_logger = logger;
|
||||
_indexers = indexers.ToList();
|
||||
InitializeIndexers();
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
_logger.Debug("Initializing indexers. Count {0}", _indexers.Count);
|
||||
|
||||
var currentIndexers = All();
|
||||
|
||||
foreach (var feedProvider in _indexers)
|
||||
{
|
||||
IndexerBase indexerLocal = feedProvider;
|
||||
if (!currentIndexers.Exists(c => c.Type == indexerLocal.GetType().ToString()))
|
||||
{
|
||||
var settings = new Indexer
|
||||
{
|
||||
Enable = indexerLocal.EnabledByDefault,
|
||||
Type = indexerLocal.GetType().ToString(),
|
||||
Name = indexerLocal.Name
|
||||
};
|
||||
|
||||
_indexerRepository.Insert(settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Indexer> All()
|
||||
|
@ -43,45 +66,14 @@ namespace NzbDrone.Core.Indexers
|
|||
|
||||
public void SaveSettings(Indexer indexer)
|
||||
{
|
||||
if (indexer.OID == 0)
|
||||
{
|
||||
Logger.Debug("Adding Indexer definitions for {0}", indexer.Name);
|
||||
_indexerRepository.Insert(indexer);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Debug("Updating Indexer definitions for {0}", indexer.Name);
|
||||
_indexerRepository.Update(indexer);
|
||||
}
|
||||
//Todo: This will be used in the API
|
||||
_logger.Debug("Upserting Indexer definitions for {0}", indexer.Name);
|
||||
_indexerRepository.Upsert(indexer);
|
||||
}
|
||||
|
||||
public Indexer GetSettings(Type type)
|
||||
{
|
||||
return _indexerRepository.Find(type);
|
||||
}
|
||||
|
||||
private void InitializeIndexers()
|
||||
{
|
||||
Logger.Debug("Initializing indexers. Count {0}", _indexers.Count);
|
||||
|
||||
|
||||
var currentIndexers = All();
|
||||
|
||||
foreach (var feedProvider in _indexers)
|
||||
{
|
||||
IndexerBase indexerLocal = feedProvider;
|
||||
if (!currentIndexers.Exists(c => c.Type == indexerLocal.GetType().ToString()))
|
||||
{
|
||||
var settings = new Indexer
|
||||
{
|
||||
Enable = indexerLocal.EnabledByDefault,
|
||||
Type = indexerLocal.GetType().ToString(),
|
||||
Name = indexerLocal.Name
|
||||
};
|
||||
|
||||
SaveSettings(settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -36,7 +36,6 @@ namespace NzbDrone.Core.Jobs
|
|||
|
||||
private ProgressNotification _notification;
|
||||
|
||||
|
||||
public JobController(NotificationProvider notificationProvider, IEnumerable<IJob> jobs, IJobRepository jobRepository, Logger logger)
|
||||
{
|
||||
StopWatch = new Stopwatch();
|
||||
|
@ -61,7 +60,6 @@ namespace NzbDrone.Core.Jobs
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public virtual void QueueScheduled()
|
||||
{
|
||||
lock (_executionLock)
|
||||
|
@ -260,7 +258,5 @@ namespace NzbDrone.Core.Jobs
|
|||
_logger.Trace("resetting queue processor thread");
|
||||
_jobThread = new Thread(ProcessQueue) { Name = "JobQueueThread" };
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -279,7 +279,7 @@
|
|||
<Compile Include="Jobs\RefreshEpsiodeMetadata.cs" />
|
||||
<Compile Include="Jobs\PastWeekBacklogSearchJob.cs" />
|
||||
<Compile Include="Jobs\SearchHistoryCleanupJob.cs" />
|
||||
<Compile Include="Lifecycle\IInitilizable.cs" />
|
||||
<Compile Include="Lifecycle\IInitializable.cs" />
|
||||
<Compile Include="Model\HistoryQueryModel.cs" />
|
||||
<Compile Include="Model\DownloadClientType.cs" />
|
||||
<Compile Include="Instrumentation\LogProvider.cs" />
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
<FileVersion>1</FileVersion>
|
||||
<AutoEnableOnStartup>False</AutoEnableOnStartup>
|
||||
<AllowParallelTestExecution>true</AllowParallelTestExecution>
|
||||
<AllowTestsToRunInParallelWithThemselves>true</AllowTestsToRunInParallelWithThemselves>
|
||||
<FrameworkUtilisationTypeForNUnit>UseDynamicAnalysis</FrameworkUtilisationTypeForNUnit>
|
||||
<FrameworkUtilisationTypeForGallio>Disabled</FrameworkUtilisationTypeForGallio>
|
||||
<FrameworkUtilisationTypeForMSpec>Disabled</FrameworkUtilisationTypeForMSpec>
|
||||
|
|
Loading…
Reference in New Issue