diff --git a/NzbDrone.Core.Test/Download/DownloadClientTests/BlackholeProviderFixture.cs b/NzbDrone.Core.Test/Download/DownloadClientTests/BlackholeProviderFixture.cs index 91bdbf0cc..6229aaf8a 100644 --- a/NzbDrone.Core.Test/Download/DownloadClientTests/BlackholeProviderFixture.cs +++ b/NzbDrone.Core.Test/Download/DownloadClientTests/BlackholeProviderFixture.cs @@ -1,6 +1,5 @@ using System.IO; using System.Net; -using FluentAssertions; using Moq; using NUnit.Framework; using NzbDrone.Common; @@ -49,31 +48,11 @@ private void WithFailedDownload() [Test] public void DownloadNzb_should_download_file_if_it_doesnt_exist() { - Subject.DownloadNzb(_remoteEpisode).Should().BeTrue(); + Subject.DownloadNzb(_remoteEpisode); Mocker.GetMock().Verify(c => c.DownloadFile(_nzbUrl, _nzbPath), Times.Once()); } - [Test] - public void DownloadNzb_not_download_file_if_it_doesn_exist() - { - WithExistingFile(); - - Subject.DownloadNzb(_remoteEpisode).Should().BeTrue(); - - Mocker.GetMock().Verify(c => c.DownloadFile(It.IsAny(), It.IsAny()), Times.Never()); - } - - [Test] - public void should_return_false_on_failed_download() - { - WithFailedDownload(); - - Subject.DownloadNzb(_remoteEpisode).Should().BeFalse(); - - ExceptionVerification.ExpectedWarns(1); - } - [Test] public void should_replace_illegal_characters_in_title() { @@ -81,7 +60,7 @@ public void should_replace_illegal_characters_in_title() var expectedFilename = Path.Combine(_blackHoleFolder, "Saturday Night Live - S38E08 - Jeremy Renner+Maroon 5 [SDTV].nzb"); _remoteEpisode.Report.Title = illegalTitle; - Subject.DownloadNzb(_remoteEpisode).Should().BeTrue(); + Subject.DownloadNzb(_remoteEpisode); Mocker.GetMock().Verify(c => c.DownloadFile(It.IsAny(), expectedFilename), Times.Once()); } diff --git a/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetProviderTests/DownloadNzbFixture.cs b/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetProviderTests/DownloadNzbFixture.cs index 0b83050bf..937a39aaf 100644 --- a/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetProviderTests/DownloadNzbFixture.cs +++ b/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetProviderTests/DownloadNzbFixture.cs @@ -57,10 +57,7 @@ public void should_add_item_to_queue() It.Is(c => c.Equals("{\"method\":\"appendurl\",\"params\":[\"30 Rock - S01E01 - Pilot [HDTV-720p]\",\"TV\",50,false,\"http://www.nzbdrone.com\"]}")))) .Returns("{\"version\": \"1.1\",\"result\": true}"); - Mocker.Resolve() - .DownloadNzb(_remoteEpisode) - .Should() - .BeTrue(); + Mocker.Resolve().DownloadNzb(_remoteEpisode); } [Test] diff --git a/NzbDrone.Core.Test/Download/DownloadClientTests/PneumaticProviderFixture.cs b/NzbDrone.Core.Test/Download/DownloadClientTests/PneumaticProviderFixture.cs index 90dfdc2a1..66b3695cc 100644 --- a/NzbDrone.Core.Test/Download/DownloadClientTests/PneumaticProviderFixture.cs +++ b/NzbDrone.Core.Test/Download/DownloadClientTests/PneumaticProviderFixture.cs @@ -1,6 +1,6 @@ +using System; using System.IO; using System.Net; -using FluentAssertions; using Moq; using NUnit.Framework; using NzbDrone.Common; @@ -55,38 +55,27 @@ private void WithFailedDownload() [Test] public void should_download_file_if_it_doesnt_exist() { - Subject.DownloadNzb(_remoteEpisode).Should().BeTrue(); + Subject.DownloadNzb(_remoteEpisode); Mocker.GetMock().Verify(c => c.DownloadFile(_nzbUrl, _nzbPath), Times.Once()); } - [Test] - public void should_not_download_file_if_it_doesn_exist() - { - WithExistingFile(); - - Subject.DownloadNzb(_remoteEpisode).Should().BeTrue(); - - Mocker.GetMock().Verify(c => c.DownloadFile(It.IsAny(), It.IsAny()), Times.Never()); - } [Test] - public void should_return_false_on_failed_download() + public void should_throw_on_failed_download() { WithFailedDownload(); - Subject.DownloadNzb(_remoteEpisode).Should().BeFalse(); - - ExceptionVerification.ExpectedWarns(1); + Assert.Throws(() => Subject.DownloadNzb(_remoteEpisode)); } [Test] - public void should_skip_if_full_season_download() + public void should_throw_if_full_season_download() { _remoteEpisode.Report.Title = "30 Rock - Season 1"; _remoteEpisode.ParsedEpisodeInfo.FullSeason = true; - Mocker.Resolve().DownloadNzb(_remoteEpisode).Should().BeFalse(); + Assert.Throws(() => Subject.DownloadNzb(_remoteEpisode)); } [Test] @@ -96,7 +85,7 @@ public void should_replace_illegal_characters_in_title() var expectedFilename = Path.Combine(_pneumaticFolder, "Saturday Night Live - S38E08 - Jeremy Renner+Maroon 5 [SDTV].nzb"); _remoteEpisode.Report.Title = illegalTitle; - Subject.DownloadNzb(_remoteEpisode).Should().BeTrue(); + Subject.DownloadNzb(_remoteEpisode); Mocker.GetMock().Verify(c => c.DownloadFile(It.IsAny(), expectedFilename), Times.Once()); } diff --git a/NzbDrone.Core.Test/Download/DownloadClientTests/SabProviderTests/SabProviderFixture.cs b/NzbDrone.Core.Test/Download/DownloadClientTests/SabProviderTests/SabProviderFixture.cs index 0ec06fef8..111347602 100644 --- a/NzbDrone.Core.Test/Download/DownloadClientTests/SabProviderTests/SabProviderFixture.cs +++ b/NzbDrone.Core.Test/Download/DownloadClientTests/SabProviderTests/SabProviderFixture.cs @@ -61,14 +61,14 @@ public void add_url_should_format_request_properly() .Returns("{ \"status\": true }"); - Subject.DownloadNzb(_remoteEpisode).Should().BeTrue(); + Subject.DownloadNzb(_remoteEpisode); } [Test] public void add_by_url_should_detect_and_handle_sab_errors() { WithFailResponse(); - Assert.Throws(() => Subject.DownloadNzb(_remoteEpisode).Should().BeFalse()); + Assert.Throws(() => Subject.DownloadNzb(_remoteEpisode)); } [Test] @@ -197,13 +197,12 @@ public void Test_should_return_version_as_a_string() } [Test] - public void should_return_false_when_WebException_is_thrown() + public void should_throw_when_WebException_is_thrown() { Mocker.GetMock() .Setup(s => s.DownloadString(It.IsAny())).Throws(new WebException()); - Subject.DownloadNzb(_remoteEpisode).Should().BeFalse(); - ExceptionVerification.ExpectedErrors(1); + Assert.Throws(() => Subject.DownloadNzb(_remoteEpisode)); } [Test] @@ -219,7 +218,7 @@ public void downloadNzb_should_use_sabRecentTvPriority_when_recentEpisode_is_tru .Returns("{ \"status\": true }"); - Subject.DownloadNzb(_remoteEpisode).Should().BeTrue(); + Subject.DownloadNzb(_remoteEpisode); Mocker.GetMock() .Verify(v => v.DownloadString("http://192.168.5.55:2222/api?mode=addurl&name=http://www.nzbclub.com/nzb_download.aspx?mid=1950232&priority=1&pp=3&cat=tv&nzbname=My+Series+Name+-+5x2-5x3+-+My+title+%5bBluray720p%5d+%5bProper%5d&output=json&apikey=5c770e3197e4fe763423ee7c392c25d1&ma_username=admin&ma_password=pass"), Times.Once()); diff --git a/NzbDrone.Core.Test/Download/DownloadServiceFixture.cs b/NzbDrone.Core.Test/Download/DownloadServiceFixture.cs index 32b859c0e..cc0285b78 100644 --- a/NzbDrone.Core.Test/Download/DownloadServiceFixture.cs +++ b/NzbDrone.Core.Test/Download/DownloadServiceFixture.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Net; using FizzWare.NBuilder; using Moq; using NUnit.Framework; @@ -40,15 +41,14 @@ public void Setup() private void WithSuccessfulAdd() { Mocker.GetMock() - .Setup(s => s.DownloadNzb(It.IsAny())) - .Returns(true); + .Setup(s => s.DownloadNzb(It.IsAny())); } private void WithFailedAdd() { Mocker.GetMock() .Setup(s => s.DownloadNzb(It.IsAny())) - .Returns(false); + .Throws(new WebException()); } [Test] @@ -77,7 +77,8 @@ public void Download_report_should_not_publish_on_failed_grab_event() { WithFailedAdd(); - Subject.DownloadReport(_parseResult); + Assert.Throws(() => Subject.DownloadReport(_parseResult)); + VerifyEventNotPublished(); } @@ -90,7 +91,7 @@ public void should_not_attempt_download_if_client_isnt_configure() Subject.DownloadReport(_parseResult); - Mocker.GetMock().Verify(c => c.DownloadNzb(It.IsAny()),Times.Never()); + Mocker.GetMock().Verify(c => c.DownloadNzb(It.IsAny()), Times.Never()); VerifyEventNotPublished(); ExceptionVerification.ExpectedWarns(1); diff --git a/NzbDrone.Core/Download/Clients/BlackholeProvider.cs b/NzbDrone.Core/Download/Clients/BlackholeProvider.cs index cfd4e4d87..520e06943 100644 --- a/NzbDrone.Core/Download/Clients/BlackholeProvider.cs +++ b/NzbDrone.Core/Download/Clients/BlackholeProvider.cs @@ -32,35 +32,20 @@ public bool IsInQueue(RemoteEpisode newEpisode) throw new NotImplementedException(); } - public bool DownloadNzb(RemoteEpisode remoteEpisode) + public void DownloadNzb(RemoteEpisode remoteEpisode) { var url = remoteEpisode.Report.NzbUrl; var title = remoteEpisode.Report.Title; - try - { - title = FileNameBuilder.CleanFilename(title); + title = FileNameBuilder.CleanFilename(title); - var filename = Path.Combine(_configService.BlackholeFolder, title + ".nzb"); + var filename = Path.Combine(_configService.BlackholeFolder, title + ".nzb"); - if (_diskProvider.FileExists(filename)) - { - //Return true so a lesser quality is not returned. - _logger.Info("NZB already exists on disk: {0}", filename); - return true; - } - _logger.Trace("Downloading NZB from: {0} to: {1}", url, filename); - _httpProvider.DownloadFile(url, filename); + _logger.Trace("Downloading NZB from: {0} to: {1}", url, filename); + _httpProvider.DownloadFile(url, filename); - _logger.Trace("NZB Download succeeded, saved to: {0}", filename); - return true; - } - catch (Exception ex) - { - _logger.WarnException("Failed to download NZB: " + url, ex); - return false; - } + _logger.Trace("NZB Download succeeded, saved to: {0}", filename); } public bool IsConfigured diff --git a/NzbDrone.Core/Download/Clients/Nzbget/NzbgetClient.cs b/NzbDrone.Core/Download/Clients/Nzbget/NzbgetClient.cs index 566a07f31..5c9f1374e 100644 --- a/NzbDrone.Core/Download/Clients/Nzbget/NzbgetClient.cs +++ b/NzbDrone.Core/Download/Clients/Nzbget/NzbgetClient.cs @@ -22,39 +22,28 @@ public NzbgetClient(IConfigService configService, IHttpProvider httpProvider, Lo _logger = logger; } - public virtual bool DownloadNzb(RemoteEpisode remoteEpisode) + public void DownloadNzb(RemoteEpisode remoteEpisode) { var url = remoteEpisode.Report.NzbUrl; var title = remoteEpisode.Report.Title; - try + string cat = _configService.NzbgetTvCategory; + int priority = remoteEpisode.IsRecentEpisode() ? (int)_configService.NzbgetRecentTvPriority : (int)_configService.NzbgetOlderTvPriority; + + var command = new JsonRequest { - string cat = _configService.NzbgetTvCategory; - int priority = remoteEpisode.IsRecentEpisode() ? (int)_configService.NzbgetRecentTvPriority : (int)_configService.NzbgetOlderTvPriority; + Method = "appendurl", + Params = new object[] { title, cat, priority, false, url } + }; - var command = new JsonRequest - { - Method = "appendurl", - Params = new object[] { title, cat, priority, false, url } - }; + _logger.Info("Adding report [{0}] to the queue.", title); + var response = PostCommand(JsonConvert.SerializeObject(command)); - _logger.Info("Adding report [{0}] to the queue.", title); - var response = PostCommand(JsonConvert.SerializeObject(command)); + CheckForError(response); - CheckForError(response); + var success = JsonConvert.DeserializeObject(response).Result; + _logger.Debug("Queue Response: [{0}]", success); - var success = JsonConvert.DeserializeObject(response).Result; - _logger.Debug("Queue Response: [{0}]", success); - - return true; - } - - catch (WebException ex) - { - _logger.Error("Error communicating with Nzbget: " + ex.Message); - } - - return false; } public bool IsConfigured diff --git a/NzbDrone.Core/Download/Clients/PneumaticClient.cs b/NzbDrone.Core/Download/Clients/PneumaticClient.cs index 2ac8749a6..a7e59b6a4 100644 --- a/NzbDrone.Core/Download/Clients/PneumaticClient.cs +++ b/NzbDrone.Core/Download/Clients/PneumaticClient.cs @@ -25,47 +25,30 @@ public PneumaticClient(IConfigService configService, IHttpProvider httpProvider, _diskProvider = diskProvider; } - public virtual bool DownloadNzb(RemoteEpisode remoteEpisode) + public void DownloadNzb(RemoteEpisode remoteEpisode) { var url = remoteEpisode.Report.NzbUrl; var title = remoteEpisode.Report.Title; - try + if (remoteEpisode.ParsedEpisodeInfo.FullSeason) { - //Todo: Allow full season releases - if (remoteEpisode.ParsedEpisodeInfo.FullSeason) - { - logger.Info("Skipping Full Season Release: {0}", title); - return false; - } - - title = FileNameBuilder.CleanFilename(title); - - //Save to the Pneumatic directory (The user will need to ensure its accessible by XBMC) - var filename = Path.Combine(_configService.PneumaticFolder, title + ".nzb"); - - if (_diskProvider.FileExists(filename)) - { - //Return true so a lesser quality is not returned. - logger.Info("NZB already exists on disk: {0}", filename); - return true; - } - - logger.Trace("Downloading NZB from: {0} to: {1}", url, filename); - _httpProvider.DownloadFile(url, filename); - - logger.Trace("NZB Download succeeded, saved to: {0}", filename); - - var contents = String.Format("plugin://plugin.program.pneumatic/?mode=strm&type=add_file&nzb={0}&nzbname={1}", filename, title); - _diskProvider.WriteAllText(Path.Combine(_configService.DownloadedEpisodesFolder, title + ".strm"), contents); - - return true; - } - catch (Exception ex) - { - logger.WarnException("Failed to download NZB: " + url, ex); - return false; + throw new NotImplementedException("Full season Pneumatic releases are not supported."); } + + title = FileNameBuilder.CleanFilename(title); + + //Save to the Pneumatic directory (The user will need to ensure its accessible by XBMC) + var filename = Path.Combine(_configService.PneumaticFolder, title + ".nzb"); + + + + logger.Trace("Downloading NZB from: {0} to: {1}", url, filename); + _httpProvider.DownloadFile(url, filename); + + logger.Trace("NZB Download succeeded, saved to: {0}", filename); + + var contents = String.Format("plugin://plugin.program.pneumatic/?mode=strm&type=add_file&nzb={0}&nzbname={1}", filename, title); + _diskProvider.WriteAllText(Path.Combine(_configService.DownloadedEpisodesFolder, title + ".strm"), contents); } public bool IsConfigured diff --git a/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdClient.cs b/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdClient.cs index 059d7520c..281096945 100644 --- a/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdClient.cs +++ b/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdClient.cs @@ -62,39 +62,28 @@ public SabnzbdClient(IConfigService configService, IHttpProvider httpProvider, L _logger = logger; } - public virtual bool DownloadNzb(RemoteEpisode remoteEpisode) + public void DownloadNzb(RemoteEpisode remoteEpisode) { var url = remoteEpisode.Report.NzbUrl; var title = remoteEpisode.Report.Title; - try - { - string cat = _configService.SabTvCategory; - int priority = remoteEpisode.IsRecentEpisode() ? (int)_configService.SabRecentTvPriority : (int)_configService.SabOlderTvPriority; + string cat = _configService.SabTvCategory; + int priority = remoteEpisode.IsRecentEpisode() ? (int)_configService.SabRecentTvPriority : (int)_configService.SabOlderTvPriority; - string name = url.Replace("&", "%26"); - string nzbName = HttpUtility.UrlEncode(title); + string name = url.Replace("&", "%26"); + string nzbName = HttpUtility.UrlEncode(title); - string action = string.Format("mode=addurl&name={0}&priority={1}&pp=3&cat={2}&nzbname={3}&output=json", - name, priority, cat, nzbName); + string action = string.Format("mode=addurl&name={0}&priority={1}&pp=3&cat={2}&nzbname={3}&output=json", + name, priority, cat, nzbName); - string request = GetSabRequest(action); - _logger.Info("Adding report [{0}] to the queue.", title); + string request = GetSabRequest(action); + _logger.Info("Adding report [{0}] to the queue.", title); - var response = _httpProvider.DownloadString(request); + var response = _httpProvider.DownloadString(request); - _logger.Debug("Queue Response: [{0}]", response); + _logger.Debug("Queue Response: [{0}]", response); - CheckForError(response); - return true; - } - - catch (WebException ex) - { - _logger.Error("Error communicating with SAB: " + ex.Message); - } - - return false; + CheckForError(response); } public bool IsConfigured diff --git a/NzbDrone.Core/Download/DownloadService.cs b/NzbDrone.Core/Download/DownloadService.cs index 9637d4417..583fdfa1f 100644 --- a/NzbDrone.Core/Download/DownloadService.cs +++ b/NzbDrone.Core/Download/DownloadService.cs @@ -6,7 +6,7 @@ namespace NzbDrone.Core.Download { public interface IDownloadService { - bool DownloadReport(RemoteEpisode remoteEpisode); + void DownloadReport(RemoteEpisode remoteEpisode); } public class DownloadService : IDownloadService @@ -24,7 +24,7 @@ public DownloadService(IProvideDownloadClient downloadClientProvider, _logger = logger; } - public bool DownloadReport(RemoteEpisode remoteEpisode) + public void DownloadReport(RemoteEpisode remoteEpisode) { var downloadTitle = remoteEpisode.Report.Title; var downloadClient = _downloadClientProvider.GetDownloadClient(); @@ -32,18 +32,13 @@ public bool DownloadReport(RemoteEpisode remoteEpisode) if (!downloadClient.IsConfigured) { _logger.Warn("Download client {0} isn't configured yet.", downloadClient.GetType().Name); - return false; + return; } - bool success = downloadClient.DownloadNzb(remoteEpisode); + downloadClient.DownloadNzb(remoteEpisode); - if (success) - { - _logger.Info("Report sent to download client. {0}", downloadTitle); - _messageAggregator.PublishEvent(new EpisodeGrabbedEvent(remoteEpisode)); - } - - return success; + _logger.Info("Report sent to download client. {0}", downloadTitle); + _messageAggregator.PublishEvent(new EpisodeGrabbedEvent(remoteEpisode)); } } } \ No newline at end of file diff --git a/NzbDrone.Core/Download/IDownloadClient.cs b/NzbDrone.Core/Download/IDownloadClient.cs index 6d3653c7e..aca724d1b 100644 --- a/NzbDrone.Core/Download/IDownloadClient.cs +++ b/NzbDrone.Core/Download/IDownloadClient.cs @@ -5,7 +5,7 @@ namespace NzbDrone.Core.Download { public interface IDownloadClient { - bool DownloadNzb(RemoteEpisode remoteEpisode); + void DownloadNzb(RemoteEpisode remoteEpisode); bool IsConfigured { get; } IEnumerable GetQueue(); }