1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00
Sonarr/NzbDrone.Core.Test/Download/DownloadClientTests/PneumaticProviderFixture.cs

94 lines
3.2 KiB
C#
Raw Normal View History

2013-08-18 02:27:18 +03:00
using System;
using System.IO;
2012-08-30 03:20:48 +03:00
using System.Net;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
2013-02-24 09:48:52 +03:00
using NzbDrone.Core.Configuration;
2013-03-05 08:33:34 +03:00
using NzbDrone.Core.Download.Clients;
using NzbDrone.Core.Parser.Model;
2012-08-30 03:20:48 +03:00
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
2013-04-01 09:22:16 +03:00
namespace NzbDrone.Core.Test.Download.DownloadClientTests
2012-08-30 03:20:48 +03:00
{
[TestFixture]
public class PneumaticProviderFixture : CoreTest<PneumaticClient>
2012-08-30 03:20:48 +03:00
{
private const string _nzbUrl = "http://www.nzbs.com/url";
private const string _title = "30.Rock.S01E05.hdtv.xvid-LoL";
2013-07-26 08:29:59 +03:00
private string _pneumaticFolder;
private string _sabDrop;
private string _nzbPath;
private RemoteEpisode _remoteEpisode;
2012-08-30 03:20:48 +03:00
[SetUp]
public void Setup()
{
2013-07-26 08:29:59 +03:00
_pneumaticFolder = @"d:\nzb\pneumatic\".AsOsAgnostic();
_nzbPath = Path.Combine(_pneumaticFolder, _title + ".nzb").AsOsAgnostic();
_sabDrop = @"d:\unsorted tv\".AsOsAgnostic();
2012-08-30 18:33:09 +03:00
Mocker.GetMock<IConfigService>().SetupGet(c => c.PneumaticFolder).Returns(_pneumaticFolder);
Mocker.GetMock<IConfigService>().SetupGet(c => c.DownloadedEpisodesFolder).Returns(_sabDrop);
_remoteEpisode = new RemoteEpisode();
_remoteEpisode.Report = new ReportInfo();
_remoteEpisode.Report.Title = _title;
_remoteEpisode.Report.NzbUrl = _nzbUrl;
_remoteEpisode.ParsedEpisodeInfo = new ParsedEpisodeInfo();
_remoteEpisode.ParsedEpisodeInfo.FullSeason = false;
2012-08-30 03:20:48 +03:00
}
private void WithExistingFile()
{
Mocker.GetMock<IDiskProvider>().Setup(c => c.FileExists(_nzbPath)).Returns(true);
2012-08-30 03:20:48 +03:00
}
private void WithFailedDownload()
{
2013-04-11 02:41:45 +03:00
Mocker.GetMock<IHttpProvider>().Setup(c => c.DownloadFile(It.IsAny<string>(), It.IsAny<string>())).Throws(new WebException());
2012-08-30 03:20:48 +03:00
}
[Test]
public void should_download_file_if_it_doesnt_exist()
{
2013-08-18 02:27:18 +03:00
Subject.DownloadNzb(_remoteEpisode);
2012-08-30 03:20:48 +03:00
2013-07-26 08:29:59 +03:00
Mocker.GetMock<IHttpProvider>().Verify(c => c.DownloadFile(_nzbUrl, _nzbPath), Times.Once());
2012-08-30 03:20:48 +03:00
}
[Test]
2013-08-18 02:27:18 +03:00
public void should_throw_on_failed_download()
2012-08-30 03:20:48 +03:00
{
WithFailedDownload();
2013-08-18 02:27:18 +03:00
Assert.Throws<WebException>(() => Subject.DownloadNzb(_remoteEpisode));
2012-08-30 03:20:48 +03:00
}
[Test]
2013-08-18 02:27:18 +03:00
public void should_throw_if_full_season_download()
2012-08-30 03:20:48 +03:00
{
_remoteEpisode.Report.Title = "30 Rock - Season 1";
_remoteEpisode.ParsedEpisodeInfo.FullSeason = true;
2013-08-18 02:27:18 +03:00
Assert.Throws<NotImplementedException>(() => Subject.DownloadNzb(_remoteEpisode));
2012-08-30 03:20:48 +03: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");
_remoteEpisode.Report.Title = illegalTitle;
2013-08-18 02:27:18 +03:00
Subject.DownloadNzb(_remoteEpisode);
2013-04-11 02:41:45 +03:00
Mocker.GetMock<IHttpProvider>().Verify(c => c.DownloadFile(It.IsAny<string>(), expectedFilename), Times.Once());
}
2012-08-30 03:20:48 +03:00
}
}