2012-08-30 00:20:48 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2012-11-19 02:17:00 +00:00
|
|
|
|
using System.IO;
|
2012-08-30 00:20:48 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Text;
|
|
|
|
|
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;
|
2012-08-30 00:20:48 +00:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
using NzbDrone.Test.Common;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2013-02-17 05:44:06 +00:00
|
|
|
|
public class PneumaticProviderFixture : CoreTest
|
2012-08-30 00:20:48 +00:00
|
|
|
|
{
|
|
|
|
|
private const string nzbUrl = "http://www.nzbs.com/url";
|
2012-08-30 15:33:09 +00:00
|
|
|
|
private const string title = "30.Rock.S01E05.hdtv.xvid-LoL";
|
2012-08-30 00:20:48 +00:00
|
|
|
|
private const string pneumaticFolder = @"d:\nzb\pneumatic\";
|
2012-08-30 15:33:09 +00:00
|
|
|
|
private const string sabDrop = @"d:\unsorted tv\";
|
|
|
|
|
private string nzbPath;
|
2012-08-30 00:20:48 +00:00
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
2012-08-30 15:33:09 +00:00
|
|
|
|
nzbPath = pneumaticFolder + title + ".nzb";
|
|
|
|
|
|
2013-02-24 19:39:31 +00:00
|
|
|
|
Mocker.GetMock<IConfigService>().SetupGet(c => c.PneumaticDirectory).Returns(pneumaticFolder);
|
|
|
|
|
Mocker.GetMock<IConfigService>().SetupGet(c => c.DownloadClientTvDirectory).Returns(sabDrop);
|
2012-08-30 00:20:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 should_download_file_if_it_doesnt_exist()
|
|
|
|
|
{
|
2012-11-23 02:56:27 +00:00
|
|
|
|
Mocker.Resolve<PneumaticProvider>().DownloadNzb(nzbUrl, title, false).Should().BeTrue();
|
2012-08-30 00:20:48 +00:00
|
|
|
|
|
|
|
|
|
Mocker.GetMock<HttpProvider>().Verify(c => c.DownloadFile(nzbUrl, nzbPath),Times.Once());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_download_file_if_it_doesn_exist()
|
|
|
|
|
{
|
|
|
|
|
WithExistingFile();
|
|
|
|
|
|
2012-11-23 02:56:27 +00:00
|
|
|
|
Mocker.Resolve<PneumaticProvider>().DownloadNzb(nzbUrl, title, false).Should().BeTrue();
|
2012-08-30 00:20:48 +00:00
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
2012-11-23 02:56:27 +00:00
|
|
|
|
Mocker.Resolve<PneumaticProvider>().DownloadNzb(nzbUrl, title, false).Should().BeFalse();
|
2012-08-30 00:20:48 +00:00
|
|
|
|
|
|
|
|
|
ExceptionVerification.ExpectedWarns(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_skip_if_full_season_download()
|
|
|
|
|
{
|
2012-11-23 02:56:27 +00:00
|
|
|
|
Mocker.Resolve<PneumaticProvider>().DownloadNzb(nzbUrl, "30 Rock - Season 1", false).Should().BeFalse();
|
2012-08-30 00:20:48 +00:00
|
|
|
|
}
|
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]";
|
|
|
|
|
var expectedFilename = Path.Combine(pneumaticFolder, "Saturday Night Live - S38E08 - Jeremy Renner+Maroon 5 [SDTV].nzb");
|
|
|
|
|
|
2012-11-23 02:56:27 +00:00
|
|
|
|
Mocker.Resolve<PneumaticProvider>().DownloadNzb(nzbUrl, illegalTitle, false).Should().BeTrue();
|
2012-11-19 02:17:00 +00:00
|
|
|
|
|
|
|
|
|
Mocker.GetMock<HttpProvider>().Verify(c => c.DownloadFile(It.IsAny<string>(), expectedFilename), Times.Once());
|
|
|
|
|
}
|
2012-08-30 00:20:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|