Added Tests for CentralDispatch

pull/6/head
kay.one 14 years ago
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] [TearDown]
public void TearDown() public void TearDown()
{ {
var filesToDelete = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sdf", SearchOption.AllDirectories);
foreach (var file in filesToDelete)
{
try
{
File.Delete(file);
}
catch{}
}
} }
[SetUp] [SetUp]
@ -42,6 +34,17 @@ namespace NzbDrone.Core.Test
{ {
Console.WriteLine("Unable to configure logging. " + e); 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() public void Setup()
{ {
ExceptionVerification.Reset(); ExceptionVerification.Reset();
} }
[TearDown] [TearDown]

@ -33,10 +33,10 @@ namespace NzbDrone.Core.Test
indexerProvider.SaveSettings(settings); indexerProvider.SaveSettings(settings);
//Assert //Assert
indexerProvider.GetAllISettings(); indexerProvider.All();
indexerProvider.GetAllISettings().Should().HaveCount(1); indexerProvider.All().Should().HaveCount(1);
indexerProvider.GetEnabledIndexers().Should().HaveCount(1); indexerProvider.GetEnabledIndexers().Should().HaveCount(1);
} }
@ -56,7 +56,7 @@ namespace NzbDrone.Core.Test
//Assert //Assert
indexerProvider.GetAllISettings().Should().HaveCount(1); indexerProvider.All().Should().HaveCount(1);
indexerProvider.GetEnabledIndexers().Should().BeEmpty(); indexerProvider.GetEnabledIndexers().Should().BeEmpty();
} }
} }

@ -56,6 +56,9 @@
<Reference Include="Moq, Version=4.0.10827.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL"> <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> <HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
</Reference> </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"> <Reference Include="NLog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\Libraries\NLog.dll</HintPath> <HintPath>..\Libraries\NLog.dll</HintPath>
@ -85,6 +88,7 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="CentralDispatchTest.cs" />
<Compile Include="DiskScanProviderTest.cs" /> <Compile Include="DiskScanProviderTest.cs" />
<Compile Include="EpisodeProviderTest_GetEpisodesByParseResult.cs" /> <Compile Include="EpisodeProviderTest_GetEpisodesByParseResult.cs" />
<Compile Include="DiskScanProviderTest_ImportFile.cs" /> <Compile Include="DiskScanProviderTest_ImportFile.cs" />

@ -17,9 +17,6 @@ namespace NzbDrone.Core.Test
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
public class QualityProfileTest : TestBase public class QualityProfileTest : TestBase
{ {
///<summary>
/// Test_s the storage.
///</summary>
[Test] [Test]
public void Test_Storage() public void Test_Storage()
{ {
@ -141,7 +138,7 @@ namespace NzbDrone.Core.Test
mocker.Resolve<QualityProvider>().SetupDefaultProfiles(); mocker.Resolve<QualityProvider>().SetupDefaultProfiles();
//Assert //Assert
var profiles = mocker.Resolve<QualityProvider>().GetAllProfiles(); var profiles = mocker.Resolve<QualityProvider>().All();
profiles.Should().HaveCount(2); profiles.Should().HaveCount(2);
@ -165,7 +162,7 @@ namespace NzbDrone.Core.Test
mocker.Resolve<QualityProvider>().SetupDefaultProfiles(); mocker.Resolve<QualityProvider>().SetupDefaultProfiles();
//Assert //Assert
var profiles = mocker.Resolve<QualityProvider>().GetAllProfiles(); var profiles = mocker.Resolve<QualityProvider>().All();
profiles.Should().HaveCount(1); profiles.Should().HaveCount(1);

@ -7,4 +7,5 @@
<package id="Unity" version="2.1.505.0" /> <package id="Unity" version="2.1.505.0" />
<package id="NUnit" version="2.5.10.11092" /> <package id="NUnit" version="2.5.10.11092" />
<package id="SqlServerCompact" version="4.0.8482.1" /> <package id="SqlServerCompact" version="4.0.8482.1" />
<package id="Ninject" version="2.2.1.4" />
</packages> </packages>

@ -52,7 +52,7 @@ namespace NzbDrone.Core
} }
} }
private static void InitializeApp() public static void InitializeApp()
{ {
BindKernel(); BindKernel();
@ -67,7 +67,7 @@ namespace NzbDrone.Core
BindExternalNotifications(); BindExternalNotifications();
} }
public static void BindKernel() private static void BindKernel()
{ {
lock (KernelLock) lock (KernelLock)
{ {

@ -67,7 +67,7 @@ namespace NzbDrone.Core.Datastore
public void Trace(string format, params object[] args) 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() 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(); 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>(); return _database.Fetch<IndexerDefinition>();
} }
@ -64,7 +64,7 @@ namespace NzbDrone.Core.Providers
_indexers = indexers; _indexers = indexers;
var currentIndexers = GetAllISettings(); var currentIndexers = All();
foreach (var feedProvider in indexers) foreach (var feedProvider in indexers)
{ {

@ -44,7 +44,7 @@ namespace NzbDrone.Core.Providers
_database.Delete<QualityProfile>(profileId); _database.Delete<QualityProfile>(profileId);
} }
public virtual List<QualityProfile> GetAllProfiles() public virtual List<QualityProfile> All()
{ {
var profiles = _database.Fetch<QualityProfile>().ToList(); var profiles = _database.Fetch<QualityProfile>().ToList();
@ -58,7 +58,7 @@ namespace NzbDrone.Core.Providers
public virtual void SetupDefaultProfiles() public virtual void SetupDefaultProfiles()
{ {
if (GetAllProfiles().Count != 0) if (All().Count != 0)
return; return;
Logger.Info("Setting up default quality profiles"); 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(); ViewData["RootDirs"] = _rootFolderProvider.GetAll().Select(c => c.Path).OrderBy(e => e).ToList();
var defaultQuality = _configProvider.DefaultQualityProfile; var defaultQuality = _configProvider.DefaultQualityProfile;
var qualityProfiles = _qualityProvider.GetAllProfiles(); var qualityProfiles = _qualityProvider.All();
ViewData["qualityList"] = qualityProfiles; ViewData["qualityList"] = qualityProfiles;
@ -69,7 +69,7 @@ namespace NzbDrone.Web.Controllers
{ {
var rootDirs = _rootFolderProvider.GetAll(); var rootDirs = _rootFolderProvider.GetAll();
var profiles = _qualityProvider.GetAllProfiles(); var profiles = _qualityProvider.All();
var defaultQuality = Convert.ToInt32(_configProvider.DefaultQualityProfile); var defaultQuality = Convert.ToInt32(_configProvider.DefaultQualityProfile);
var selectList = new SelectList(profiles, "QualityProfileId", "Name", defaultQuality); var selectList = new SelectList(profiles, "QualityProfileId", "Name", defaultQuality);
ViewData["qualities"] = selectList; ViewData["qualities"] = selectList;
@ -106,7 +106,7 @@ namespace NzbDrone.Web.Controllers
ViewData["javaPath"] = path.Replace(Path.DirectorySeparatorChar, '|').Replace(Path.VolumeSeparatorChar, '^').Replace('\'', '`'); ViewData["javaPath"] = path.Replace(Path.DirectorySeparatorChar, '|').Replace(Path.VolumeSeparatorChar, '^').Replace('\'', '`');
var defaultQuality = _configProvider.DefaultQualityProfile; var defaultQuality = _configProvider.DefaultQualityProfile;
var qualityProfiles = _qualityProvider.GetAllProfiles(); var qualityProfiles = _qualityProvider.All();
ViewData["quality"] = new SelectList( ViewData["quality"] = new SelectList(
qualityProfiles, qualityProfiles,

@ -41,7 +41,7 @@ namespace NzbDrone.Web.Controllers
public ActionResult Index() public ActionResult Index()
{ {
var profiles = _qualityProvider.GetAllProfiles(); var profiles = _qualityProvider.All();
ViewData["SelectList"] = new SelectList(profiles, "QualityProfileId", "Name"); ViewData["SelectList"] = new SelectList(profiles, "QualityProfileId", "Name");
return View(); return View();

@ -116,7 +116,7 @@ namespace NzbDrone.Web.Controllers
ViewData["Qualities"] = qualityTypes; ViewData["Qualities"] = qualityTypes;
var profiles = _qualityProvider.GetAllProfiles().ToList(); var profiles = _qualityProvider.All().ToList();
foreach (var qualityProfile in profiles) foreach (var qualityProfile in profiles)
{ {
@ -229,7 +229,7 @@ namespace NzbDrone.Web.Controllers
public QualityModel GetUpdatedProfileList() public QualityModel GetUpdatedProfileList()
{ {
var profiles = _qualityProvider.GetAllProfiles().ToList(); var profiles = _qualityProvider.All().ToList();
var defaultQualityQualityProfileId = var defaultQualityQualityProfileId =
Convert.ToInt32(_configProvider.GetValue("DefaultQualityProfile", profiles[0].QualityProfileId)); Convert.ToInt32(_configProvider.GetValue("DefaultQualityProfile", profiles[0].QualityProfileId));
var selectList = new SelectList(profiles, "QualityProfileId", "Name"); var selectList = new SelectList(profiles, "QualityProfileId", "Name");

@ -33,7 +33,7 @@ namespace NzbDrone.Web.Controllers
public ActionResult Indexers() public ActionResult Indexers()
{ {
return View(_indexerProvider.GetAllISettings()); return View(_indexerProvider.All());
} }

Loading…
Cancel
Save