diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs index b98636a5f..e6f56a12b 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/QBittorrentTests/QBittorrentFixture.cs @@ -35,6 +35,10 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests Mocker.GetMock() .Setup(s => s.Get(It.IsAny())) .Returns(r => new HttpResponse(r, new HttpHeader(), new Byte[0])); + + Mocker.GetMock() + .Setup(s => s.GetConfig(It.IsAny())) + .Returns(new QBittorrentPreferences()); } protected void GivenRedirectToMagnet() @@ -85,6 +89,17 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests }); } + protected void GivenMaxRatio(float maxRatio, bool removeOnMaxRatio = true) + { + Mocker.GetMock() + .Setup(s => s.GetConfig(It.IsAny())) + .Returns(new QBittorrentPreferences + { + RemoveOnMaxRatio = removeOnMaxRatio, + MaxRatio = maxRatio + }); + } + protected virtual void GivenTorrents(List torrents) { if (torrents == null) @@ -294,5 +309,97 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests 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 { 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 { 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 { 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 { torrent }); + + var item = Subject.GetItems().Single(); + item.IsReadOnly.Should().BeFalse(); + } } } diff --git a/src/NzbDrone.Core/Download/Clients/qBittorrent/QBittorrent.cs b/src/NzbDrone.Core/Download/Clients/qBittorrent/QBittorrent.cs index 942cbdaf6..b7d06cd3c 100644 --- a/src/NzbDrone.Core/Download/Clients/qBittorrent/QBittorrent.cs +++ b/src/NzbDrone.Core/Download/Clients/qBittorrent/QBittorrent.cs @@ -12,7 +12,6 @@ using FluentValidation.Results; using System.Net; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.RemotePathMappings; -using NzbDrone.Core.ThingiProvider; namespace NzbDrone.Core.Download.Clients.QBittorrent {