From 6393d0a3f931211b18f69f6ef58d9583e91c14c4 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Thu, 7 Jul 2011 22:41:08 -0700 Subject: [PATCH] Added Tests for CentralDispatch --- NzbDrone.Core.Test/CentralDispatchTest.cs | 94 +++++++++++++++++++ NzbDrone.Core.Test/Framework/Fixtures.cs | 21 +++-- NzbDrone.Core.Test/Framework/TestBase.cs | 2 + NzbDrone.Core.Test/IndexerProviderTest.cs | 6 +- NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 4 + NzbDrone.Core.Test/QualityProfileTest.cs | 7 +- NzbDrone.Core.Test/packages.config | 1 + NzbDrone.Core/CentralDispatch.cs | 4 +- NzbDrone.Core/Datastore/MigrationLogger.cs | 2 +- NzbDrone.Core/Providers/IndexerProvider.cs | 6 +- NzbDrone.Core/Providers/QualityProvider.cs | 4 +- .../Controllers/AddSeriesController.cs | 6 +- NzbDrone.Web/Controllers/SeriesController.cs | 2 +- .../Controllers/SettingsController.cs | 4 +- NzbDrone.Web/Controllers/SystemController.cs | 2 +- 15 files changed, 133 insertions(+), 32 deletions(-) create mode 100644 NzbDrone.Core.Test/CentralDispatchTest.cs diff --git a/NzbDrone.Core.Test/CentralDispatchTest.cs b/NzbDrone.Core.Test/CentralDispatchTest.cs new file mode 100644 index 000000000..3df09023d --- /dev/null +++ b/NzbDrone.Core.Test/CentralDispatchTest.cs @@ -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 indexers = typeof(CentralDispatch).Assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(IndexerBase))).ToList(); + readonly IList 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(); + + jobs.Should().NotBeEmpty(); + + registeredJobs.Should().HaveSameCount(jobs); + } + + + [Test] + public void All_indexers_should_be_registered() + { + //Assert + + var registeredIndexers = CentralDispatch.NinjectKernel.GetAll(); + + indexers.Should().NotBeEmpty(); + + registeredIndexers.Should().HaveSameCount(indexers); + } + + + [Test] + public void jobs_are_initialized() + { + CentralDispatch.NinjectKernel.Get().All().Should().HaveSameCount(jobs); + } + + [Test] + public void indexers_are_initialized() + { + CentralDispatch.NinjectKernel.Get().All().Should().HaveSameCount(indexers); + } + + [Test] + public void quality_profile_initialized() + { + CentralDispatch.NinjectKernel.Get().All().Should().HaveCount(2); + } + + [Test] + public void get_version() + { + CentralDispatch.Version.Should().NotBeNull(); + } + } +} diff --git a/NzbDrone.Core.Test/Framework/Fixtures.cs b/NzbDrone.Core.Test/Framework/Fixtures.cs index 156fa50c2..4d16f35ba 100644 --- a/NzbDrone.Core.Test/Framework/Fixtures.cs +++ b/NzbDrone.Core.Test/Framework/Fixtures.cs @@ -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 { } + } } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/Framework/TestBase.cs b/NzbDrone.Core.Test/Framework/TestBase.cs index 53f2c57b6..900d071a5 100644 --- a/NzbDrone.Core.Test/Framework/TestBase.cs +++ b/NzbDrone.Core.Test/Framework/TestBase.cs @@ -10,6 +10,8 @@ namespace NzbDrone.Core.Test.Framework public void Setup() { ExceptionVerification.Reset(); + + } [TearDown] diff --git a/NzbDrone.Core.Test/IndexerProviderTest.cs b/NzbDrone.Core.Test/IndexerProviderTest.cs index c6e0cdf59..a586ab5f7 100644 --- a/NzbDrone.Core.Test/IndexerProviderTest.cs +++ b/NzbDrone.Core.Test/IndexerProviderTest.cs @@ -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(); } } diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 8d17c7745..e933c681c 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -56,6 +56,9 @@ ..\packages\Moq.4.0.10827\lib\NET40\Moq.dll + + ..\packages\Ninject.2.2.1.4\lib\net40-Full\Ninject.dll + False ..\Libraries\NLog.dll @@ -85,6 +88,7 @@ + diff --git a/NzbDrone.Core.Test/QualityProfileTest.cs b/NzbDrone.Core.Test/QualityProfileTest.cs index 186356dad..b1973c7c0 100644 --- a/NzbDrone.Core.Test/QualityProfileTest.cs +++ b/NzbDrone.Core.Test/QualityProfileTest.cs @@ -17,9 +17,6 @@ namespace NzbDrone.Core.Test // ReSharper disable InconsistentNaming public class QualityProfileTest : TestBase { - /// - /// Test_s the storage. - /// [Test] public void Test_Storage() { @@ -141,7 +138,7 @@ namespace NzbDrone.Core.Test mocker.Resolve().SetupDefaultProfiles(); //Assert - var profiles = mocker.Resolve().GetAllProfiles(); + var profiles = mocker.Resolve().All(); profiles.Should().HaveCount(2); @@ -165,7 +162,7 @@ namespace NzbDrone.Core.Test mocker.Resolve().SetupDefaultProfiles(); //Assert - var profiles = mocker.Resolve().GetAllProfiles(); + var profiles = mocker.Resolve().All(); profiles.Should().HaveCount(1); diff --git a/NzbDrone.Core.Test/packages.config b/NzbDrone.Core.Test/packages.config index 9e1b92dfa..fe6b20152 100644 --- a/NzbDrone.Core.Test/packages.config +++ b/NzbDrone.Core.Test/packages.config @@ -7,4 +7,5 @@ + \ No newline at end of file diff --git a/NzbDrone.Core/CentralDispatch.cs b/NzbDrone.Core/CentralDispatch.cs index eaa1d1cd4..6d9f15f4b 100644 --- a/NzbDrone.Core/CentralDispatch.cs +++ b/NzbDrone.Core/CentralDispatch.cs @@ -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) { diff --git a/NzbDrone.Core/Datastore/MigrationLogger.cs b/NzbDrone.Core/Datastore/MigrationLogger.cs index f9adaa38e..84ceb5fd3 100644 --- a/NzbDrone.Core/Datastore/MigrationLogger.cs +++ b/NzbDrone.Core/Datastore/MigrationLogger.cs @@ -67,7 +67,7 @@ namespace NzbDrone.Core.Datastore public void Trace(string format, params object[] args) { - Logger.Trace(format, args); + //Logger.Trace(format, args); } } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/IndexerProvider.cs b/NzbDrone.Core/Providers/IndexerProvider.cs index 85eebd11d..e82b19ef5 100644 --- a/NzbDrone.Core/Providers/IndexerProvider.cs +++ b/NzbDrone.Core/Providers/IndexerProvider.cs @@ -30,11 +30,11 @@ namespace NzbDrone.Core.Providers public virtual IList 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 GetAllISettings() + public virtual List All() { return _database.Fetch(); } @@ -64,7 +64,7 @@ namespace NzbDrone.Core.Providers _indexers = indexers; - var currentIndexers = GetAllISettings(); + var currentIndexers = All(); foreach (var feedProvider in indexers) { diff --git a/NzbDrone.Core/Providers/QualityProvider.cs b/NzbDrone.Core/Providers/QualityProvider.cs index b7ba8ebe4..33660adbf 100644 --- a/NzbDrone.Core/Providers/QualityProvider.cs +++ b/NzbDrone.Core/Providers/QualityProvider.cs @@ -44,7 +44,7 @@ namespace NzbDrone.Core.Providers _database.Delete(profileId); } - public virtual List GetAllProfiles() + public virtual List All() { var profiles = _database.Fetch().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"); diff --git a/NzbDrone.Web/Controllers/AddSeriesController.cs b/NzbDrone.Web/Controllers/AddSeriesController.cs index 5e9769eb5..4caf1d731 100644 --- a/NzbDrone.Web/Controllers/AddSeriesController.cs +++ b/NzbDrone.Web/Controllers/AddSeriesController.cs @@ -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, diff --git a/NzbDrone.Web/Controllers/SeriesController.cs b/NzbDrone.Web/Controllers/SeriesController.cs index 1dbb80a99..61c1a53f9 100644 --- a/NzbDrone.Web/Controllers/SeriesController.cs +++ b/NzbDrone.Web/Controllers/SeriesController.cs @@ -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(); diff --git a/NzbDrone.Web/Controllers/SettingsController.cs b/NzbDrone.Web/Controllers/SettingsController.cs index dd2c71a1a..bbb237f29 100644 --- a/NzbDrone.Web/Controllers/SettingsController.cs +++ b/NzbDrone.Web/Controllers/SettingsController.cs @@ -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"); diff --git a/NzbDrone.Web/Controllers/SystemController.cs b/NzbDrone.Web/Controllers/SystemController.cs index f31f3db6e..3a9966ca7 100644 --- a/NzbDrone.Web/Controllers/SystemController.cs +++ b/NzbDrone.Web/Controllers/SystemController.cs @@ -33,7 +33,7 @@ namespace NzbDrone.Web.Controllers public ActionResult Indexers() { - return View(_indexerProvider.GetAllISettings()); + return View(_indexerProvider.All()); }