2013-04-01 09:22:16 +03:00
using System ;
2013-01-24 09:36:37 +03:00
using FluentAssertions ;
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.Nzbget ;
2013-03-28 22:05:43 +03:00
using NzbDrone.Core.Test.Framework ;
2013-01-24 09:36:37 +03:00
2013-04-01 09:22:16 +03:00
namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetProviderTests
2013-01-24 09:36:37 +03:00
{
2013-03-28 22:05:43 +03:00
public class DownloadNzbFixture : CoreTest
2013-01-24 09:36:37 +03:00
{
[SetUp]
public void Setup ( )
{
2013-02-24 22:39:31 +03:00
var fakeConfig = Mocker . GetMock < IConfigService > ( ) ;
2013-01-24 09:36:37 +03:00
fakeConfig . SetupGet ( c = > c . NzbgetHost ) . Returns ( "192.168.5.55" ) ;
fakeConfig . SetupGet ( c = > c . NzbgetPort ) . Returns ( 6789 ) ;
fakeConfig . SetupGet ( c = > c . NzbgetUsername ) . Returns ( "nzbget" ) ;
fakeConfig . SetupGet ( c = > c . NzbgetPassword ) . Returns ( "pass" ) ;
fakeConfig . SetupGet ( c = > c . NzbgetTvCategory ) . Returns ( "TV" ) ;
fakeConfig . SetupGet ( c = > c . NzbgetBacklogTvPriority ) . Returns ( PriorityType . Normal ) ;
fakeConfig . SetupGet ( c = > c . NzbgetRecentTvPriority ) . Returns ( PriorityType . High ) ;
}
2013-03-28 22:05:43 +03:00
2013-01-24 09:36:37 +03:00
private void WithFailResponse ( )
{
2013-04-11 02:41:45 +03:00
Mocker . GetMock < IHttpProvider > ( )
2013-01-24 10:38:16 +03:00
. Setup ( s = > s . PostCommand ( "192.168.5.55:6789" , "nzbget" , "pass" , It . IsAny < String > ( ) ) )
2013-03-28 22:05:43 +03:00
. Returns ( ReadAllText ( "Files" , "Nzbget" , "JsonError.txt" ) ) ;
2013-01-24 09:36:37 +03:00
}
[Test]
public void should_add_item_to_queue ( )
{
const string url = "http://www.nzbdrone.com" ;
const string title = "30 Rock - S01E01 - Pilot [HDTV-720p]" ;
2013-04-11 02:41:45 +03:00
Mocker . GetMock < IHttpProvider > ( )
2013-01-24 10:38:16 +03:00
. Setup ( s = > s . PostCommand ( "192.168.5.55:6789" , "nzbget" , "pass" ,
2013-01-24 09:36:37 +03:00
It . Is < String > ( c = > c . Equals ( "{\"method\":\"appendurl\",\"params\":[\"30 Rock - S01E01 - Pilot [HDTV-720p]\",\"TV\",0,false,\"http://www.nzbdrone.com\"]}" ) ) ) )
. Returns ( "{\"version\": \"1.1\",\"result\": true}" ) ;
2013-04-15 04:41:39 +03:00
Mocker . Resolve < NzbgetClient > ( )
2013-01-24 09:36:37 +03:00
. DownloadNzb ( url , title , false )
. Should ( )
. BeTrue ( ) ;
}
[Test]
public void should_throw_when_error_is_returned ( )
{
WithFailResponse ( ) ;
2013-04-15 04:41:39 +03:00
Assert . Throws < ApplicationException > ( ( ) = > Mocker . Resolve < NzbgetClient > ( ) . DownloadNzb ( "http://www.nzbdrone.com" , "30 Rock - S01E01 - Pilot [HDTV-720p]" , false ) ) ;
2013-01-24 09:36:37 +03:00
}
}
}