|
|
|
@ -1,9 +1,11 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using NzbDrone.Common.Disk;
|
|
|
|
|
using NzbDrone.Common.Http;
|
|
|
|
|
using NzbDrone.Core.MediaFiles.TorrentInfo;
|
|
|
|
|
using NzbDrone.Core.Download;
|
|
|
|
@ -122,6 +124,24 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
|
|
|
|
|
Mocker.GetMock<IQBittorrentProxy>()
|
|
|
|
|
.Setup(s => s.GetTorrents(It.IsAny<QBittorrentSettings>()))
|
|
|
|
|
.Returns(torrents);
|
|
|
|
|
|
|
|
|
|
foreach (var torrent in torrents)
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<IQBittorrentProxy>()
|
|
|
|
|
.Setup(s => s.GetTorrentProperties(torrent.Hash.ToLower(), It.IsAny<QBittorrentSettings>()))
|
|
|
|
|
.Returns(new QBittorrentTorrentProperties { SavePath = torrent.SavePath });
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IQBittorrentProxy>()
|
|
|
|
|
.Setup(s => s.GetTorrentFiles(torrent.Hash.ToLower(), It.IsAny<QBittorrentSettings>()))
|
|
|
|
|
.Returns(new List<QBittorrentTorrentFile> { new QBittorrentTorrentFile { Name = torrent.Name } });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GivenTorrentFiles(string hash, List<QBittorrentTorrentFile> files)
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<IQBittorrentProxy>()
|
|
|
|
|
.Setup(s => s.GetTorrentFiles(hash.ToLower(), It.IsAny<QBittorrentSettings>()))
|
|
|
|
|
.Returns(files);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
@ -256,6 +276,112 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.QBittorrentTests
|
|
|
|
|
item.RemainingTime.Should().NotHaveValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void single_file_torrent_outputpath_should_have_sanitised_name()
|
|
|
|
|
{
|
|
|
|
|
var torrent = new QBittorrentTorrent
|
|
|
|
|
{
|
|
|
|
|
Hash = "HASH",
|
|
|
|
|
Name = @"Droned.S01E01.Test\'s.1080p.WEB-DL-DRONE.mkv",
|
|
|
|
|
Size = 1000,
|
|
|
|
|
Progress = 0.7,
|
|
|
|
|
Eta = 8640000,
|
|
|
|
|
State = "stalledDL",
|
|
|
|
|
Label = "",
|
|
|
|
|
SavePath = @"C:\Torrents".AsOsAgnostic()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var file = new QBittorrentTorrentFile
|
|
|
|
|
{
|
|
|
|
|
Name = "Droned.S01E01.Tests.1080p.WEB-DL-DRONE.mkv"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
GivenTorrents(new List<QBittorrentTorrent> { torrent });
|
|
|
|
|
GivenTorrentFiles(torrent.Hash, new List<QBittorrentTorrentFile> { file });
|
|
|
|
|
|
|
|
|
|
var item = new DownloadClientItem
|
|
|
|
|
{
|
|
|
|
|
DownloadId = torrent.Hash
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var result = Subject.GetImportItem(item, null);
|
|
|
|
|
|
|
|
|
|
result.OutputPath.FullPath.Should().Be(Path.Combine(torrent.SavePath, file.Name));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void multi_file_torrent_outputpath_should_have_sanitised_name()
|
|
|
|
|
{
|
|
|
|
|
var torrent = new QBittorrentTorrent
|
|
|
|
|
{
|
|
|
|
|
Hash = "HASH",
|
|
|
|
|
Name = @"Droned.S01.\1/2",
|
|
|
|
|
Size = 1000,
|
|
|
|
|
Progress = 0.7,
|
|
|
|
|
Eta = 8640000,
|
|
|
|
|
State = "stalledDL",
|
|
|
|
|
Label = "",
|
|
|
|
|
SavePath = @"C:\Torrents".AsOsAgnostic()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var files = new List<QBittorrentTorrentFile>
|
|
|
|
|
{
|
|
|
|
|
new QBittorrentTorrentFile
|
|
|
|
|
{
|
|
|
|
|
Name = @"Droned.S01.12\E01.mkv".AsOsAgnostic()
|
|
|
|
|
},
|
|
|
|
|
new QBittorrentTorrentFile
|
|
|
|
|
{
|
|
|
|
|
Name = @"Droned.S01.12\E02.mkv".AsOsAgnostic()
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
GivenTorrents(new List<QBittorrentTorrent> { torrent });
|
|
|
|
|
GivenTorrentFiles(torrent.Hash, files);
|
|
|
|
|
|
|
|
|
|
var item = new DownloadClientItem
|
|
|
|
|
{
|
|
|
|
|
DownloadId = torrent.Hash
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var result = Subject.GetImportItem(item, null);
|
|
|
|
|
|
|
|
|
|
result.OutputPath.FullPath.Should().Be(Path.Combine(torrent.SavePath, "Droned.S01.12") + Path.DirectorySeparatorChar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void api_261_should_use_content_path()
|
|
|
|
|
{
|
|
|
|
|
var torrent = new QBittorrentTorrent
|
|
|
|
|
{
|
|
|
|
|
Hash = "HASH",
|
|
|
|
|
Name = @"Droned.S01.\1/2",
|
|
|
|
|
Size = 1000,
|
|
|
|
|
Progress = 0.7,
|
|
|
|
|
Eta = 8640000,
|
|
|
|
|
State = "stalledDL",
|
|
|
|
|
Label = "",
|
|
|
|
|
SavePath = @"C:\Torrents".AsOsAgnostic(),
|
|
|
|
|
ContentPath = @"C:\Torrents\Droned.S01.12".AsOsAgnostic()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
GivenTorrents(new List<QBittorrentTorrent> { torrent });
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IQBittorrentProxy>()
|
|
|
|
|
.Setup(v => v.GetApiVersion(It.IsAny<QBittorrentSettings>()))
|
|
|
|
|
.Returns(new Version(2, 6, 1));
|
|
|
|
|
|
|
|
|
|
var item = new DownloadClientItem
|
|
|
|
|
{
|
|
|
|
|
DownloadId = torrent.Hash,
|
|
|
|
|
OutputPath = new OsPath(torrent.ContentPath)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var result = Subject.GetImportItem(item, null);
|
|
|
|
|
|
|
|
|
|
result.OutputPath.FullPath.Should().Be(torrent.ContentPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Download_should_return_unique_id()
|
|
|
|
|
{
|
|
|
|
|