2012-11-19 02:17:00 +00:00
|
|
|
using System.IO;
|
2012-02-07 05:08:07 +00:00
|
|
|
using System.Net;
|
|
|
|
using FluentAssertions;
|
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using NzbDrone.Common;
|
2013-02-24 06:48:52 +00:00
|
|
|
using NzbDrone.Core.Configuration;
|
2013-03-05 05:33:34 +00:00
|
|
|
using NzbDrone.Core.Download.Clients;
|
2013-07-08 03:15:15 +00:00
|
|
|
using NzbDrone.Core.Parser.Model;
|
2012-02-07 05:08:07 +00:00
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
using NzbDrone.Test.Common;
|
|
|
|
|
2013-04-01 06:22:16 +00:00
|
|
|
namespace NzbDrone.Core.Test.Download.DownloadClientTests
|
2012-02-07 05:08:07 +00:00
|
|
|
{
|
|
|
|
[TestFixture]
|
2013-04-07 17:53:04 +00:00
|
|
|
public class BlackholeProviderFixture : CoreTest<BlackholeProvider>
|
2012-02-07 05:08:07 +00:00
|
|
|
{
|
2013-07-08 03:15:15 +00:00
|
|
|
private const string _nzbUrl = "http://www.nzbs.com/url";
|
|
|
|
private const string _title = "some_nzb_title";
|
|
|
|
private const string _blackHoleFolder = @"d:\nzb\blackhole\";
|
|
|
|
private const string _nzbPath = @"d:\nzb\blackhole\some_nzb_title.nzb";
|
|
|
|
private RemoteEpisode _remoteEpisode;
|
2012-02-07 05:08:07 +00:00
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void Setup()
|
|
|
|
{
|
2013-07-08 03:15:15 +00:00
|
|
|
Mocker.GetMock<IConfigService>().SetupGet(c => c.BlackholeFolder).Returns(_blackHoleFolder);
|
2012-02-07 05:08:07 +00:00
|
|
|
|
2013-07-08 03:15:15 +00:00
|
|
|
_remoteEpisode = new RemoteEpisode();
|
|
|
|
_remoteEpisode.Report = new ReportInfo();
|
|
|
|
_remoteEpisode.Report.Title = _title;
|
|
|
|
_remoteEpisode.Report.NzbUrl = _nzbUrl;
|
|
|
|
}
|
2012-02-07 05:08:07 +00:00
|
|
|
|
|
|
|
private void WithExistingFile()
|
|
|
|
{
|
2013-07-08 03:15:15 +00:00
|
|
|
Mocker.GetMock<IDiskProvider>().Setup(c => c.FileExists(_nzbPath)).Returns(true);
|
2012-02-07 05:08:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void WithFailedDownload()
|
|
|
|
{
|
2013-04-10 23:41:45 +00:00
|
|
|
Mocker.GetMock<IHttpProvider>().Setup(c => c.DownloadFile(It.IsAny<string>(), It.IsAny<string>())).Throws(new WebException());
|
2012-02-07 05:08:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void DownloadNzb_should_download_file_if_it_doesnt_exist()
|
|
|
|
{
|
2013-07-08 03:15:15 +00:00
|
|
|
Subject.DownloadNzb(_remoteEpisode).Should().BeTrue();
|
2012-02-07 05:08:07 +00:00
|
|
|
|
2013-07-08 03:15:15 +00:00
|
|
|
Mocker.GetMock<IHttpProvider>().Verify(c => c.DownloadFile(_nzbUrl, _nzbPath), Times.Once());
|
2012-02-07 05:08:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void DownloadNzb_not_download_file_if_it_doesn_exist()
|
|
|
|
{
|
|
|
|
WithExistingFile();
|
|
|
|
|
2013-07-08 03:15:15 +00:00
|
|
|
Subject.DownloadNzb(_remoteEpisode).Should().BeTrue();
|
2012-02-07 05:08:07 +00:00
|
|
|
|
2013-04-10 23:41:45 +00:00
|
|
|
Mocker.GetMock<IHttpProvider>().Verify(c => c.DownloadFile(It.IsAny<string>(), It.IsAny<string>()), Times.Never());
|
2012-02-07 05:08:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void should_return_false_on_failed_download()
|
|
|
|
{
|
|
|
|
WithFailedDownload();
|
|
|
|
|
2013-07-08 03:15:15 +00:00
|
|
|
Subject.DownloadNzb(_remoteEpisode).Should().BeFalse();
|
2013-04-07 17:53:04 +00:00
|
|
|
|
2012-02-07 05:08:07 +00:00
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
|
|
|
}
|
|
|
|
|
2012-11-19 02:17:00 +00:00
|
|
|
[Test]
|
|
|
|
public void should_replace_illegal_characters_in_title()
|
|
|
|
{
|
|
|
|
var illegalTitle = "Saturday Night Live - S38E08 - Jeremy Renner/Maroon 5 [SDTV]";
|
2013-07-08 03:15:15 +00:00
|
|
|
var expectedFilename = Path.Combine(_blackHoleFolder, "Saturday Night Live - S38E08 - Jeremy Renner+Maroon 5 [SDTV].nzb");
|
|
|
|
_remoteEpisode.Report.Title = illegalTitle;
|
2012-02-07 05:08:07 +00:00
|
|
|
|
2013-07-08 03:15:15 +00:00
|
|
|
Subject.DownloadNzb(_remoteEpisode).Should().BeTrue();
|
2012-11-19 02:17:00 +00:00
|
|
|
|
2013-04-10 23:41:45 +00:00
|
|
|
Mocker.GetMock<IHttpProvider>().Verify(c => c.DownloadFile(It.IsAny<string>(), expectedFilename), Times.Once());
|
2012-11-19 02:17:00 +00:00
|
|
|
}
|
2012-02-07 05:08:07 +00:00
|
|
|
}
|
|
|
|
}
|