2011-11-03 05:44:22 +03:00
using System ;
2011-11-14 03:22:18 +03:00
2011-11-03 05:44:22 +03:00
using FizzWare.NBuilder ;
using FluentAssertions ;
using Moq ;
using NUnit.Framework ;
using NzbDrone.Core.Model ;
using NzbDrone.Core.Providers ;
using NzbDrone.Core.Repository ;
using NzbDrone.Core.Test.Framework ;
using NzbDrone.Test.Common ;
2011-11-14 03:22:18 +03:00
using NzbDrone.Test.Common.AutoMoq ;
2011-11-03 05:44:22 +03:00
using Prowlin ;
// ReSharper disable InconsistentNaming
namespace NzbDrone.Core.Test.ProviderTests
{
[Explicit]
[TestFixture]
2013-02-17 08:44:06 +03:00
public class ProwlProviderTest : CoreTest
2011-11-03 05:44:22 +03:00
{
private const string _apiKey = "c3bdc0f48168f72d546cc6872925b160f5cbffc1" ;
private const string _apiKey2 = "46a710a46b111b0b8633819b0d8a1e0272a3affa" ;
private const string _badApiKey = "1234567890abcdefghijklmnopqrstuvwxyz1234" ;
[Test]
public void Verify_should_return_true_for_a_valid_apiKey ( )
{
//Setup
2011-12-15 07:15:53 +03:00
WithStrictMocker ( ) ;
2011-11-03 05:44:22 +03:00
//Act
2011-12-15 07:15:53 +03:00
var result = Mocker . Resolve < ProwlProvider > ( ) . Verify ( _apiKey ) ;
2011-11-03 05:44:22 +03:00
//Assert
result . Should ( ) . BeTrue ( ) ;
}
[Test]
public void Verify_should_return_false_for_an_invalid_apiKey ( )
{
//Setup
2011-12-15 07:15:53 +03:00
WithStrictMocker ( ) ;
2011-11-03 05:44:22 +03:00
//Act
2011-12-15 07:15:53 +03:00
var result = Mocker . Resolve < ProwlProvider > ( ) . Verify ( _badApiKey ) ;
2011-11-03 05:44:22 +03:00
//Assert
2011-12-20 03:58:26 +03:00
ExceptionVerification . ExpectedWarns ( 1 ) ;
2011-11-03 05:44:22 +03:00
result . Should ( ) . BeFalse ( ) ;
}
[Test]
public void SendNotification_should_return_true_for_a_valid_apiKey ( )
{
//Setup
2011-12-15 07:15:53 +03:00
WithStrictMocker ( ) ;
2011-11-03 05:44:22 +03:00
//Act
2011-12-15 07:15:53 +03:00
var result = Mocker . Resolve < ProwlProvider > ( ) . SendNotification ( "NzbDrone Test" , "This is a test message from NzbDrone" , _apiKey ) ;
2011-11-03 05:44:22 +03:00
//Assert
result . Should ( ) . BeTrue ( ) ;
}
[Test]
public void SendNotification_should_return_false_for_an_invalid_apiKey ( )
{
//Setup
2011-12-15 07:15:53 +03:00
WithStrictMocker ( ) ;
2011-11-03 05:44:22 +03:00
//Act
2011-12-15 07:15:53 +03:00
var result = Mocker . Resolve < ProwlProvider > ( ) . SendNotification ( "NzbDrone Test" , "This is a test message from NzbDrone" , _badApiKey ) ;
2011-11-03 05:44:22 +03:00
//Assert
2011-12-20 03:58:26 +03:00
ExceptionVerification . ExpectedWarns ( 1 ) ;
2011-11-03 05:44:22 +03:00
result . Should ( ) . BeFalse ( ) ;
}
[Test]
public void SendNotification_should_alert_with_high_priority ( )
{
//Setup
2011-12-15 07:15:53 +03:00
WithStrictMocker ( ) ;
2011-11-03 05:44:22 +03:00
//Act
2011-12-15 07:15:53 +03:00
var result = Mocker . Resolve < ProwlProvider > ( ) . SendNotification ( "NzbDrone Test" , "This is a test message from NzbDrone (High)" , _apiKey , NotificationPriority . High ) ;
2011-11-03 05:44:22 +03:00
//Assert
result . Should ( ) . BeTrue ( ) ;
}
[Test]
public void SendNotification_should_alert_with_VeryLow_priority ( )
{
//Setup
2011-12-15 07:15:53 +03:00
WithStrictMocker ( ) ;
2011-11-03 05:44:22 +03:00
//Act
2011-12-15 07:15:53 +03:00
var result = Mocker . Resolve < ProwlProvider > ( ) . SendNotification ( "NzbDrone Test" , "This is a test message from NzbDrone (VeryLow)" , _apiKey , NotificationPriority . VeryLow ) ;
2011-11-03 05:44:22 +03:00
//Assert
result . Should ( ) . BeTrue ( ) ;
}
[Test]
public void SendNotification_should_have_a_call_back_url ( )
{
//Setup
2011-12-15 07:15:53 +03:00
WithStrictMocker ( ) ;
2011-11-03 05:44:22 +03:00
//Act
2011-12-15 07:15:53 +03:00
var result = Mocker . Resolve < ProwlProvider > ( ) . SendNotification ( "NzbDrone Test" , "This is a test message from NzbDrone" , _apiKey , NotificationPriority . Normal , "http://www.nzbdrone.com" ) ;
2011-11-03 05:44:22 +03:00
//Assert
result . Should ( ) . BeTrue ( ) ;
}
[Test]
public void SendNotification_should_return_true_for_two_valid_apiKey ( )
{
//Setup
2011-12-15 07:15:53 +03:00
WithStrictMocker ( ) ;
2011-11-03 05:44:22 +03:00
//Act
2011-12-15 07:15:53 +03:00
var result = Mocker . Resolve < ProwlProvider > ( ) . SendNotification ( "NzbDrone Test" , "This is a test message from NzbDrone" , _apiKey + ", " + _apiKey2 ) ;
2011-11-03 05:44:22 +03:00
//Assert
result . Should ( ) . BeTrue ( ) ;
}
[Test]
public void SendNotification_should_return_true_for_valid_apiKey_with_bad_apiKey ( )
{
//Setup
2011-12-15 07:15:53 +03:00
WithStrictMocker ( ) ;
2011-11-03 05:44:22 +03:00
//Act
2011-12-15 07:15:53 +03:00
var result = Mocker . Resolve < ProwlProvider > ( ) . SendNotification ( "NzbDrone Test" , "This is a test message from NzbDrone" , _apiKey + ", " + _badApiKey ) ;
2011-11-03 05:44:22 +03:00
//Assert
result . Should ( ) . BeTrue ( ) ;
}
}
}