mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-24 22:35:39 -04:00
New: Added support for nzb downloads in Synology Download Station.
This commit is contained in:
+56
-56
@@ -20,16 +20,16 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
{
|
||||
protected DownloadStationSettings _settings;
|
||||
|
||||
protected DownloadStationTorrent _queued;
|
||||
protected DownloadStationTorrent _downloading;
|
||||
protected DownloadStationTorrent _failed;
|
||||
protected DownloadStationTorrent _completed;
|
||||
protected DownloadStationTorrent _seeding;
|
||||
protected DownloadStationTorrent _magnet;
|
||||
protected DownloadStationTorrent _singleFile;
|
||||
protected DownloadStationTorrent _multipleFiles;
|
||||
protected DownloadStationTorrent _singleFileCompleted;
|
||||
protected DownloadStationTorrent _multipleFilesCompleted;
|
||||
protected DownloadStationTask _queued;
|
||||
protected DownloadStationTask _downloading;
|
||||
protected DownloadStationTask _failed;
|
||||
protected DownloadStationTask _completed;
|
||||
protected DownloadStationTask _seeding;
|
||||
protected DownloadStationTask _magnet;
|
||||
protected DownloadStationTask _singleFile;
|
||||
protected DownloadStationTask _multipleFiles;
|
||||
protected DownloadStationTask _singleFileCompleted;
|
||||
protected DownloadStationTask _multipleFilesCompleted;
|
||||
|
||||
protected string _serialNumber = "SERIALNUMBER";
|
||||
protected string _category = "sonarr";
|
||||
@@ -55,7 +55,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
Subject.Definition = new DownloadClientDefinition();
|
||||
Subject.Definition.Settings = _settings;
|
||||
|
||||
_queued = new DownloadStationTorrent()
|
||||
_queued = new DownloadStationTask()
|
||||
{
|
||||
Id = "id1",
|
||||
Size = 1000,
|
||||
@@ -63,7 +63,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
Type = DownloadStationTaskType.BT,
|
||||
Username = "admin",
|
||||
Title = "title",
|
||||
Additional = new DownloadStationTorrentAdditional
|
||||
Additional = new DownloadStationTaskAdditional
|
||||
{
|
||||
Detail = new Dictionary<string, string>
|
||||
{
|
||||
@@ -78,7 +78,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
}
|
||||
};
|
||||
|
||||
_completed = new DownloadStationTorrent()
|
||||
_completed = new DownloadStationTask()
|
||||
{
|
||||
Id = "id2",
|
||||
Size = 1000,
|
||||
@@ -86,7 +86,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
Type = DownloadStationTaskType.BT,
|
||||
Username = "admin",
|
||||
Title = "title",
|
||||
Additional = new DownloadStationTorrentAdditional
|
||||
Additional = new DownloadStationTaskAdditional
|
||||
{
|
||||
Detail = new Dictionary<string, string>
|
||||
{
|
||||
@@ -101,7 +101,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
}
|
||||
};
|
||||
|
||||
_seeding = new DownloadStationTorrent()
|
||||
_seeding = new DownloadStationTask()
|
||||
{
|
||||
Id = "id2",
|
||||
Size = 1000,
|
||||
@@ -109,7 +109,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
Type = DownloadStationTaskType.BT,
|
||||
Username = "admin",
|
||||
Title = "title",
|
||||
Additional = new DownloadStationTorrentAdditional
|
||||
Additional = new DownloadStationTaskAdditional
|
||||
{
|
||||
Detail = new Dictionary<string, string>
|
||||
{
|
||||
@@ -124,7 +124,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
}
|
||||
};
|
||||
|
||||
_downloading = new DownloadStationTorrent()
|
||||
_downloading = new DownloadStationTask()
|
||||
{
|
||||
Id = "id3",
|
||||
Size = 1000,
|
||||
@@ -132,7 +132,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
Type = DownloadStationTaskType.BT,
|
||||
Username = "admin",
|
||||
Title = "title",
|
||||
Additional = new DownloadStationTorrentAdditional
|
||||
Additional = new DownloadStationTaskAdditional
|
||||
{
|
||||
Detail = new Dictionary<string, string>
|
||||
{
|
||||
@@ -147,7 +147,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
}
|
||||
};
|
||||
|
||||
_failed = new DownloadStationTorrent()
|
||||
_failed = new DownloadStationTask()
|
||||
{
|
||||
Id = "id4",
|
||||
Size = 1000,
|
||||
@@ -155,7 +155,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
Type = DownloadStationTaskType.BT,
|
||||
Username = "admin",
|
||||
Title = "title",
|
||||
Additional = new DownloadStationTorrentAdditional
|
||||
Additional = new DownloadStationTaskAdditional
|
||||
{
|
||||
Detail = new Dictionary<string, string>
|
||||
{
|
||||
@@ -170,7 +170,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
}
|
||||
};
|
||||
|
||||
_singleFile = new DownloadStationTorrent()
|
||||
_singleFile = new DownloadStationTask()
|
||||
{
|
||||
Id = "id5",
|
||||
Size = 1000,
|
||||
@@ -178,7 +178,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
Type = DownloadStationTaskType.BT,
|
||||
Username = "admin",
|
||||
Title = "a.mkv",
|
||||
Additional = new DownloadStationTorrentAdditional
|
||||
Additional = new DownloadStationTaskAdditional
|
||||
{
|
||||
Detail = new Dictionary<string, string>
|
||||
{
|
||||
@@ -193,7 +193,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
}
|
||||
};
|
||||
|
||||
_multipleFiles = new DownloadStationTorrent()
|
||||
_multipleFiles = new DownloadStationTask()
|
||||
{
|
||||
Id = "id6",
|
||||
Size = 1000,
|
||||
@@ -201,7 +201,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
Type = DownloadStationTaskType.BT,
|
||||
Username = "admin",
|
||||
Title = "title",
|
||||
Additional = new DownloadStationTorrentAdditional
|
||||
Additional = new DownloadStationTaskAdditional
|
||||
{
|
||||
Detail = new Dictionary<string, string>
|
||||
{
|
||||
@@ -216,7 +216,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
}
|
||||
};
|
||||
|
||||
_singleFileCompleted = new DownloadStationTorrent()
|
||||
_singleFileCompleted = new DownloadStationTask()
|
||||
{
|
||||
Id = "id6",
|
||||
Size = 1000,
|
||||
@@ -224,7 +224,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
Type = DownloadStationTaskType.BT,
|
||||
Username = "admin",
|
||||
Title = "a.mkv",
|
||||
Additional = new DownloadStationTorrentAdditional
|
||||
Additional = new DownloadStationTaskAdditional
|
||||
{
|
||||
Detail = new Dictionary<string, string>
|
||||
{
|
||||
@@ -239,7 +239,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
}
|
||||
};
|
||||
|
||||
_multipleFilesCompleted = new DownloadStationTorrent()
|
||||
_multipleFilesCompleted = new DownloadStationTask()
|
||||
{
|
||||
Id = "id6",
|
||||
Size = 1000,
|
||||
@@ -247,7 +247,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
Type = DownloadStationTaskType.BT,
|
||||
Username = "admin",
|
||||
Title = "title",
|
||||
Additional = new DownloadStationTorrentAdditional
|
||||
Additional = new DownloadStationTaskAdditional
|
||||
{
|
||||
Detail = new Dictionary<string, string>
|
||||
{
|
||||
@@ -304,21 +304,21 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
_settings.TvDirectory = _tvDirectory;
|
||||
}
|
||||
|
||||
protected virtual void GivenTorrents(List<DownloadStationTorrent> torrents)
|
||||
protected virtual void GivenTorrents(List<DownloadStationTask> torrents)
|
||||
{
|
||||
if (torrents == null)
|
||||
{
|
||||
torrents = new List<DownloadStationTorrent>();
|
||||
torrents = new List<DownloadStationTask>();
|
||||
}
|
||||
|
||||
Mocker.GetMock<IDownloadStationProxy>()
|
||||
.Setup(s => s.GetTorrents(It.IsAny<DownloadStationSettings>()))
|
||||
.Setup(s => s.GetTasks(DownloadStationTaskType.BT, It.IsAny<DownloadStationSettings>()))
|
||||
.Returns(torrents);
|
||||
}
|
||||
|
||||
protected void PrepareClientToReturnQueuedItem()
|
||||
{
|
||||
GivenTorrents(new List<DownloadStationTorrent>
|
||||
GivenTorrents(new List<DownloadStationTask>
|
||||
{
|
||||
_queued
|
||||
});
|
||||
@@ -331,11 +331,11 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[1000]));
|
||||
|
||||
Mocker.GetMock<IDownloadStationProxy>()
|
||||
.Setup(s => s.AddTorrentFromUrl(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DownloadStationSettings>()))
|
||||
.Setup(s => s.AddTaskFromUrl(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DownloadStationSettings>()))
|
||||
.Callback(PrepareClientToReturnQueuedItem);
|
||||
|
||||
Mocker.GetMock<IDownloadStationProxy>()
|
||||
.Setup(s => s.AddTorrentFromData(It.IsAny<byte[]>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DownloadStationSettings>()))
|
||||
.Setup(s => s.AddTaskFromData(It.IsAny<byte[]>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DownloadStationSettings>()))
|
||||
.Callback(PrepareClientToReturnQueuedItem);
|
||||
}
|
||||
|
||||
@@ -350,10 +350,10 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
|
||||
protected int GivenAllKindOfTasks()
|
||||
{
|
||||
var tasks = new List<DownloadStationTorrent>() { _queued, _completed, _failed, _downloading, _seeding };
|
||||
var tasks = new List<DownloadStationTask>() { _queued, _completed, _failed, _downloading, _seeding };
|
||||
|
||||
Mocker.GetMock<IDownloadStationProxy>()
|
||||
.Setup(d => d.GetTorrents(_settings))
|
||||
.Setup(d => d.GetTasks(DownloadStationTaskType.BT, _settings))
|
||||
.Returns(tasks);
|
||||
|
||||
return tasks.Count;
|
||||
@@ -373,7 +373,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
Mocker.GetMock<IDownloadStationProxy>()
|
||||
.Verify(v => v.AddTorrentFromUrl(It.IsAny<string>(), _tvDirectory, It.IsAny<DownloadStationSettings>()), Times.Once());
|
||||
.Verify(v => v.AddTaskFromUrl(It.IsAny<string>(), _tvDirectory, It.IsAny<DownloadStationSettings>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -390,7 +390,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
Mocker.GetMock<IDownloadStationProxy>()
|
||||
.Verify(v => v.AddTorrentFromUrl(It.IsAny<string>(), $"{_defaultDestination}/{_category}", It.IsAny<DownloadStationSettings>()), Times.Once());
|
||||
.Verify(v => v.AddTaskFromUrl(It.IsAny<string>(), $"{_defaultDestination}/{_category}", It.IsAny<DownloadStationSettings>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -406,7 +406,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
Mocker.GetMock<IDownloadStationProxy>()
|
||||
.Verify(v => v.AddTorrentFromUrl(It.IsAny<string>(), null, It.IsAny<DownloadStationSettings>()), Times.Once());
|
||||
.Verify(v => v.AddTaskFromUrl(It.IsAny<string>(), null, It.IsAny<DownloadStationSettings>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -416,7 +416,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
GivenTorrents(new List<DownloadStationTorrent> { _completed });
|
||||
GivenTorrents(new List<DownloadStationTask> { _completed });
|
||||
|
||||
Subject.GetItems().Should().BeEmpty();
|
||||
}
|
||||
@@ -450,7 +450,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Download_should_throw_and_not_add_torrent_if_cannot_get_serial_number()
|
||||
public void Download_should_throw_and_not_add_task_if_cannot_get_serial_number()
|
||||
{
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
@@ -461,16 +461,16 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
Assert.Throws(Is.InstanceOf<Exception>(), () => Subject.Download(remoteEpisode));
|
||||
|
||||
Mocker.GetMock<IDownloadStationProxy>()
|
||||
.Verify(v => v.AddTorrentFromUrl(It.IsAny<string>(), null, _settings), Times.Never());
|
||||
.Verify(v => v.AddTaskFromUrl(It.IsAny<string>(), null, _settings), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_set_outputPath_to_base_folder_when_single_file_non_finished_torrent()
|
||||
public void GetItems_should_set_outputPath_to_base_folder_when_single_file_non_finished_tasks()
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
|
||||
GivenTorrents(new List<DownloadStationTorrent>() { _singleFile });
|
||||
GivenTorrents(new List<DownloadStationTask>() { _singleFile });
|
||||
|
||||
var items = Subject.GetItems();
|
||||
|
||||
@@ -479,12 +479,12 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_set_outputPath_to_torrent_folder_when_multiple_files_non_finished_torrent()
|
||||
public void GetItems_should_set_outputPath_to_torrent_folder_when_multiple_files_non_finished_tasks()
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
|
||||
GivenTorrents(new List<DownloadStationTorrent>() { _multipleFiles });
|
||||
GivenTorrents(new List<DownloadStationTask>() { _multipleFiles });
|
||||
|
||||
var items = Subject.GetItems();
|
||||
|
||||
@@ -493,12 +493,12 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_set_outputPath_to_base_folder_when_single_file_finished_torrent()
|
||||
public void GetItems_should_set_outputPath_to_base_folder_when_single_file_finished_tasks()
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
|
||||
GivenTorrents(new List<DownloadStationTorrent>() { _singleFileCompleted });
|
||||
GivenTorrents(new List<DownloadStationTask>() { _singleFileCompleted });
|
||||
|
||||
var items = Subject.GetItems();
|
||||
|
||||
@@ -507,12 +507,12 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_set_outputPath_to_torrent_folder_when_multiple_files_finished_torrent()
|
||||
public void GetItems_should_set_outputPath_to_torrent_folder_when_multiple_files_finished_tasks()
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
|
||||
GivenTorrents(new List<DownloadStationTorrent>() { _multipleFilesCompleted });
|
||||
GivenTorrents(new List<DownloadStationTask>() { _multipleFilesCompleted });
|
||||
|
||||
var items = Subject.GetItems();
|
||||
|
||||
@@ -521,12 +521,12 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_not_map_outputpath_for_queued_or_downloading_torrents()
|
||||
public void GetItems_should_not_map_outputpath_for_queued_or_downloading_tasks()
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
|
||||
GivenTorrents(new List<DownloadStationTorrent>
|
||||
GivenTorrents(new List<DownloadStationTask>
|
||||
{
|
||||
_queued, _downloading
|
||||
});
|
||||
@@ -538,12 +538,12 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_map_outputpath_for_completed_or_failed_torrents()
|
||||
public void GetItems_should_map_outputpath_for_completed_or_failed_tasks()
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
|
||||
GivenTorrents(new List<DownloadStationTorrent>
|
||||
GivenTorrents(new List<DownloadStationTask>
|
||||
{
|
||||
_completed, _failed, _seeding
|
||||
});
|
||||
@@ -565,7 +565,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
|
||||
_queued.Status = apiStatus;
|
||||
|
||||
GivenTorrents(new List<DownloadStationTorrent>() { _queued });
|
||||
GivenTorrents(new List<DownloadStationTask>() { _queued });
|
||||
|
||||
var items = Subject.GetItems();
|
||||
|
||||
@@ -589,7 +589,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
|
||||
_queued.Status = apiStatus;
|
||||
|
||||
GivenTorrents(new List<DownloadStationTorrent>() { _queued });
|
||||
GivenTorrents(new List<DownloadStationTask>() { _queued });
|
||||
|
||||
var items = Subject.GetItems();
|
||||
items.Should().HaveCount(1);
|
||||
|
||||
+442
@@ -0,0 +1,442 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Download.Clients.DownloadStation;
|
||||
using NzbDrone.Core.Download.Clients.DownloadStation.Proxies;
|
||||
using NzbDrone.Core.MediaFiles.TorrentInfo;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Test.Common;
|
||||
using NzbDrone.Core.Organizer;
|
||||
|
||||
namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class UsenetDownloadStationFixture : DownloadClientFixtureBase<UsenetDownloadStation>
|
||||
{
|
||||
protected DownloadStationSettings _settings;
|
||||
|
||||
protected DownloadStationTask _queued;
|
||||
protected DownloadStationTask _downloading;
|
||||
protected DownloadStationTask _failed;
|
||||
protected DownloadStationTask _completed;
|
||||
protected DownloadStationTask _seeding;
|
||||
|
||||
protected string _serialNumber = "SERIALNUMBER";
|
||||
protected string _category = "sonarr";
|
||||
protected string _tvDirectory = @"video/Series";
|
||||
protected string _defaultDestination = "somepath";
|
||||
protected OsPath _physicalPath = new OsPath("/mnt/sdb1/mydata");
|
||||
|
||||
protected RemoteEpisode _remoteEpisode;
|
||||
|
||||
protected Dictionary<string, object> _downloadStationConfigItems;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
_settings = new DownloadStationSettings()
|
||||
{
|
||||
Host = "127.0.0.1",
|
||||
Port = 5000,
|
||||
Username = "admin",
|
||||
Password = "pass"
|
||||
};
|
||||
|
||||
Subject.Definition = new DownloadClientDefinition();
|
||||
Subject.Definition.Settings = _settings;
|
||||
|
||||
_queued = new DownloadStationTask()
|
||||
{
|
||||
Id = "id1",
|
||||
Size = 1000,
|
||||
Status = DownloadStationTaskStatus.Waiting,
|
||||
Type = DownloadStationTaskType.NZB,
|
||||
Username = "admin",
|
||||
Title = "title",
|
||||
Additional = new DownloadStationTaskAdditional
|
||||
{
|
||||
Detail = new Dictionary<string, string>
|
||||
{
|
||||
{ "destination","shared/folder" },
|
||||
{ "uri", FileNameBuilder.CleanFileName(_remoteEpisode.Release.Title) + ".nzb" }
|
||||
},
|
||||
Transfer = new Dictionary<string, string>
|
||||
{
|
||||
{ "size_downloaded", "0"},
|
||||
{ "speed_download", "0" }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_completed = new DownloadStationTask()
|
||||
{
|
||||
Id = "id2",
|
||||
Size = 1000,
|
||||
Status = DownloadStationTaskStatus.Finished,
|
||||
Type = DownloadStationTaskType.NZB,
|
||||
Username = "admin",
|
||||
Title = "title",
|
||||
Additional = new DownloadStationTaskAdditional
|
||||
{
|
||||
Detail = new Dictionary<string, string>
|
||||
{
|
||||
{ "destination","shared/folder" },
|
||||
{ "uri", FileNameBuilder.CleanFileName(_remoteEpisode.Release.Title) + ".nzb" }
|
||||
},
|
||||
Transfer = new Dictionary<string, string>
|
||||
{
|
||||
{ "size_downloaded", "1000"},
|
||||
{ "speed_download", "0" }
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
_seeding = new DownloadStationTask()
|
||||
{
|
||||
Id = "id2",
|
||||
Size = 1000,
|
||||
Status = DownloadStationTaskStatus.Seeding,
|
||||
Type = DownloadStationTaskType.NZB,
|
||||
Username = "admin",
|
||||
Title = "title",
|
||||
Additional = new DownloadStationTaskAdditional
|
||||
{
|
||||
Detail = new Dictionary<string, string>
|
||||
{
|
||||
{ "destination","shared/folder" },
|
||||
{ "uri", FileNameBuilder.CleanFileName(_remoteEpisode.Release.Title) + ".nzb" }
|
||||
},
|
||||
Transfer = new Dictionary<string, string>
|
||||
{
|
||||
{ "size_downloaded", "1000"},
|
||||
{ "speed_download", "0" }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_downloading = new DownloadStationTask()
|
||||
{
|
||||
Id = "id3",
|
||||
Size = 1000,
|
||||
Status = DownloadStationTaskStatus.Downloading,
|
||||
Type = DownloadStationTaskType.NZB,
|
||||
Username = "admin",
|
||||
Title = "title",
|
||||
Additional = new DownloadStationTaskAdditional
|
||||
{
|
||||
Detail = new Dictionary<string, string>
|
||||
{
|
||||
{ "destination","shared/folder" },
|
||||
{ "uri", FileNameBuilder.CleanFileName(_remoteEpisode.Release.Title) + ".nzb" }
|
||||
},
|
||||
Transfer = new Dictionary<string, string>
|
||||
{
|
||||
{ "size_downloaded", "100"},
|
||||
{ "speed_download", "50" }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_failed = new DownloadStationTask()
|
||||
{
|
||||
Id = "id4",
|
||||
Size = 1000,
|
||||
Status = DownloadStationTaskStatus.Error,
|
||||
Type = DownloadStationTaskType.NZB,
|
||||
Username = "admin",
|
||||
Title = "title",
|
||||
Additional = new DownloadStationTaskAdditional
|
||||
{
|
||||
Detail = new Dictionary<string, string>
|
||||
{
|
||||
{ "destination","shared/folder" },
|
||||
{ "uri", FileNameBuilder.CleanFileName(_remoteEpisode.Release.Title) + ".nzb" }
|
||||
},
|
||||
Transfer = new Dictionary<string, string>
|
||||
{
|
||||
{ "size_downloaded", "10"},
|
||||
{ "speed_download", "0" }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Mocker.GetMock<IHttpClient>()
|
||||
.Setup(s => s.Get(It.IsAny<HttpRequest>()))
|
||||
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[0]));
|
||||
|
||||
_downloadStationConfigItems = new Dictionary<string, object>
|
||||
{
|
||||
{ "default_destination", _defaultDestination },
|
||||
};
|
||||
|
||||
Mocker.GetMock<IDownloadStationProxy>()
|
||||
.Setup(v => v.GetConfig(It.IsAny<DownloadStationSettings>()))
|
||||
.Returns(_downloadStationConfigItems);
|
||||
}
|
||||
|
||||
protected void GivenSharedFolder()
|
||||
{
|
||||
Mocker.GetMock<ISharedFolderResolver>()
|
||||
.Setup(s => s.RemapToFullPath(It.IsAny<OsPath>(), It.IsAny<DownloadStationSettings>(), It.IsAny<string>()))
|
||||
.Returns<OsPath, DownloadStationSettings, string>((path, setttings, serial) => _physicalPath);
|
||||
}
|
||||
|
||||
protected void GivenSerialNumber()
|
||||
{
|
||||
Mocker.GetMock<ISerialNumberProvider>()
|
||||
.Setup(s => s.GetSerialNumber(It.IsAny<DownloadStationSettings>()))
|
||||
.Returns(_serialNumber);
|
||||
}
|
||||
|
||||
protected void GivenTvCategory()
|
||||
{
|
||||
_settings.TvCategory = _category;
|
||||
}
|
||||
|
||||
protected void GivenTvDirectory()
|
||||
{
|
||||
_settings.TvDirectory = _tvDirectory;
|
||||
}
|
||||
|
||||
protected virtual void GivenNZBs(List<DownloadStationTask> nzbs)
|
||||
{
|
||||
if (nzbs == null)
|
||||
{
|
||||
nzbs = new List<DownloadStationTask>();
|
||||
}
|
||||
|
||||
Mocker.GetMock<IDownloadStationProxy>()
|
||||
.Setup(s => s.GetTasks(DownloadStationTaskType.NZB, It.IsAny<DownloadStationSettings>()))
|
||||
.Returns(nzbs);
|
||||
}
|
||||
|
||||
protected void PrepareClientToReturnQueuedItem()
|
||||
{
|
||||
GivenNZBs(new List<DownloadStationTask>
|
||||
{
|
||||
_queued
|
||||
});
|
||||
}
|
||||
|
||||
protected void GivenSuccessfulDownload()
|
||||
{/*
|
||||
Mocker.GetMock<IHttpClient>()
|
||||
.Setup(s => s.Get(It.IsAny<HttpRequest>()))
|
||||
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[1000]));
|
||||
*/
|
||||
|
||||
Mocker.GetMock<IDownloadStationProxy>()
|
||||
.Setup(s => s.AddTaskFromData(It.IsAny<byte[]>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DownloadStationSettings>()))
|
||||
.Callback(PrepareClientToReturnQueuedItem);
|
||||
}
|
||||
|
||||
protected void GivenAllKindOfTasks()
|
||||
{
|
||||
var tasks = new List<DownloadStationTask>() { _queued, _completed, _failed, _downloading, _seeding };
|
||||
|
||||
Mocker.GetMock<IDownloadStationProxy>()
|
||||
.Setup(d => d.GetTasks(DownloadStationTaskType.NZB, _settings))
|
||||
.Returns(tasks);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Download_with_TvDirectory_should_force_directory()
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenTvDirectory();
|
||||
GivenSuccessfulDownload();
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
Mocker.GetMock<IDownloadStationProxy>()
|
||||
.Verify(v => v.AddTaskFromData(It.IsAny<byte[]>(), It.IsAny<string>(), _tvDirectory, It.IsAny<DownloadStationSettings>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Download_with_category_should_force_directory()
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenTvCategory();
|
||||
GivenSuccessfulDownload();
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
Mocker.GetMock<IDownloadStationProxy>()
|
||||
.Verify(v => v.AddTaskFromData(It.IsAny<byte[]>(), It.IsAny<string>(), $"{_defaultDestination}/{_category}", It.IsAny<DownloadStationSettings>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Download_without_TvDirectory_and_Category_should_use_default()
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenSuccessfulDownload();
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
Mocker.GetMock<IDownloadStationProxy>()
|
||||
.Verify(v => v.AddTaskFromData(It.IsAny<byte[]>(), It.IsAny<string>(), null, It.IsAny<DownloadStationSettings>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_return_empty_list_if_no_tasks_available()
|
||||
{
|
||||
_settings.TvDirectory = @"/shared/folder/sub";
|
||||
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
GivenNZBs(new List<DownloadStationTask>());
|
||||
|
||||
Subject.GetItems().Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_ignore_downloads_in_wrong_folder()
|
||||
{
|
||||
_settings.TvDirectory = @"/shared/folder/sub";
|
||||
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
GivenNZBs(new List<DownloadStationTask> { _completed });
|
||||
|
||||
Subject.GetItems().Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_throw_if_shared_folder_resolve_fails()
|
||||
{
|
||||
Mocker.GetMock<ISharedFolderResolver>()
|
||||
.Setup(s => s.RemapToFullPath(It.IsAny<OsPath>(), It.IsAny<DownloadStationSettings>(), It.IsAny<string>()))
|
||||
.Throws(new ApplicationException("Some unknown exception, HttpException or DownloadClientException"));
|
||||
|
||||
GivenSerialNumber();
|
||||
GivenAllKindOfTasks();
|
||||
|
||||
Assert.Throws(Is.InstanceOf<Exception>(), () => Subject.GetItems());
|
||||
ExceptionVerification.ExpectedErrors(0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_throw_if_serial_number_unavailable()
|
||||
{
|
||||
Mocker.GetMock<ISerialNumberProvider>()
|
||||
.Setup(s => s.GetSerialNumber(_settings))
|
||||
.Throws(new ApplicationException("Some unknown exception, HttpException or DownloadClientException"));
|
||||
|
||||
GivenSharedFolder();
|
||||
GivenAllKindOfTasks();
|
||||
|
||||
Assert.Throws(Is.InstanceOf<Exception>(), () => Subject.GetItems());
|
||||
ExceptionVerification.ExpectedErrors(0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Download_should_throw_and_not_add_tasks_if_cannot_get_serial_number()
|
||||
{
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
Mocker.GetMock<ISerialNumberProvider>()
|
||||
.Setup(s => s.GetSerialNumber(_settings))
|
||||
.Throws(new ApplicationException("Some unknown exception, HttpException or DownloadClientException"));
|
||||
|
||||
Assert.Throws(Is.InstanceOf<Exception>(), () => Subject.Download(remoteEpisode));
|
||||
|
||||
Mocker.GetMock<IDownloadStationProxy>()
|
||||
.Verify(v => v.AddTaskFromUrl(It.IsAny<string>(), null, _settings), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_not_map_outputpath_for_queued_or_downloading_tasks()
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
|
||||
GivenNZBs(new List<DownloadStationTask>
|
||||
{
|
||||
_queued, _downloading
|
||||
});
|
||||
|
||||
var items = Subject.GetItems();
|
||||
|
||||
items.Should().HaveCount(2);
|
||||
items.Should().OnlyContain(v => v.OutputPath.IsEmpty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_map_outputpath_for_completed_or_failed_tasks()
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
|
||||
GivenNZBs(new List<DownloadStationTask>
|
||||
{
|
||||
_completed, _failed, _seeding
|
||||
});
|
||||
|
||||
var items = Subject.GetItems();
|
||||
|
||||
items.Should().HaveCount(3);
|
||||
items.Should().OnlyContain(v => !v.OutputPath.IsEmpty);
|
||||
}
|
||||
|
||||
[TestCase(DownloadStationTaskStatus.Downloading, DownloadItemStatus.Downloading, true)]
|
||||
[TestCase(DownloadStationTaskStatus.Finished, DownloadItemStatus.Completed, false)]
|
||||
[TestCase(DownloadStationTaskStatus.Waiting, DownloadItemStatus.Queued, true)]
|
||||
public void GetItems_should_return_readonly_expected(DownloadStationTaskStatus apiStatus, DownloadItemStatus expectedItemStatus, bool readOnlyExpected)
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
|
||||
_queued.Status = apiStatus;
|
||||
|
||||
GivenNZBs(new List<DownloadStationTask>() { _queued });
|
||||
|
||||
var items = Subject.GetItems();
|
||||
|
||||
items.Should().HaveCount(1);
|
||||
items.First().IsReadOnly.Should().Be(readOnlyExpected);
|
||||
}
|
||||
|
||||
[TestCase(DownloadStationTaskStatus.Downloading, DownloadItemStatus.Downloading)]
|
||||
[TestCase(DownloadStationTaskStatus.Error, DownloadItemStatus.Failed)]
|
||||
[TestCase(DownloadStationTaskStatus.Extracting, DownloadItemStatus.Downloading)]
|
||||
[TestCase(DownloadStationTaskStatus.Finished, DownloadItemStatus.Completed)]
|
||||
[TestCase(DownloadStationTaskStatus.Finishing, DownloadItemStatus.Downloading)]
|
||||
[TestCase(DownloadStationTaskStatus.HashChecking, DownloadItemStatus.Downloading)]
|
||||
[TestCase(DownloadStationTaskStatus.Paused, DownloadItemStatus.Paused)]
|
||||
[TestCase(DownloadStationTaskStatus.Waiting, DownloadItemStatus.Queued)]
|
||||
public void GetItems_should_return_item_as_downloadItemStatus(DownloadStationTaskStatus apiStatus, DownloadItemStatus expectedItemStatus)
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
|
||||
_queued.Status = apiStatus;
|
||||
|
||||
GivenNZBs(new List<DownloadStationTask>() { _queued });
|
||||
|
||||
var items = Subject.GetItems();
|
||||
items.Should().HaveCount(1);
|
||||
|
||||
items.First().Status.Should().Be(expectedItemStatus);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user