-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from merodriguezblanco/hipchat-integration
Hipchat integration
- Loading branch information
Showing
19 changed files
with
319 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 0 additions & 28 deletions
28
ExceptionNotification.Core.Tests/Email/EmailExceptionNotifierTests.cs
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
ExceptionNotification.Core.Tests/Email/EmailNotifierTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using ExceptionNotification.Core.Email; | ||
using ExceptionNotification.Core.Exceptions.Email; | ||
using Xunit; | ||
|
||
namespace ExceptionNotification.Core.Tests.Email | ||
{ | ||
public class EmailNotifierTests | ||
{ | ||
[Fact] | ||
public void FireExceptionThrowsExceptionWhenConfigurationIsNull() | ||
{ | ||
var notifier = new EmailNotifier(null); | ||
|
||
var exception = Assert.Throws<ConfigurationMissingException>(() => notifier.FireNotification(new Exception(), null)); | ||
Assert.Equal("FireNotification failure: configuration is null.", exception.Message); | ||
} | ||
|
||
[Fact] | ||
public void FireExceptionThrowsExceptionWhenExceptionIsNull() | ||
{ | ||
var notifier = new EmailNotifier(new EmailConfiguration()); | ||
|
||
var exception = Assert.Throws<ExceptionMissingException>(() => notifier.FireNotification(null, null)); | ||
Assert.Equal("FireNotification failure: exception is null.", exception.Message); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
ExceptionNotification.Core.Tests/Hipchat/HipchatNotifierTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using ExceptionNotification.Core.Exceptions.Email; | ||
using ExceptionNotification.Core.Hipchat; | ||
using Xunit; | ||
|
||
namespace ExceptionNotification.Core.Tests.Hipchat | ||
{ | ||
public class HipchatNotifierTests | ||
{ | ||
[Fact] | ||
public void FireExceptionThrowsExceptionWhenConfigurationIsNull() | ||
{ | ||
var notifier = new HipchatNotifier(null); | ||
|
||
var exception = Assert.Throws<ConfigurationMissingException>(() => notifier.FireNotification(new Exception(), null)); | ||
Assert.Equal("FireNotification failure: configuration is null.", exception.Message); | ||
} | ||
|
||
[Fact] | ||
public void FireExceptionThrowsExceptionWhenExceptionIsNull() | ||
{ | ||
var notifier = new HipchatNotifier(new HipchatConfiguration()); | ||
|
||
var exception = Assert.Throws<ExceptionMissingException>(() => notifier.FireNotification(null, null)); | ||
Assert.Equal("FireNotification failure: exception is null.", exception.Message); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Reflection; | ||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace ExceptionNotification.Core | ||
{ | ||
public class BaseNotifier | ||
{ | ||
protected NotifierOptions NotifierOptions; | ||
|
||
public BaseNotifier() | ||
{ | ||
NotifierOptions = new NotifierOptions | ||
{ | ||
ProjectName = Assembly.GetEntryAssembly().GetName().Name, | ||
Environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") | ||
}; | ||
} | ||
|
||
public virtual void FireNotification(Exception exception) | ||
{} | ||
|
||
public virtual void FireNotification(Exception exception, HttpRequest request) | ||
{} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 0 additions & 57 deletions
57
ExceptionNotification.Core/Email/EmailExceptionNotifier.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using System.Net; | ||
using System.Net.Mail; | ||
using ExceptionNotification.Core.Exceptions.Email; | ||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace ExceptionNotification.Core.Email | ||
{ | ||
public class EmailNotifier : BaseNotifier | ||
{ | ||
private readonly EmailConfiguration _configuration; | ||
|
||
public EmailNotifier(EmailConfiguration configuration) | ||
{ | ||
_configuration = configuration; | ||
} | ||
|
||
public override void FireNotification(Exception exception) | ||
{ | ||
FireNotification(exception, null); | ||
} | ||
|
||
public override void FireNotification(Exception exception, HttpRequest request) | ||
{ | ||
if (_configuration == null) | ||
{ | ||
throw new ConfigurationMissingException("FireNotification failure: configuration is null."); | ||
} | ||
|
||
if (exception == null) | ||
{ | ||
throw new ExceptionMissingException("FireNotification failure: exception is null."); | ||
} | ||
|
||
var message = EmailBuilder.ComposeEmail(exception, _configuration, NotifierOptions, request); | ||
|
||
try | ||
{ | ||
using (var client = new SmtpClient(_configuration.SmtpServer, _configuration.SmtpPort)) | ||
{ | ||
client.UseDefaultCredentials = false; | ||
|
||
if (_configuration.UseCredentials) | ||
{ | ||
client.Credentials = | ||
new NetworkCredential(_configuration.SmtpUser, _configuration.SmtpPassword); | ||
} | ||
|
||
client.EnableSsl = _configuration.EnableSsl; | ||
client.Send(message); | ||
} | ||
} | ||
catch (Exception) | ||
{ | ||
// | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.