diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/TorrentDownloadStationFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/TorrentDownloadStationFixture.cs index 34c48cea9..d48b29e11 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/TorrentDownloadStationFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/TorrentDownloadStationFixture.cs @@ -304,7 +304,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests _settings.TvDirectory = _tvDirectory; } - protected virtual void GivenTorrents(List torrents) + protected virtual void GivenTasks(List torrents) { if (torrents == null) { @@ -312,13 +312,13 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests } Mocker.GetMock() - .Setup(s => s.GetTasks(DownloadStationTaskType.BT, It.IsAny())) + .Setup(s => s.GetTasks(It.IsAny())) .Returns(torrents); } protected void PrepareClientToReturnQueuedItem() { - GivenTorrents(new List + GivenTasks(new List { _queued }); @@ -353,7 +353,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests var tasks = new List() { _queued, _completed, _failed, _downloading, _seeding }; Mocker.GetMock() - .Setup(d => d.GetTasks(DownloadStationTaskType.BT, _settings)) + .Setup(d => d.GetTasks(_settings)) .Returns(tasks); return tasks.Count; @@ -409,6 +409,28 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests .Verify(v => v.AddTaskFromUrl(It.IsAny(), null, It.IsAny()), Times.Once()); } + [Test] + public void GetItems_should_return_empty_list_if_no_tasks_available() + { + GivenSerialNumber(); + GivenSharedFolder(); + GivenTasks(new List()); + + Subject.GetItems().Should().BeEmpty(); + } + + [Test] + public void GetItems_should_return_ignore_tasks_of_unknown_type() + { + GivenSerialNumber(); + GivenSharedFolder(); + GivenTasks(new List { _completed }); + + _completed.Type = "ipfs"; + + Subject.GetItems().Should().BeEmpty(); + } + [Test] public void GetItems_should_ignore_downloads_in_wrong_folder() { @@ -416,7 +438,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests GivenSerialNumber(); GivenSharedFolder(); - GivenTorrents(new List { _completed }); + GivenTasks(new List { _completed }); Subject.GetItems().Should().BeEmpty(); } @@ -470,7 +492,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests GivenSerialNumber(); GivenSharedFolder(); - GivenTorrents(new List() { _singleFile }); + GivenTasks(new List() { _singleFile }); var items = Subject.GetItems(); @@ -484,7 +506,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests GivenSerialNumber(); GivenSharedFolder(); - GivenTorrents(new List() { _multipleFiles }); + GivenTasks(new List() { _multipleFiles }); var items = Subject.GetItems(); @@ -498,7 +520,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests GivenSerialNumber(); GivenSharedFolder(); - GivenTorrents(new List() { _singleFileCompleted }); + GivenTasks(new List() { _singleFileCompleted }); var items = Subject.GetItems(); @@ -512,7 +534,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests GivenSerialNumber(); GivenSharedFolder(); - GivenTorrents(new List() { _multipleFilesCompleted }); + GivenTasks(new List() { _multipleFilesCompleted }); var items = Subject.GetItems(); @@ -526,7 +548,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests GivenSerialNumber(); GivenSharedFolder(); - GivenTorrents(new List + GivenTasks(new List { _queued, _downloading }); @@ -543,7 +565,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests GivenSerialNumber(); GivenSharedFolder(); - GivenTorrents(new List + GivenTasks(new List { _completed, _failed, _seeding }); @@ -565,7 +587,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests _queued.Status = apiStatus; - GivenTorrents(new List() { _queued }); + GivenTasks(new List() { _queued }); var items = Subject.GetItems(); @@ -589,7 +611,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests _queued.Status = apiStatus; - GivenTorrents(new List() { _queued }); + GivenTasks(new List() { _queued }); var items = Subject.GetItems(); items.Should().HaveCount(1); diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/UsenetDownloadStationFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/UsenetDownloadStationFixture.cs index c9b672f75..2e44c60ba 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/UsenetDownloadStationFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/DownloadStationTests/UsenetDownloadStationFixture.cs @@ -206,7 +206,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests _settings.TvDirectory = _tvDirectory; } - protected virtual void GivenNZBs(List nzbs) + protected virtual void GivenTasks(List nzbs) { if (nzbs == null) { @@ -214,13 +214,13 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests } Mocker.GetMock() - .Setup(s => s.GetTasks(DownloadStationTaskType.NZB, It.IsAny())) + .Setup(s => s.GetTasks(It.IsAny())) .Returns(nzbs); } protected void PrepareClientToReturnQueuedItem() { - GivenNZBs(new List + GivenTasks(new List { _queued }); @@ -243,7 +243,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests var tasks = new List() { _queued, _completed, _failed, _downloading, _seeding }; Mocker.GetMock() - .Setup(d => d.GetTasks(DownloadStationTaskType.NZB, _settings)) + .Setup(d => d.GetTasks(_settings)) .Returns(tasks); } @@ -300,11 +300,21 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests [Test] public void GetItems_should_return_empty_list_if_no_tasks_available() { - _settings.TvDirectory = @"/shared/folder/sub"; + GivenSerialNumber(); + GivenSharedFolder(); + GivenTasks(new List()); + Subject.GetItems().Should().BeEmpty(); + } + + [Test] + public void GetItems_should_return_ignore_tasks_of_unknown_type() + { GivenSerialNumber(); GivenSharedFolder(); - GivenNZBs(new List()); + GivenTasks(new List { _completed }); + + _completed.Type = "ipfs"; Subject.GetItems().Should().BeEmpty(); } @@ -316,7 +326,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests GivenSerialNumber(); GivenSharedFolder(); - GivenNZBs(new List { _completed }); + GivenTasks(new List { _completed }); Subject.GetItems().Should().BeEmpty(); } @@ -350,7 +360,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests } [Test] - public void Download_should_throw_and_not_add_tasks_if_cannot_get_serial_number() + public void Download_should_throw_and_not_add_task_if_cannot_get_serial_number() { var remoteEpisode = CreateRemoteEpisode(); @@ -370,7 +380,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests GivenSerialNumber(); GivenSharedFolder(); - GivenNZBs(new List + GivenTasks(new List { _queued, _downloading }); @@ -387,7 +397,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests GivenSerialNumber(); GivenSharedFolder(); - GivenNZBs(new List + GivenTasks(new List { _completed, _failed, _seeding }); @@ -408,7 +418,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests _queued.Status = apiStatus; - GivenNZBs(new List() { _queued }); + GivenTasks(new List() { _queued }); var items = Subject.GetItems(); @@ -431,7 +441,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests _queued.Status = apiStatus; - GivenNZBs(new List() { _queued }); + GivenTasks(new List() { _queued }); var items = Subject.GetItems(); items.Should().HaveCount(1); diff --git a/src/NzbDrone.Core/Download/Clients/DownloadStation/Proxies/DownloadStationProxy.cs b/src/NzbDrone.Core/Download/Clients/DownloadStation/Proxies/DownloadStationProxy.cs index 823ac9ad9..427cd3d5b 100644 --- a/src/NzbDrone.Core/Download/Clients/DownloadStation/Proxies/DownloadStationProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/DownloadStation/Proxies/DownloadStationProxy.cs @@ -10,7 +10,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies { public interface IDownloadStationProxy { - IEnumerable GetTasks(DownloadStationTaskType type, DownloadStationSettings settings); + IEnumerable GetTasks(DownloadStationSettings settings); Dictionary GetConfig(DownloadStationSettings settings); void RemoveTask(string downloadId, DownloadStationSettings settings); void AddTaskFromUrl(string url, string downloadDirectory, DownloadStationSettings settings); @@ -40,8 +40,8 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies } arguments.Add("file", new Dictionary() { { "name", filename }, { "data", data } }); - - var response = ProcessRequest(DiskStationApi.DownloadStationTask, arguments, settings, $"add task from data {filename}", HttpMethod.POST); + + var response = ProcessRequest(DiskStationApi.DownloadStationTask, arguments, settings, $"add task from data {filename}", HttpMethod.POST); } public void AddTaskFromUrl(string url, string downloadDirectory, DownloadStationSettings settings) @@ -62,7 +62,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies var response = ProcessRequest(DiskStationApi.DownloadStationTask, arguments, settings, $"add task from url {url}"); } - public IEnumerable GetTasks(DownloadStationTaskType type, DownloadStationSettings settings) + public IEnumerable GetTasks(DownloadStationSettings settings) { var arguments = new Dictionary { @@ -76,7 +76,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies { var response = ProcessRequest(DiskStationApi.DownloadStationTask, arguments, settings, "get tasks"); - return response.Data.Tasks.Where(t => t.Type == type.ToString()); + return response.Data.Tasks; } catch (DownloadClientException e) { diff --git a/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs b/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs index 987c81970..de7b55031 100644 --- a/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs +++ b/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs @@ -45,9 +45,14 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation public override string Name => "Download Station"; + protected IEnumerable GetTasks() + { + return _proxy.GetTasks(Settings).Where(v => v.Type == DownloadStationTaskType.BT.ToString()); + } + public override IEnumerable GetItems() { - var torrents = _proxy.GetTasks(DownloadStationTaskType.BT, Settings); + var torrents = GetTasks(); var serialNumber = _serialNumberProvider.GetSerialNumber(Settings); var items = new List(); @@ -145,7 +150,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation _proxy.AddTaskFromUrl(magnetLink, GetDownloadDirectory(), Settings); - var item = _proxy.GetTasks(DownloadStationTaskType.BT, Settings).SingleOrDefault(t => t.Additional.Detail["uri"] == magnetLink); + var item = GetTasks().SingleOrDefault(t => t.Additional.Detail["uri"] == magnetLink); if (item != null) { @@ -164,7 +169,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation _proxy.AddTaskFromData(fileContent, filename, GetDownloadDirectory(), Settings); - var items = _proxy.GetTasks(DownloadStationTaskType.BT, Settings).Where(t => t.Additional.Detail["uri"] == Path.GetFileNameWithoutExtension(filename)); + var items = GetTasks().Where(t => t.Additional.Detail["uri"] == Path.GetFileNameWithoutExtension(filename)); var item = items.SingleOrDefault(); @@ -354,7 +359,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation { try { - _proxy.GetTasks(DownloadStationTaskType.BT, Settings); + GetItems(); return null; } catch (Exception ex) diff --git a/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs b/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs index 3f9d56f2f..31524bc9d 100644 --- a/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs +++ b/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs @@ -42,9 +42,14 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation public override string Name => "Download Station"; + protected IEnumerable GetTasks() + { + return _proxy.GetTasks(Settings).Where(v => v.Type == DownloadStationTaskType.NZB.ToString()); + } + public override IEnumerable GetItems() { - var nzbTasks = _proxy.GetTasks(DownloadStationTaskType.NZB, Settings); + var nzbTasks = GetTasks(); var serialNumber = _serialNumberProvider.GetSerialNumber(Settings); var items = new List(); @@ -158,7 +163,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation _proxy.AddTaskFromData(fileContent, filename, GetDownloadDirectory(), Settings); - var items = _proxy.GetTasks(DownloadStationTaskType.NZB, Settings).Where(t => t.Additional.Detail["uri"] == filename); + var items = GetTasks().Where(t => t.Additional.Detail["uri"] == filename); var item = items.SingleOrDefault(); @@ -353,7 +358,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation { try { - _proxy.GetTasks(DownloadStationTaskType.NZB, Settings); + GetItems(); return null; } catch (Exception ex)