From fef3423019c84b534d82dc6a51f8ffd1819cd026 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Fri, 30 Jun 2017 21:45:13 +0200 Subject: [PATCH] Fixed error in NzbGet KeepHistory check and updated tests. --- .../NzbgetTests/NzbgetFixture.cs | 18 +++++++++++------- .../Download/Clients/Nzbget/Nzbget.cs | 9 +++++---- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetTests/NzbgetFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetTests/NzbgetFixture.cs index cfae6d94a..feea1329d 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetTests/NzbgetFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetTests/NzbgetFixture.cs @@ -19,6 +19,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests private NzbgetQueueItem _queued; private NzbgetHistoryItem _failed; private NzbgetHistoryItem _completed; + private Dictionary _configItems; [SetUp] public void Setup() @@ -80,13 +81,18 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests DownloadRate = 7000000 }); - var configItems = new Dictionary(); - configItems.Add("Category1.Name", "tv"); - configItems.Add("Category1.DestDir", @"/remote/mount/tv"); + + Mocker.GetMock() + .Setup(v => v.GetVersion(It.IsAny())) + .Returns("14.0"); + + _configItems = new Dictionary(); + _configItems.Add("Category1.Name", "tv"); + _configItems.Add("Category1.DestDir", @"/remote/mount/tv"); Mocker.GetMock() .Setup(v => v.GetConfig(It.IsAny())) - .Returns(configItems); + .Returns(_configItems); } protected void GivenFailedDownload() @@ -421,9 +427,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests [TestCase("5000000", false)] public void should_test_keephistory(string keephistory, bool expected) { - Mocker.GetMock() - .Setup(v => v.GetConfig(It.IsAny())) - .Returns(new Dictionary { { "KeepHistory", keephistory } }); + _configItems["KeepHistory"] = keephistory; var error = Subject.Test(); diff --git a/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs b/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs index cd481cfa8..84c6a1dd3 100644 --- a/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs +++ b/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs @@ -1,7 +1,8 @@ using System; +using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; -using System.Collections.Generic; using FluentValidation.Results; using NLog; using NzbDrone.Common.Disk; @@ -9,8 +10,8 @@ using NzbDrone.Common.Extensions; using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; using NzbDrone.Core.Parser.Model; -using NzbDrone.Core.Validation; using NzbDrone.Core.RemotePathMappings; +using NzbDrone.Core.Validation; namespace NzbDrone.Core.Download.Clients.Nzbget { @@ -296,9 +297,9 @@ namespace NzbDrone.Core.Download.Clients.Nzbget { var config = _proxy.GetConfig(Settings); - var keepHistory = config.GetValueOrDefault("KeepHistory"); + var keepHistory = config.GetValueOrDefault("KeepHistory", "7"); int value; - if (int.TryParse(keepHistory, out value) || value == 0) + if (!int.TryParse(keepHistory, NumberStyles.None, CultureInfo.InvariantCulture, out value) || value == 0) { return new NzbDroneValidationFailure(string.Empty, "NzbGet setting KeepHistory should be greater than 0") {