1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-26 01:37:07 +00:00
Sonarr/NzbDrone.Core.Test/Download/DownloadClientTests/BlackholeProviderFixture.cs

79 lines
2.6 KiB
C#
Raw Normal View History

using System.IO;
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;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
2013-04-01 06:22:16 +00:00
namespace NzbDrone.Core.Test.Download.DownloadClientTests
{
[TestFixture]
2013-04-07 17:53:04 +00:00
public class BlackholeProviderFixture : CoreTest<BlackholeProvider>
{
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";
[SetUp]
public void Setup()
{
2013-02-24 19:39:31 +00:00
Mocker.GetMock<IConfigService>().SetupGet(c => c.BlackholeDirectory).Returns(blackHoleFolder);
}
private void WithExistingFile()
{
Mocker.GetMock<DiskProvider>().Setup(c => c.FileExists(nzbPath)).Returns(true);
}
private void WithFailedDownload()
{
Mocker.GetMock<HttpProvider>().Setup(c => c.DownloadFile(It.IsAny<string>(), It.IsAny<string>())).Throws(new WebException());
}
[Test]
public void DownloadNzb_should_download_file_if_it_doesnt_exist()
{
2013-04-07 17:53:04 +00:00
Subject.DownloadNzb(nzbUrl, title, false).Should().BeTrue();
2013-04-07 17:53:04 +00:00
Mocker.GetMock<HttpProvider>().Verify(c => c.DownloadFile(nzbUrl, nzbPath), Times.Once());
}
[Test]
public void DownloadNzb_not_download_file_if_it_doesn_exist()
{
WithExistingFile();
2013-04-07 17:53:04 +00:00
Subject.DownloadNzb(nzbUrl, title, false).Should().BeTrue();
Mocker.GetMock<HttpProvider>().Verify(c => c.DownloadFile(It.IsAny<string>(), It.IsAny<string>()), Times.Never());
}
[Test]
public void should_return_false_on_failed_download()
{
WithFailedDownload();
2013-04-07 17:53:04 +00:00
Subject.DownloadNzb(nzbUrl, title, false).Should().BeFalse();
ExceptionVerification.ExpectedWarns(1);
}
[Test]
public void should_replace_illegal_characters_in_title()
{
var illegalTitle = "Saturday Night Live - S38E08 - Jeremy Renner/Maroon 5 [SDTV]";
var expectedFilename = Path.Combine(blackHoleFolder, "Saturday Night Live - S38E08 - Jeremy Renner+Maroon 5 [SDTV].nzb");
2013-04-07 17:53:04 +00:00
Subject.DownloadNzb(nzbUrl, illegalTitle, false).Should().BeTrue();
Mocker.GetMock<HttpProvider>().Verify(c => c.DownloadFile(It.IsAny<string>(), expectedFilename), Times.Once());
}
}
}