From 653f45f10efac85641adb29cc492a1fde440587d Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sat, 19 Jan 2013 10:54:00 -0800 Subject: [PATCH] more test fixes. --- .../JobProviderTests/JobProviderFixture.cs | 24 ------------ NzbDrone.Core.Test/QualityProfileTest.cs | 37 +++++++++---------- NzbDrone.Core/ContainerExtentions.cs | 17 ++++----- NzbDrone.Core/Providers/NewznabProvider.cs | 1 - 4 files changed, 24 insertions(+), 55 deletions(-) diff --git a/NzbDrone.Core.Test/ProviderTests/JobProviderTests/JobProviderFixture.cs b/NzbDrone.Core.Test/ProviderTests/JobProviderTests/JobProviderFixture.cs index 8004685c5..d0130a30f 100644 --- a/NzbDrone.Core.Test/ProviderTests/JobProviderTests/JobProviderFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/JobProviderTests/JobProviderFixture.cs @@ -251,30 +251,6 @@ namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests timers[0].Enable.Should().BeTrue(); } - [Test] - public void Init_Timers_only_registers_once() - { - for (int i = 0; i < 2; i++) - { - var fakeTimer = new FakeJob(); - IEnumerable BaseFakeJobs = new List { fakeTimer }; - - Mocker.SetConstant(BaseFakeJobs); - - Mocker.Resolve(); - } - - var Mocker2 = new AutoMoqer(); - - Mocker2.SetConstant(Db); - var assertjobProvider = Mocker2.Resolve(); - var timers = assertjobProvider.All(); - - - timers.Should().HaveCount(1); - timers[0].Enable.Should().BeTrue(); - } - [Test] public void inti_should_removed_jobs_that_no_longer_exist() { diff --git a/NzbDrone.Core.Test/QualityProfileTest.cs b/NzbDrone.Core.Test/QualityProfileTest.cs index 8c13a0677..8c1b91d9e 100644 --- a/NzbDrone.Core.Test/QualityProfileTest.cs +++ b/NzbDrone.Core.Test/QualityProfileTest.cs @@ -15,7 +15,7 @@ namespace NzbDrone.Core.Test { [TestFixture] // ReSharper disable InconsistentNaming - public class QualityProfileTest : CoreTest + public class QualityProfileTest : CoreTest { [Test] public void Test_Storage() @@ -29,11 +29,11 @@ namespace NzbDrone.Core.Test Allowed = new List { QualityTypes.HDTV720p, QualityTypes.DVD }, }; - + var id = Convert.ToInt32(database.Insert(testProfile)); var fetch = database.SingleOrDefault(id); - + Assert.AreEqual(id, fetch.QualityProfileId); Assert.AreEqual(testProfile.Name, fetch.Name); Assert.AreEqual(testProfile.Cutoff, fetch.Cutoff); @@ -52,11 +52,11 @@ namespace NzbDrone.Core.Test Cutoff = QualityTypes.SDTV }; - + var id = Convert.ToInt32(database.Insert(testProfile)); var fetch = database.SingleOrDefault(id); - + Assert.AreEqual(id, fetch.QualityProfileId); Assert.AreEqual(testProfile.Name, fetch.Name); Assert.AreEqual(testProfile.Cutoff, fetch.Cutoff); @@ -68,7 +68,7 @@ namespace NzbDrone.Core.Test public void Update_Success() { //Arrange - + var db = TestDbHelper.GetEmptyDatabase(); Mocker.SetConstant(db); @@ -78,7 +78,7 @@ namespace NzbDrone.Core.Test Cutoff = QualityTypes.SDTV }; - + var id = Convert.ToInt32(db.Insert(testProfile)); var currentProfile = db.SingleOrDefault(id); @@ -89,7 +89,7 @@ namespace NzbDrone.Core.Test var updated = Mocker.Resolve().Get(currentProfile.QualityProfileId); - + updated.Name.Should().Be(currentProfile.Name); updated.Cutoff.Should().Be(QualityTypes.Bluray720p); updated.AllowedString.Should().Be(currentProfile.AllowedString); @@ -130,14 +130,14 @@ namespace NzbDrone.Core.Test [Test] public void SetupInitial_should_add_two_profiles() { - + var db = TestDbHelper.GetEmptyDatabase(); Mocker.SetConstant(db); - + Mocker.Resolve(); - + var profiles = Mocker.Resolve().All(); @@ -152,19 +152,16 @@ namespace NzbDrone.Core.Test //We don't want to keep adding them back if a user deleted them on purpose. public void SetupInitial_should_skip_if_any_profile_exists() { - - var db = TestDbHelper.GetEmptyDatabase(); - Mocker.SetConstant(db); - var fakeProfile = Builder.CreateNew().With(p => p.Cutoff = QualityTypes.DVD).With(p => p.Allowed = new List { QualityTypes.SDTV, QualityTypes.DVD }).Build(); + WithRealDb(); - - Mocker.Resolve().Add(fakeProfile); + InitiateSubject(); - - var profiles = Mocker.Resolve().All(); + var profiles = Subject.All(); + Subject.Delete(profiles[0].QualityProfileId); + InitiateSubject(); - profiles.Should().HaveCount(1); + Subject.All().Should().HaveCount(profiles.Count - 1); } } } \ No newline at end of file diff --git a/NzbDrone.Core/ContainerExtentions.cs b/NzbDrone.Core/ContainerExtentions.cs index 22960f641..84a76818a 100644 --- a/NzbDrone.Core/ContainerExtentions.cs +++ b/NzbDrone.Core/ContainerExtentions.cs @@ -18,14 +18,13 @@ namespace NzbDrone.Core public static class ContainerExtentions { - private static readonly Logger _logger = LogManager.GetLogger("ServiceRegistration"); + private static readonly Logger logger = LogManager.GetLogger("ServiceRegistration"); public static void RegisterCoreServices(this ContainerBuilder container) { var core = Assembly.Load("NzbDrone.Core"); var common = Assembly.Load("NzbDrone.Common"); - container.RegisterAssembly(core); container.RegisterAssembly(common); @@ -44,27 +43,25 @@ namespace NzbDrone.Core .SingleInstance(); container.RegisterAssemblyTypes(assembly) - .Where(t => t.BaseType == typeof(IndexerBase)) + .Where(t => t.IsSubclassOf(typeof(IndexerBase))) .As().SingleInstance(); container.RegisterAssemblyTypes(assembly) - .Where(t => t.BaseType == typeof(SearchBase)) + .Where(t => t.IsSubclassOf(typeof(SearchBase))) .As().SingleInstance(); container.RegisterAssemblyTypes(assembly) - .Where(t => t.BaseType == typeof(ExternalNotificationBase)) + .Where(t => t.IsSubclassOf(typeof(ExternalNotificationBase))) .As().SingleInstance(); container.RegisterAssemblyTypes(assembly) - .Where(t => t.BaseType == typeof(MetadataBase)) + .Where(t => t.IsSubclassOf(typeof(MetadataBase))) .As().SingleInstance(); } - - - + private static void InitDatabase(this ContainerBuilder container) { - _logger.Info("Registering Database..."); + logger.Info("Registering Database..."); var appDataPath = new EnvironmentProvider().GetAppDataPath(); if (!Directory.Exists(appDataPath)) Directory.CreateDirectory(appDataPath); diff --git a/NzbDrone.Core/Providers/NewznabProvider.cs b/NzbDrone.Core/Providers/NewznabProvider.cs index e3957ba81..6e9e6bf9e 100644 --- a/NzbDrone.Core/Providers/NewznabProvider.cs +++ b/NzbDrone.Core/Providers/NewznabProvider.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Net; using NLog; -using NzbDrone.Core.Providers.Indexer; using NzbDrone.Core.Repository; using PetaPoco;