New: Choose extension for magnet links in Torrent Blackhole

Co-Authored-By: Mark McDowall <markus101@users.noreply.github.com>
This commit is contained in:
Qstick
2018-09-13 22:28:17 -04:00
parent 622e2de07d
commit d61ba76574
3 changed files with 33 additions and 5 deletions
@@ -32,7 +32,6 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
_completedDownloadFolder = @"c:\blackhole\completed".AsOsAgnostic();
_blackholeFolder = @"c:\blackhole\torrent".AsOsAgnostic();
_filePath = (@"c:\blackhole\torrent\" + _title + ".torrent").AsOsAgnostic();
_magnetFilePath = Path.ChangeExtension(_filePath, ".magnet");
Mocker.SetConstant<IScanWatchFolder>(Mocker.Resolve<ScanWatchFolder>());
@@ -79,6 +78,11 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
.Returns(1000000);
}
protected void GivenMagnetFilePath(string extension = ".magnet")
{
_magnetFilePath = Path.ChangeExtension(_filePath, extension);
}
protected override RemoteAlbum CreateRemoteAlbum()
{
var remoteAlbum = base.CreateRemoteAlbum();
@@ -145,7 +149,25 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
[Test]
public void Download_should_save_magnet_if_enabled()
{
GivenMagnetFilePath();
Subject.Definition.Settings.As<TorrentBlackholeSettings>().SaveMagnetFiles = true;
var remoteAlbum = CreateRemoteAlbum();
remoteAlbum.Release.DownloadUrl = null;
Subject.Download(remoteAlbum);
Mocker.GetMock<IHttpClient>().Verify(c => c.Get(It.Is<HttpRequest>(v => v.Url.FullUri == _downloadUrl)), Times.Never());
Mocker.GetMock<IDiskProvider>().Verify(c => c.OpenWriteStream(_filePath), Times.Never());
Mocker.GetMock<IDiskProvider>().Verify(c => c.OpenWriteStream(_magnetFilePath), Times.Once());
Mocker.GetMock<IHttpClient>().Verify(c => c.DownloadFile(It.IsAny<string>(), It.IsAny<string>()), Times.Never());
}
[Test]
public void Download_should_save_magnet_using_specified_extension()
{
var magnetFileExtension = ".url";
GivenMagnetFilePath(magnetFileExtension);
Subject.Definition.Settings.As<TorrentBlackholeSettings>().SaveMagnetFiles = true;
Subject.Definition.Settings.As<TorrentBlackholeSettings>().MagnetFileExtension = magnetFileExtension;
var remoteAlbum = CreateRemoteAlbum();
remoteAlbum.Release.DownloadUrl = null;
@@ -161,6 +183,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
[Test]
public void Download_should_not_save_magnet_if_disabled()
{
GivenMagnetFilePath();
var remoteAlbum = CreateRemoteAlbum();
remoteAlbum.Release.DownloadUrl = null;