diff --git a/NzbDrone.Core.Test/InstrumentationTests/DatabaseTargetFixture.cs b/NzbDrone.Core.Test/InstrumentationTests/DatabaseTargetFixture.cs index afbc2a2f6..4a7eb726b 100644 --- a/NzbDrone.Core.Test/InstrumentationTests/DatabaseTargetFixture.cs +++ b/NzbDrone.Core.Test/InstrumentationTests/DatabaseTargetFixture.cs @@ -33,6 +33,9 @@ public void Setup() Mocker.Resolve(); Mocker.Resolve().Register(); + LogManager.ReconfigExistingLoggers(); + + _logger = LogManager.GetCurrentClassLogger(); _loggerName = _logger.Name.Replace("NzbDrone.",""); diff --git a/NzbDrone.Core.Test/JobTests/AppUpdateJobFixture.cs b/NzbDrone.Core.Test/JobTests/AppUpdateJobFixture.cs index 62921746a..73021d293 100644 --- a/NzbDrone.Core.Test/JobTests/AppUpdateJobFixture.cs +++ b/NzbDrone.Core.Test/JobTests/AppUpdateJobFixture.cs @@ -35,7 +35,7 @@ public void Setup() { Mocker.GetMock().SetupGet(c => c.SystemTemp).Returns(@"C:\Temp\"); Mocker.GetMock().SetupGet(c => c.Guid).Returns(_clientGuid); - Mocker.GetMock().Setup(c => c.GetAvilableUpdate(It.IsAny())).Returns(updatePackage); + Mocker.GetMock().Setup(c => c.GetAvailableUpdate(It.IsAny())).Returns(updatePackage); } @@ -126,7 +126,7 @@ public void should_start_update_client() [Test] public void when_no_updates_are_available_should_return_without_error_or_warnings() { - Mocker.GetMock().Setup(c => c.GetAvilableUpdate(It.IsAny())).Returns((UpdatePackage)null); + Mocker.GetMock().Setup(c => c.GetAvailableUpdate(It.IsAny())).Returns((UpdatePackage)null); StartUpdate(); diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 5f20938c7..ece43a531 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -178,7 +178,7 @@ - + diff --git a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpDropFolderFixture.cs b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpDropFolderFixture.cs index f8334d458..a9fedf483 100644 --- a/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpDropFolderFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/CleanUpDropFolderFixture.cs @@ -1,23 +1,16 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Linq; -using System.Linq.Expressions; using FizzWare.NBuilder; -using FluentAssertions; using Moq; using NUnit.Framework; using NzbDrone.Common; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Organizer; -using NzbDrone.Core.Qualities; using NzbDrone.Core.Tv; -using NzbDrone.Core.Model; using NzbDrone.Core.Providers; using NzbDrone.Core.Test.Framework; -using NzbDrone.Test.Common; -using NzbDrone.Test.Common.AutoMoq; namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests { diff --git a/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/GetAvailableUpdateFixture.cs b/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/GetAvailableUpdateFixture.cs new file mode 100644 index 000000000..e21103daf --- /dev/null +++ b/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/GetAvailableUpdateFixture.cs @@ -0,0 +1,55 @@ +using System; +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Common; +using NzbDrone.Core.Configuration; +using NzbDrone.Core.Providers; +using NzbDrone.Core.Test.Framework; + +namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests +{ + class GetAvailableUpdateFixture : CoreTest + { + private static readonly Version LatestTestVersion = new Version("0.6.0.3"); + private const string LATEST_TEST_URL = "http://update.nzbdrone.com/_test/NzbDrone.master.0.6.0.3.zip"; + private const string LATEST_TEST_FILE_NAME = "NzbDrone.master.0.6.0.3.zip"; + + [SetUp] + public void Setup() + { + Mocker.GetMock().SetupGet(c => c.UpdateUrl).Returns("http://update.nzbdrone.com/_test/"); + Mocker.Resolve(); + } + + [TestCase("0.6.0.9")] + [TestCase("0.7.0.1")] + [TestCase("1.0.0.0")] + public void should_return_null_if_latest_is_lower_than_current_version(string currentVersion) + { + var updatePackage = Subject.GetAvailableUpdate(new Version(currentVersion)); + + updatePackage.Should().BeNull(); + } + + [Test] + public void should_return_null_if_latest_is_equal_to_current_version() + { + var updatePackage = Subject.GetAvailableUpdate(LatestTestVersion); + + updatePackage.Should().BeNull(); + } + + [TestCase("0.0.0.0")] + [TestCase("0.0.0.1")] + [TestCase("0.0.10.10")] + public void should_return_update_if_latest_is_higher_than_current_version(string currentVersion) + { + var updatePackage = Subject.GetAvailableUpdate(new Version(currentVersion)); + + updatePackage.Should().NotBeNull(); + updatePackage.Version.Should().Be(LatestTestVersion); + updatePackage.FileName.Should().BeEquivalentTo(LATEST_TEST_FILE_NAME); + updatePackage.Url.Should().BeEquivalentTo(LATEST_TEST_URL); + } + } +} diff --git a/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/GetAvilableUpdateFixture.cs b/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/GetAvilableUpdateFixture.cs deleted file mode 100644 index e6cf07fb9..000000000 --- a/NzbDrone.Core.Test/ProviderTests/UpdateProviderTests/GetAvilableUpdateFixture.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; - -using FluentAssertions; -using Moq; -using NUnit.Framework; -using NzbDrone.Common; -using NzbDrone.Core.Configuration; -using NzbDrone.Core.Providers; -using NzbDrone.Core.Test.Framework; -using NzbDrone.Test.Common.AutoMoq; - -namespace NzbDrone.Core.Test.ProviderTests.UpdateProviderTests -{ - class GetAvilableUpdateFixture : CoreTest - { - private static Version _latestsTestVersion = new Version("0.6.0.3"); - private static string _latestsTestUrl = "http://update.nzbdrone.com/_test/NzbDrone.master.0.6.0.3.zip"; - private static string _latestsTestFileName = "NzbDrone.master.0.6.0.3.zip"; - - [SetUp] - public void Setup() - { - WithStrictMocker(); - - Mocker.GetMock().SetupGet(c => c.UpdateUrl).Returns("http://update.nzbdrone.com/_test/"); - Mocker.Resolve(); - } - - [TestCase("0.6.0.9")] - [TestCase("0.7.0.1")] - [TestCase("1.0.0.0")] - public void should_return_null_if_latests_is_lower_than_current_version(string currentVersion) - { - - var updatePackage = Mocker.Resolve().GetAvilableUpdate(new Version(currentVersion)); - - updatePackage.Should().BeNull(); - } - - [Test] - public void should_return_null_if_latests_is_equal_to_current_version() - { - var updatePackage = Mocker.Resolve().GetAvilableUpdate(_latestsTestVersion); - - updatePackage.Should().BeNull(); - } - - [TestCase("0.0.0.0")] - [TestCase("0.0.0.1")] - [TestCase("0.0.10.10")] - public void should_return_update_if_latests_is_higher_than_current_version(string currentVersion) - { - var updatePackage = Mocker.Resolve().GetAvilableUpdate(new Version(currentVersion)); - - updatePackage.Should().NotBeNull(); - updatePackage.Version.Should().Be(_latestsTestVersion); - updatePackage.FileName.Should().BeEquivalentTo(_latestsTestFileName); - updatePackage.Url.Should().BeEquivalentTo(_latestsTestUrl); - } - } -} diff --git a/NzbDrone.Core.Test/Qualities/QualityProfileFixture.cs b/NzbDrone.Core.Test/Qualities/QualityProfileFixture.cs index f46cc2401..bc271b733 100644 --- a/NzbDrone.Core.Test/Qualities/QualityProfileFixture.cs +++ b/NzbDrone.Core.Test/Qualities/QualityProfileFixture.cs @@ -1,14 +1,9 @@ - - using System.Linq; -using System; -using System.Collections.Generic; using FizzWare.NBuilder; -using FluentAssertions; using Moq; using NUnit.Framework; +using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Qualities; -using NzbDrone.Core.Tv; using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test.Qualities @@ -20,7 +15,7 @@ public class QualityProfileFixture : CoreTest [Test] public void Init_should_add_two_profiles() { - Subject.Init(); + Subject.Handle(new ApplicationStartedEvent()); Mocker.GetMock() .Verify(v => v.Insert(It.IsAny()), Times.Exactly(2)); @@ -35,7 +30,7 @@ public void Init_should_skip_if_any_profiles_already_exist() .Setup(s => s.All()) .Returns(Builder.CreateListOfSize(2).Build().ToList()); - Subject.Init(); + Subject.Handle(new ApplicationStartedEvent()); Mocker.GetMock() .Verify(v => v.Insert(It.IsAny()), Times.Never()); diff --git a/NzbDrone.Core.Test/Qualities/QualitySizeServiceFixture.cs b/NzbDrone.Core.Test/Qualities/QualitySizeServiceFixture.cs index e59cb1ba5..f3dded938 100644 --- a/NzbDrone.Core.Test/Qualities/QualitySizeServiceFixture.cs +++ b/NzbDrone.Core.Test/Qualities/QualitySizeServiceFixture.cs @@ -1,11 +1,7 @@ - - -using System.Linq; using System.Collections.Generic; -using FizzWare.NBuilder; -using FluentAssertions; using Moq; using NUnit.Framework; +using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Qualities; using NzbDrone.Core.Test.Framework; @@ -18,26 +14,10 @@ public class QualitySizeServiceFixture : CoreTest [Test] public void Init_should_add_all_sizes() { - Subject.Init(); + Subject.Handle(new ApplicationStartedEvent()); Mocker.GetMock() .Verify(v => v.Insert(It.IsAny()), Times.Exactly(Quality.All().Count - 1)); - - //Todo: Should we validate each was inserted exactly as configured? - - //var types = Mocker.Resolve().All(); - - //types.Should().HaveCount(10); - //types.Should().Contain(e => e.Name == "SDTV" && e.QualityId == 1); - //types.Should().Contain(e => e.Name == "DVD" && e.QualityId == 2); - //types.Should().Contain(e => e.Name == "WEBDL-480p" && e.QualityId == 8); - //types.Should().Contain(e => e.Name == "HDTV-720p" && e.QualityId == 4); - //types.Should().Contain(e => e.Name == "HDTV-1080p" && e.QualityId == 9); - //types.Should().Contain(e => e.Name == "Raw-HD" && e.QualityId == 10); - //types.Should().Contain(e => e.Name == "WEBDL-720p" && e.QualityId == 5); - //types.Should().Contain(e => e.Name == "WEBDL-1080p" && e.QualityId == 3); - //types.Should().Contain(e => e.Name == "Bluray720p" && e.QualityId == 6); - //types.Should().Contain(e => e.Name == "Bluray1080p" && e.QualityId == 7); } [Test] @@ -50,7 +30,7 @@ public void Init_should_insert_any_missing_sizes() new QualitySize { QualityId = 1, Name = "SDTV", MinSize = 0, MaxSize = 100 } }); - Subject.Init(); + Subject.Handle(new ApplicationStartedEvent()); Mocker.GetMock() .Verify(v => v.Insert(It.IsAny()), Times.Exactly(Quality.All().Count - 2)); diff --git a/NzbDrone.Core/Configuration/ConfigService.cs b/NzbDrone.Core/Configuration/ConfigService.cs index 31f32234e..b5a71e004 100644 --- a/NzbDrone.Core/Configuration/ConfigService.cs +++ b/NzbDrone.Core/Configuration/ConfigService.cs @@ -211,7 +211,7 @@ public string XbmcPassword public string UpdateUrl { - get { return GetValue("UpdateUrl", UpdateProvider.DEFAULT_UPDATE_URL); } + get { return GetValue("UpdateUrl", "http://update.nzbdrone.com/_release/"); } set { SetValue("UpdateUrl", value); } } diff --git a/NzbDrone.Core/DecisionEngine/Specifications/AllowedReleaseGroupSpecification.cs b/NzbDrone.Core/DecisionEngine/Specifications/AllowedReleaseGroupSpecification.cs index 80a78b135..8a3ce67b0 100644 --- a/NzbDrone.Core/DecisionEngine/Specifications/AllowedReleaseGroupSpecification.cs +++ b/NzbDrone.Core/DecisionEngine/Specifications/AllowedReleaseGroupSpecification.cs @@ -32,7 +32,7 @@ public virtual bool IsSatisfiedBy(IndexerParseResult subject) //Todo: Make this use NzbRestrictions - How should whitelist be used? Will it override blacklist or vice-versa? //var allowed = _configService.AllowedReleaseGroups; - var allowed = ""; + const string allowed = ""; if (string.IsNullOrWhiteSpace(allowed)) return true; diff --git a/NzbDrone.Core/Lifecycle/AppUpdateJob.cs b/NzbDrone.Core/Lifecycle/AppUpdateJob.cs index 2583bf191..d82aa4562 100644 --- a/NzbDrone.Core/Lifecycle/AppUpdateJob.cs +++ b/NzbDrone.Core/Lifecycle/AppUpdateJob.cs @@ -48,7 +48,7 @@ public virtual void Start(ProgressNotification notification, dynamic options) { notification.CurrentMessage = "Checking for updates"; - var updatePackage = _updateProvider.GetAvilableUpdate(_environmentProvider.Version); + var updatePackage = _updateProvider.GetAvailableUpdate(_environmentProvider.Version); //No updates available if (updatePackage == null) diff --git a/NzbDrone.Core/Providers/DiskScanProvider.cs b/NzbDrone.Core/Providers/DiskScanProvider.cs index eb8d671d9..accbc4fbc 100644 --- a/NzbDrone.Core/Providers/DiskScanProvider.cs +++ b/NzbDrone.Core/Providers/DiskScanProvider.cs @@ -195,7 +195,7 @@ public virtual void CleanUpDropFolder(string path) } catch (Exception ex) { - Logger.WarnException("Failed to move epiosde file from drop folder: " + file, ex); + Logger.WarnException("Failed to move episode file from drop folder: " + file, ex); throw; } } diff --git a/NzbDrone.Core/Providers/UpdateProvider.cs b/NzbDrone.Core/Providers/UpdateProvider.cs index 7fbe614c8..d50f4e64a 100644 --- a/NzbDrone.Core/Providers/UpdateProvider.cs +++ b/NzbDrone.Core/Providers/UpdateProvider.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; @@ -20,19 +19,19 @@ public class UpdateProvider private readonly EnvironmentProvider _environmentProvider; private readonly DiskProvider _diskProvider; - private static readonly Logger logger = LogManager.GetCurrentClassLogger(); + private readonly Logger _logger; private static readonly Regex parseRegex = new Regex(@"(?:\>)(?NzbDrone.+?(?\d+\.\d+\.\d+\.\d+).+?)(?:\<\/A\>)", RegexOptions.IgnoreCase); - public const string DEFAULT_UPDATE_URL = @"http://update.nzbdrone.com/_release/"; public UpdateProvider(IHttpProvider httpProvider, IConfigService configService, - EnvironmentProvider environmentProvider, DiskProvider diskProvider) + EnvironmentProvider environmentProvider, DiskProvider diskProvider, Logger logger) { _httpProvider = httpProvider; _configService = configService; _environmentProvider = environmentProvider; _diskProvider = diskProvider; + _logger = logger; } public UpdateProvider() @@ -40,7 +39,7 @@ public UpdateProvider() } - private List GetAvailablePackages() + private IEnumerable GetAvailablePackages() { var updateList = new List(); var updateUrl = _configService.UpdateUrl; @@ -59,17 +58,17 @@ private List GetAvailablePackages() return updateList; } - public virtual UpdatePackage GetAvilableUpdate(Version currentVersion) + public virtual UpdatePackage GetAvailableUpdate(Version currentVersion) { var latestAvailable = GetAvailablePackages().OrderByDescending(c => c.Version).FirstOrDefault(); if (latestAvailable != null && latestAvailable.Version > currentVersion) { - logger.Debug("An update is available ({0}) => ({1})", currentVersion, latestAvailable.Version); + _logger.Debug("An update is available ({0}) => ({1})", currentVersion, latestAvailable.Version); return latestAvailable; } - logger.Trace("No updates available"); + _logger.Trace("No updates available"); return null; } diff --git a/NzbDrone.Core/Qualities/QualityProfileService.cs b/NzbDrone.Core/Qualities/QualityProfileService.cs index 08cede134..f09b11211 100644 --- a/NzbDrone.Core/Qualities/QualityProfileService.cs +++ b/NzbDrone.Core/Qualities/QualityProfileService.cs @@ -52,11 +52,6 @@ public QualityProfile Get(int id) return _qualityProfileRepository.Get(id); } - public void Init() - { - - } - public void Handle(ApplicationStartedEvent message) { if (All().Any()) return;