Cleaned up IndexerService and tests
This commit is contained in:
parent
5b50aa5d59
commit
563db453fc
|
@ -20,17 +20,13 @@ namespace NzbDrone.Core.Test.Indexers
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
public class IndexerServiceTest : CoreTest
|
public class IndexerServiceTest : CoreTest<IndexerService>
|
||||||
{
|
{
|
||||||
[Test]
|
[Test]
|
||||||
public void Init_indexer_test()
|
public void Init_indexer_test()
|
||||||
{
|
{
|
||||||
Mocker.SetConstant<IEnumerable<IndexerBase>>(new List<IndexerBase> { Mocker.Resolve<MockIndexer>() });
|
Mocker.SetConstant<IEnumerable<IndexerBase>>(new List<IndexerBase> { Mocker.Resolve<MockIndexer>() });
|
||||||
|
|
||||||
//Mocker.GetMock<IIndexerRepository>()
|
|
||||||
// .Setup(s => s.Find(typeof(MockIndexer)))
|
|
||||||
// .Returns()
|
|
||||||
|
|
||||||
Mocker.Resolve<IndexerService>();
|
Mocker.Resolve<IndexerService>();
|
||||||
|
|
||||||
Mocker.GetMock<IIndexerRepository>()
|
Mocker.GetMock<IIndexerRepository>()
|
||||||
|
@ -46,7 +42,7 @@ namespace NzbDrone.Core.Test.Indexers
|
||||||
.Setup(s => s.All())
|
.Setup(s => s.All())
|
||||||
.Returns(new List<Indexer> {new Indexer {OID = 1, Type = "", Enable = false, Name = "Fake Indexer"}});
|
.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]
|
[Test]
|
||||||
|
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Core.Indexers.Providers;
|
using NzbDrone.Core.Indexers.Providers;
|
||||||
|
using NzbDrone.Core.Lifecycle;
|
||||||
using PetaPoco;
|
using PetaPoco;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Indexers
|
namespace NzbDrone.Core.Indexers
|
||||||
|
@ -15,55 +16,23 @@ namespace NzbDrone.Core.Indexers
|
||||||
Indexer GetSettings(Type type);
|
Indexer GetSettings(Type type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class IndexerService : IIndexerService
|
public class IndexerService : IIndexerService, IInitializable
|
||||||
{
|
{
|
||||||
private readonly IIndexerRepository _indexerRepository;
|
private readonly IIndexerRepository _indexerRepository;
|
||||||
|
private readonly Logger _logger;
|
||||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
||||||
|
|
||||||
private IList<IndexerBase> _indexers;
|
private IList<IndexerBase> _indexers;
|
||||||
|
|
||||||
public IndexerService(IIndexerRepository indexerRepository, IEnumerable<IndexerBase> indexers)
|
public IndexerService(IIndexerRepository indexerRepository, IEnumerable<IndexerBase> indexers, Logger logger)
|
||||||
{
|
{
|
||||||
_indexerRepository = indexerRepository;
|
_indexerRepository = indexerRepository;
|
||||||
|
_logger = logger;
|
||||||
_indexers = indexers.ToList();
|
_indexers = indexers.ToList();
|
||||||
InitializeIndexers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Indexer> All()
|
public void Init()
|
||||||
{
|
{
|
||||||
return _indexerRepository.All().ToList();
|
_logger.Debug("Initializing indexers. Count {0}", _indexers.Count);
|
||||||
}
|
|
||||||
|
|
||||||
public List<IndexerBase> GetEnabledIndexers()
|
|
||||||
{
|
|
||||||
var all = All();
|
|
||||||
return _indexers.Where(i => all.Exists(c => c.Type == i.GetType().ToString() && c.Enable)).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Indexer GetSettings(Type type)
|
|
||||||
{
|
|
||||||
return _indexerRepository.Find(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void InitializeIndexers()
|
|
||||||
{
|
|
||||||
Logger.Debug("Initializing indexers. Count {0}", _indexers.Count);
|
|
||||||
|
|
||||||
|
|
||||||
var currentIndexers = All();
|
var currentIndexers = All();
|
||||||
|
|
||||||
|
@ -79,9 +48,32 @@ namespace NzbDrone.Core.Indexers
|
||||||
Name = indexerLocal.Name
|
Name = indexerLocal.Name
|
||||||
};
|
};
|
||||||
|
|
||||||
SaveSettings(settings);
|
_indexerRepository.Insert(settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Indexer> All()
|
||||||
|
{
|
||||||
|
return _indexerRepository.All().ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<IndexerBase> GetEnabledIndexers()
|
||||||
|
{
|
||||||
|
var all = All();
|
||||||
|
return _indexers.Where(i => all.Exists(c => c.Type == i.GetType().ToString() && c.Enable)).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SaveSettings(Indexer 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -36,7 +36,6 @@ namespace NzbDrone.Core.Jobs
|
||||||
|
|
||||||
private ProgressNotification _notification;
|
private ProgressNotification _notification;
|
||||||
|
|
||||||
|
|
||||||
public JobController(NotificationProvider notificationProvider, IEnumerable<IJob> jobs, IJobRepository jobRepository, Logger logger)
|
public JobController(NotificationProvider notificationProvider, IEnumerable<IJob> jobs, IJobRepository jobRepository, Logger logger)
|
||||||
{
|
{
|
||||||
StopWatch = new Stopwatch();
|
StopWatch = new Stopwatch();
|
||||||
|
@ -61,7 +60,6 @@ namespace NzbDrone.Core.Jobs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public virtual void QueueScheduled()
|
public virtual void QueueScheduled()
|
||||||
{
|
{
|
||||||
lock (_executionLock)
|
lock (_executionLock)
|
||||||
|
@ -260,7 +258,5 @@ namespace NzbDrone.Core.Jobs
|
||||||
_logger.Trace("resetting queue processor thread");
|
_logger.Trace("resetting queue processor thread");
|
||||||
_jobThread = new Thread(ProcessQueue) { Name = "JobQueueThread" };
|
_jobThread = new Thread(ProcessQueue) { Name = "JobQueueThread" };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -279,7 +279,7 @@
|
||||||
<Compile Include="Jobs\RefreshEpsiodeMetadata.cs" />
|
<Compile Include="Jobs\RefreshEpsiodeMetadata.cs" />
|
||||||
<Compile Include="Jobs\PastWeekBacklogSearchJob.cs" />
|
<Compile Include="Jobs\PastWeekBacklogSearchJob.cs" />
|
||||||
<Compile Include="Jobs\SearchHistoryCleanupJob.cs" />
|
<Compile Include="Jobs\SearchHistoryCleanupJob.cs" />
|
||||||
<Compile Include="Lifecycle\IInitilizable.cs" />
|
<Compile Include="Lifecycle\IInitializable.cs" />
|
||||||
<Compile Include="Model\HistoryQueryModel.cs" />
|
<Compile Include="Model\HistoryQueryModel.cs" />
|
||||||
<Compile Include="Model\DownloadClientType.cs" />
|
<Compile Include="Model\DownloadClientType.cs" />
|
||||||
<Compile Include="Instrumentation\LogProvider.cs" />
|
<Compile Include="Instrumentation\LogProvider.cs" />
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
<FileVersion>1</FileVersion>
|
<FileVersion>1</FileVersion>
|
||||||
<AutoEnableOnStartup>False</AutoEnableOnStartup>
|
<AutoEnableOnStartup>False</AutoEnableOnStartup>
|
||||||
<AllowParallelTestExecution>true</AllowParallelTestExecution>
|
<AllowParallelTestExecution>true</AllowParallelTestExecution>
|
||||||
<AllowTestsToRunInParallelWithThemselves>true</AllowTestsToRunInParallelWithThemselves>
|
|
||||||
<FrameworkUtilisationTypeForNUnit>UseDynamicAnalysis</FrameworkUtilisationTypeForNUnit>
|
<FrameworkUtilisationTypeForNUnit>UseDynamicAnalysis</FrameworkUtilisationTypeForNUnit>
|
||||||
<FrameworkUtilisationTypeForGallio>Disabled</FrameworkUtilisationTypeForGallio>
|
<FrameworkUtilisationTypeForGallio>Disabled</FrameworkUtilisationTypeForGallio>
|
||||||
<FrameworkUtilisationTypeForMSpec>Disabled</FrameworkUtilisationTypeForMSpec>
|
<FrameworkUtilisationTypeForMSpec>Disabled</FrameworkUtilisationTypeForMSpec>
|
||||||
|
|
Loading…
Reference in New Issue