Added Tests for CentralDispatch
This commit is contained in:
parent
c339ea6ba2
commit
6393d0a3f9
|
@ -0,0 +1,94 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Providers.Indexer;
|
||||
using NzbDrone.Core.Providers.Jobs;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using Ninject;
|
||||
|
||||
namespace NzbDrone.Core.Test
|
||||
{
|
||||
[TestFixture]
|
||||
// ReSharper disable InconsistentNaming
|
||||
class CentralDispatchTest : TestBase
|
||||
{
|
||||
readonly IList<Type> indexers = typeof(CentralDispatch).Assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(IndexerBase))).ToList();
|
||||
readonly IList<Type> jobs = typeof(CentralDispatch).Assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IJob))).ToList();
|
||||
|
||||
|
||||
[Test]
|
||||
public void InitAppTest()
|
||||
{
|
||||
CentralDispatch.NinjectKernel.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Resolve_all_providers()
|
||||
{
|
||||
var providers = typeof(CentralDispatch).Assembly.GetTypes().Where(t => t.Name.EndsWith("Provider")).ToList();
|
||||
|
||||
providers.Should().NotBeEmpty();
|
||||
|
||||
foreach (var provider in providers)
|
||||
{
|
||||
Console.WriteLine("Resolving " + provider.Name);
|
||||
CentralDispatch.NinjectKernel.Get(provider).Should().NotBeNull();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void All_jobs_should_be_registered()
|
||||
{
|
||||
//Assert
|
||||
|
||||
var registeredJobs = CentralDispatch.NinjectKernel.GetAll<IJob>();
|
||||
|
||||
jobs.Should().NotBeEmpty();
|
||||
|
||||
registeredJobs.Should().HaveSameCount(jobs);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void All_indexers_should_be_registered()
|
||||
{
|
||||
//Assert
|
||||
|
||||
var registeredIndexers = CentralDispatch.NinjectKernel.GetAll<IndexerBase>();
|
||||
|
||||
indexers.Should().NotBeEmpty();
|
||||
|
||||
registeredIndexers.Should().HaveSameCount(indexers);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void jobs_are_initialized()
|
||||
{
|
||||
CentralDispatch.NinjectKernel.Get<JobProvider>().All().Should().HaveSameCount(jobs);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void indexers_are_initialized()
|
||||
{
|
||||
CentralDispatch.NinjectKernel.Get<IndexerProvider>().All().Should().HaveSameCount(indexers);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void quality_profile_initialized()
|
||||
{
|
||||
CentralDispatch.NinjectKernel.Get<QualityProvider>().All().Should().HaveCount(2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void get_version()
|
||||
{
|
||||
CentralDispatch.Version.Should().NotBeNull();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,15 +13,7 @@ namespace NzbDrone.Core.Test
|
|||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
var filesToDelete = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sdf", SearchOption.AllDirectories);
|
||||
foreach (var file in filesToDelete)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(file);
|
||||
}
|
||||
catch{}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
|
@ -42,6 +34,17 @@ namespace NzbDrone.Core.Test
|
|||
{
|
||||
Console.WriteLine("Unable to configure logging. " + e);
|
||||
}
|
||||
|
||||
|
||||
var filesToDelete = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sdf", SearchOption.AllDirectories);
|
||||
foreach (var file in filesToDelete)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(file);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,6 +10,8 @@ namespace NzbDrone.Core.Test.Framework
|
|||
public void Setup()
|
||||
{
|
||||
ExceptionVerification.Reset();
|
||||
|
||||
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
|
|
|
@ -33,10 +33,10 @@ namespace NzbDrone.Core.Test
|
|||
indexerProvider.SaveSettings(settings);
|
||||
|
||||
//Assert
|
||||
indexerProvider.GetAllISettings();
|
||||
indexerProvider.All();
|
||||
|
||||
|
||||
indexerProvider.GetAllISettings().Should().HaveCount(1);
|
||||
indexerProvider.All().Should().HaveCount(1);
|
||||
indexerProvider.GetEnabledIndexers().Should().HaveCount(1);
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ namespace NzbDrone.Core.Test
|
|||
|
||||
//Assert
|
||||
|
||||
indexerProvider.GetAllISettings().Should().HaveCount(1);
|
||||
indexerProvider.All().Should().HaveCount(1);
|
||||
indexerProvider.GetEnabledIndexers().Should().BeEmpty();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,6 +56,9 @@
|
|||
<Reference Include="Moq, Version=4.0.10827.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Ninject, Version=2.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Ninject.2.2.1.4\lib\net40-Full\Ninject.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Libraries\NLog.dll</HintPath>
|
||||
|
@ -85,6 +88,7 @@
|
|||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CentralDispatchTest.cs" />
|
||||
<Compile Include="DiskScanProviderTest.cs" />
|
||||
<Compile Include="EpisodeProviderTest_GetEpisodesByParseResult.cs" />
|
||||
<Compile Include="DiskScanProviderTest_ImportFile.cs" />
|
||||
|
|
|
@ -17,9 +17,6 @@ namespace NzbDrone.Core.Test
|
|||
// ReSharper disable InconsistentNaming
|
||||
public class QualityProfileTest : TestBase
|
||||
{
|
||||
///<summary>
|
||||
/// Test_s the storage.
|
||||
///</summary>
|
||||
[Test]
|
||||
public void Test_Storage()
|
||||
{
|
||||
|
@ -141,7 +138,7 @@ namespace NzbDrone.Core.Test
|
|||
mocker.Resolve<QualityProvider>().SetupDefaultProfiles();
|
||||
|
||||
//Assert
|
||||
var profiles = mocker.Resolve<QualityProvider>().GetAllProfiles();
|
||||
var profiles = mocker.Resolve<QualityProvider>().All();
|
||||
|
||||
|
||||
profiles.Should().HaveCount(2);
|
||||
|
@ -165,7 +162,7 @@ namespace NzbDrone.Core.Test
|
|||
mocker.Resolve<QualityProvider>().SetupDefaultProfiles();
|
||||
|
||||
//Assert
|
||||
var profiles = mocker.Resolve<QualityProvider>().GetAllProfiles();
|
||||
var profiles = mocker.Resolve<QualityProvider>().All();
|
||||
|
||||
|
||||
profiles.Should().HaveCount(1);
|
||||
|
|
|
@ -7,4 +7,5 @@
|
|||
<package id="Unity" version="2.1.505.0" />
|
||||
<package id="NUnit" version="2.5.10.11092" />
|
||||
<package id="SqlServerCompact" version="4.0.8482.1" />
|
||||
<package id="Ninject" version="2.2.1.4" />
|
||||
</packages>
|
|
@ -52,7 +52,7 @@ namespace NzbDrone.Core
|
|||
}
|
||||
}
|
||||
|
||||
private static void InitializeApp()
|
||||
public static void InitializeApp()
|
||||
{
|
||||
BindKernel();
|
||||
|
||||
|
@ -67,7 +67,7 @@ namespace NzbDrone.Core
|
|||
BindExternalNotifications();
|
||||
}
|
||||
|
||||
public static void BindKernel()
|
||||
private static void BindKernel()
|
||||
{
|
||||
lock (KernelLock)
|
||||
{
|
||||
|
|
|
@ -67,7 +67,7 @@ namespace NzbDrone.Core.Datastore
|
|||
|
||||
public void Trace(string format, params object[] args)
|
||||
{
|
||||
Logger.Trace(format, args);
|
||||
//Logger.Trace(format, args);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -30,11 +30,11 @@ namespace NzbDrone.Core.Providers
|
|||
|
||||
public virtual IList<IndexerBase> GetEnabledIndexers()
|
||||
{
|
||||
var all = GetAllISettings();
|
||||
var all = All();
|
||||
return _indexers.Where(i => all.Exists(c => c.IndexProviderType == i.GetType().ToString() && c.Enable)).ToList();
|
||||
}
|
||||
|
||||
public virtual List<IndexerDefinition> GetAllISettings()
|
||||
public virtual List<IndexerDefinition> All()
|
||||
{
|
||||
return _database.Fetch<IndexerDefinition>();
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ namespace NzbDrone.Core.Providers
|
|||
|
||||
_indexers = indexers;
|
||||
|
||||
var currentIndexers = GetAllISettings();
|
||||
var currentIndexers = All();
|
||||
|
||||
foreach (var feedProvider in indexers)
|
||||
{
|
||||
|
|
|
@ -44,7 +44,7 @@ namespace NzbDrone.Core.Providers
|
|||
_database.Delete<QualityProfile>(profileId);
|
||||
}
|
||||
|
||||
public virtual List<QualityProfile> GetAllProfiles()
|
||||
public virtual List<QualityProfile> All()
|
||||
{
|
||||
var profiles = _database.Fetch<QualityProfile>().ToList();
|
||||
|
||||
|
@ -58,7 +58,7 @@ namespace NzbDrone.Core.Providers
|
|||
|
||||
public virtual void SetupDefaultProfiles()
|
||||
{
|
||||
if (GetAllProfiles().Count != 0)
|
||||
if (All().Count != 0)
|
||||
return;
|
||||
|
||||
Logger.Info("Setting up default quality profiles");
|
||||
|
|
|
@ -52,7 +52,7 @@ namespace NzbDrone.Web.Controllers
|
|||
ViewData["RootDirs"] = _rootFolderProvider.GetAll().Select(c => c.Path).OrderBy(e => e).ToList();
|
||||
|
||||
var defaultQuality = _configProvider.DefaultQualityProfile;
|
||||
var qualityProfiles = _qualityProvider.GetAllProfiles();
|
||||
var qualityProfiles = _qualityProvider.All();
|
||||
|
||||
ViewData["qualityList"] = qualityProfiles;
|
||||
|
||||
|
@ -69,7 +69,7 @@ namespace NzbDrone.Web.Controllers
|
|||
{
|
||||
var rootDirs = _rootFolderProvider.GetAll();
|
||||
|
||||
var profiles = _qualityProvider.GetAllProfiles();
|
||||
var profiles = _qualityProvider.All();
|
||||
var defaultQuality = Convert.ToInt32(_configProvider.DefaultQualityProfile);
|
||||
var selectList = new SelectList(profiles, "QualityProfileId", "Name", defaultQuality);
|
||||
ViewData["qualities"] = selectList;
|
||||
|
@ -106,7 +106,7 @@ namespace NzbDrone.Web.Controllers
|
|||
ViewData["javaPath"] = path.Replace(Path.DirectorySeparatorChar, '|').Replace(Path.VolumeSeparatorChar, '^').Replace('\'', '`');
|
||||
|
||||
var defaultQuality = _configProvider.DefaultQualityProfile;
|
||||
var qualityProfiles = _qualityProvider.GetAllProfiles();
|
||||
var qualityProfiles = _qualityProvider.All();
|
||||
|
||||
ViewData["quality"] = new SelectList(
|
||||
qualityProfiles,
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace NzbDrone.Web.Controllers
|
|||
|
||||
public ActionResult Index()
|
||||
{
|
||||
var profiles = _qualityProvider.GetAllProfiles();
|
||||
var profiles = _qualityProvider.All();
|
||||
ViewData["SelectList"] = new SelectList(profiles, "QualityProfileId", "Name");
|
||||
|
||||
return View();
|
||||
|
|
|
@ -116,7 +116,7 @@ namespace NzbDrone.Web.Controllers
|
|||
|
||||
ViewData["Qualities"] = qualityTypes;
|
||||
|
||||
var profiles = _qualityProvider.GetAllProfiles().ToList();
|
||||
var profiles = _qualityProvider.All().ToList();
|
||||
|
||||
foreach (var qualityProfile in profiles)
|
||||
{
|
||||
|
@ -229,7 +229,7 @@ namespace NzbDrone.Web.Controllers
|
|||
|
||||
public QualityModel GetUpdatedProfileList()
|
||||
{
|
||||
var profiles = _qualityProvider.GetAllProfiles().ToList();
|
||||
var profiles = _qualityProvider.All().ToList();
|
||||
var defaultQualityQualityProfileId =
|
||||
Convert.ToInt32(_configProvider.GetValue("DefaultQualityProfile", profiles[0].QualityProfileId));
|
||||
var selectList = new SelectList(profiles, "QualityProfileId", "Name");
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace NzbDrone.Web.Controllers
|
|||
|
||||
public ActionResult Indexers()
|
||||
{
|
||||
return View(_indexerProvider.GetAllISettings());
|
||||
return View(_indexerProvider.All());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue