Notifications can be tested

Notification ImplementationType was added for showing in UI (Humanized/Title cased of Implementation)
This commit is contained in:
Mark McDowall 2013-06-12 23:41:26 -07:00
commit 8cac7ed1cd
34 changed files with 418 additions and 328 deletions

View file

@ -42,8 +42,7 @@ namespace NzbDrone.Core.Test.NotificationTests
Mocker.GetMock<IHttpProvider>().Setup(s => s.DownloadStream("http://localhost:32400/library/sections", null))
.Returns(stream);
var result = Mocker.Resolve<PlexProvider>().GetSectionKeys("localhost:32400");
var result = Mocker.Resolve<PlexService>().GetSectionKeys(new PlexServerSettings { Host = "localhost", Port = 32400 });
result.Should().HaveCount(1);
@ -62,7 +61,7 @@ namespace NzbDrone.Core.Test.NotificationTests
.Returns(stream);
var result = Mocker.Resolve<PlexProvider>().GetSectionKeys("localhost:32400");
var result = Mocker.Resolve<PlexService>().GetSectionKeys(new PlexServerSettings { Host = "localhost", Port = 32400 });
result.Should().HaveCount(1);
@ -80,8 +79,8 @@ namespace NzbDrone.Core.Test.NotificationTests
Mocker.GetMock<IHttpProvider>().Setup(s => s.DownloadStream("http://localhost:32400/library/sections", null))
.Returns(stream);
var result = Mocker.Resolve<PlexProvider>().GetSectionKeys("localhost:32400");
var result = Mocker.Resolve<PlexService>().GetSectionKeys(new PlexServerSettings { Host = "localhost", Port = 32400 });
result.Should().HaveCount(2);
@ -100,8 +99,8 @@ namespace NzbDrone.Core.Test.NotificationTests
Mocker.GetMock<IHttpProvider>().Setup(s => s.DownloadString("http://localhost:32400/library/sections/5/refresh"))
.Returns(response);
Mocker.Resolve<PlexProvider>().UpdateSection("localhost:32400", 5);
Mocker.Resolve<PlexService>().UpdateSection(new PlexServerSettings { Host = "localhost", Port = 32400 }, 5);
@ -121,7 +120,7 @@ namespace NzbDrone.Core.Test.NotificationTests
.Returns("ok");
Mocker.Resolve<PlexProvider>().Notify(_clientSettings, header, message);
Mocker.Resolve<PlexService>().Notify(_clientSettings, header, message);
fakeHttp.Verify(v => v.DownloadString(expectedUrl), Times.Once());
@ -142,7 +141,7 @@ namespace NzbDrone.Core.Test.NotificationTests
.Returns("ok");
Mocker.Resolve<PlexProvider>().Notify(_clientSettings, header, message);
Mocker.Resolve<PlexService>().Notify(_clientSettings, header, message);
fakeHttp.Verify(v => v.DownloadString(expectedUrl, "plex", "plex"), Times.Once());

View file

@ -9,130 +9,40 @@ namespace NzbDrone.Core.Test.NotificationTests
{
[Explicit]
[TestFixture]
public class ProwlProviderTest : CoreTest
public class ProwlProviderTest : CoreTest<ProwlService>
{
private const string _apiKey = "c3bdc0f48168f72d546cc6872925b160f5cbffc1";
private const string _apiKey2 = "46a710a46b111b0b8633819b0d8a1e0272a3affa";
private const string _apiKey = "66e9f688b512152eb2688f0486ae542c76e564a2";
private const string _badApiKey = "1234567890abcdefghijklmnopqrstuvwxyz1234";
[Test]
public void Verify_should_return_true_for_a_valid_apiKey()
public void Verify_should_not_throw_for_a_valid_apiKey()
{
var result = Mocker.Resolve<ProwlProvider>().Verify(_apiKey);
result.Should().BeTrue();
Subject.Verify(_apiKey);
ExceptionVerification.ExpectedWarns(0);
}
[Test]
public void Verify_should_return_false_for_an_invalid_apiKey()
public void Verify_should_throw_for_an_invalid_apiKey()
{
var result = Mocker.Resolve<ProwlProvider>().Verify(_badApiKey);
Assert.Throws<InvalidApiKeyException>(() => Subject.Verify(_badApiKey));
ExceptionVerification.ExpectedWarns(1);
result.Should().BeFalse();
}
[Test]
public void SendNotification_should_return_true_for_a_valid_apiKey()
public void SendNotification_should_not_throw_for_a_valid_apiKey()
{
var result = Mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone", _apiKey);
result.Should().BeTrue();
Subject.SendNotification("NzbDrone Test", "This is a test message from NzbDrone", _apiKey);
ExceptionVerification.ExpectedWarns(0);
}
[Test]
public void SendNotification_should_return_false_for_an_invalid_apiKey()
public void SendNotification_should_log_a_warning_for_an_invalid_apiKey()
{
Subject.SendNotification("NzbDrone Test", "This is a test message from NzbDrone", _badApiKey);
var result = Mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone", _badApiKey);
ExceptionVerification.ExpectedWarns(1);
result.Should().BeFalse();
}
[Test]
public void SendNotification_should_alert_with_high_priority()
{
var result = Mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone (High)", _apiKey, NotificationPriority.High);
result.Should().BeTrue();
}
[Test]
public void SendNotification_should_alert_with_VeryLow_priority()
{
var result = Mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone (VeryLow)", _apiKey, NotificationPriority.VeryLow);
result.Should().BeTrue();
}
[Test]
public void SendNotification_should_have_a_call_back_url()
{
var result = Mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone", _apiKey, NotificationPriority.Normal, "http://www.nzbdrone.com");
result.Should().BeTrue();
}
[Test]
public void SendNotification_should_return_true_for_two_valid_apiKey()
{
var result = Mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone", _apiKey + ", " + _apiKey2);
result.Should().BeTrue();
}
[Test]
public void SendNotification_should_return_true_for_valid_apiKey_with_bad_apiKey()
{
var result = Mocker.Resolve<ProwlProvider>().SendNotification("NzbDrone Test", "This is a test message from NzbDrone", _apiKey + ", " + _badApiKey);
result.Should().BeTrue();
}
}
}