Fixed error in NzbGet KeepHistory check and updated tests.

This commit is contained in:
Taloth Saldono 2017-06-30 21:45:13 +02:00
parent 11926d8b2d
commit fef3423019
2 changed files with 16 additions and 11 deletions

View File

@ -19,6 +19,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests
private NzbgetQueueItem _queued; private NzbgetQueueItem _queued;
private NzbgetHistoryItem _failed; private NzbgetHistoryItem _failed;
private NzbgetHistoryItem _completed; private NzbgetHistoryItem _completed;
private Dictionary<string, string> _configItems;
[SetUp] [SetUp]
public void Setup() public void Setup()
@ -80,13 +81,18 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests
DownloadRate = 7000000 DownloadRate = 7000000
}); });
var configItems = new Dictionary<string, string>();
configItems.Add("Category1.Name", "tv"); Mocker.GetMock<INzbgetProxy>()
configItems.Add("Category1.DestDir", @"/remote/mount/tv"); .Setup(v => v.GetVersion(It.IsAny<NzbgetSettings>()))
.Returns("14.0");
_configItems = new Dictionary<string, string>();
_configItems.Add("Category1.Name", "tv");
_configItems.Add("Category1.DestDir", @"/remote/mount/tv");
Mocker.GetMock<INzbgetProxy>() Mocker.GetMock<INzbgetProxy>()
.Setup(v => v.GetConfig(It.IsAny<NzbgetSettings>())) .Setup(v => v.GetConfig(It.IsAny<NzbgetSettings>()))
.Returns(configItems); .Returns(_configItems);
} }
protected void GivenFailedDownload() protected void GivenFailedDownload()
@ -421,9 +427,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests
[TestCase("5000000", false)] [TestCase("5000000", false)]
public void should_test_keephistory(string keephistory, bool expected) public void should_test_keephistory(string keephistory, bool expected)
{ {
Mocker.GetMock<INzbgetProxy>() _configItems["KeepHistory"] = keephistory;
.Setup(v => v.GetConfig(It.IsAny<NzbgetSettings>()))
.Returns(new Dictionary<string, string> { { "KeepHistory", keephistory } });
var error = Subject.Test(); var error = Subject.Test();

View File

@ -1,7 +1,8 @@
using System; using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Collections.Generic;
using FluentValidation.Results; using FluentValidation.Results;
using NLog; using NLog;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
@ -9,8 +10,8 @@ using NzbDrone.Common.Extensions;
using NzbDrone.Common.Http; using NzbDrone.Common.Http;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Validation;
using NzbDrone.Core.RemotePathMappings; using NzbDrone.Core.RemotePathMappings;
using NzbDrone.Core.Validation;
namespace NzbDrone.Core.Download.Clients.Nzbget namespace NzbDrone.Core.Download.Clients.Nzbget
{ {
@ -296,9 +297,9 @@ namespace NzbDrone.Core.Download.Clients.Nzbget
{ {
var config = _proxy.GetConfig(Settings); var config = _proxy.GetConfig(Settings);
var keepHistory = config.GetValueOrDefault("KeepHistory"); var keepHistory = config.GetValueOrDefault("KeepHistory", "7");
int value; 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") return new NzbDroneValidationFailure(string.Empty, "NzbGet setting KeepHistory should be greater than 0")
{ {