Added and fixed qBittorent tests

This commit is contained in:
Mark McDowall 2016-10-28 13:28:21 -07:00
parent 1ac442d0e6
commit f2ecbe776b
2 changed files with 107 additions and 1 deletions

View File

@ -35,6 +35,10 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
Mocker.GetMock<IHttpClient>() Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.IsAny<HttpRequest>())) .Setup(s => s.Get(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new Byte[0])); .Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new Byte[0]));
Mocker.GetMock<IQBittorrentProxy>()
.Setup(s => s.GetConfig(It.IsAny<QBittorrentSettings>()))
.Returns(new QBittorrentPreferences());
} }
protected void GivenRedirectToMagnet() protected void GivenRedirectToMagnet()
@ -85,6 +89,17 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
}); });
} }
protected void GivenMaxRatio(float maxRatio, bool removeOnMaxRatio = true)
{
Mocker.GetMock<IQBittorrentProxy>()
.Setup(s => s.GetConfig(It.IsAny<QBittorrentSettings>()))
.Returns(new QBittorrentPreferences
{
RemoveOnMaxRatio = removeOnMaxRatio,
MaxRatio = maxRatio
});
}
protected virtual void GivenTorrents(List<QBittorrentTorrent> torrents) protected virtual void GivenTorrents(List<QBittorrentTorrent> torrents)
{ {
if (torrents == null) if (torrents == null)
@ -294,5 +309,97 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
id.Should().NotBeNullOrEmpty(); id.Should().NotBeNullOrEmpty();
} }
[Test]
public void should_be_read_only_if_max_ratio_not_reached()
{
GivenMaxRatio(1.0f);
var torrent = new QBittorrentTorrent
{
Hash = "HASH",
Name = _title,
Size = 1000,
Progress = 1.0,
Eta = 8640000,
State = "uploading",
Label = "",
SavePath = "",
Ratio = 0.5f
};
GivenTorrents(new List<QBittorrentTorrent> { torrent });
var item = Subject.GetItems().Single();
item.IsReadOnly.Should().BeTrue();
}
[Test]
public void should_be_read_only_if_max_ratio_reached_and_not_paused()
{
GivenMaxRatio(1.0f);
var torrent = new QBittorrentTorrent
{
Hash = "HASH",
Name = _title,
Size = 1000,
Progress = 1.0,
Eta = 8640000,
State = "uploading",
Label = "",
SavePath = "",
Ratio = 1.0f
};
GivenTorrents(new List<QBittorrentTorrent> { torrent });
var item = Subject.GetItems().Single();
item.IsReadOnly.Should().BeTrue();
}
[Test]
public void should_be_read_only_if_max_ratio_is_not_set()
{
GivenMaxRatio(1.0f, false);
var torrent = new QBittorrentTorrent
{
Hash = "HASH",
Name = _title,
Size = 1000,
Progress = 1.0,
Eta = 8640000,
State = "uploading",
Label = "",
SavePath = "",
Ratio = 1.0f
};
GivenTorrents(new List<QBittorrentTorrent> { torrent });
var item = Subject.GetItems().Single();
item.IsReadOnly.Should().BeTrue();
}
[Test]
public void should_not_be_read_only_if_max_ratio_reached_and_paused()
{
GivenMaxRatio(1.0f);
var torrent = new QBittorrentTorrent
{
Hash = "HASH",
Name = _title,
Size = 1000,
Progress = 1.0,
Eta = 8640000,
State = "pausedUP",
Label = "",
SavePath = "",
Ratio = 1.0f
};
GivenTorrents(new List<QBittorrentTorrent> { torrent });
var item = Subject.GetItems().Single();
item.IsReadOnly.Should().BeFalse();
}
} }
} }

View File

@ -12,7 +12,6 @@ using FluentValidation.Results;
using System.Net; using System.Net;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.RemotePathMappings; using NzbDrone.Core.RemotePathMappings;
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.Download.Clients.QBittorrent namespace NzbDrone.Core.Download.Clients.QBittorrent
{ {