-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: sanity-check email address and address lists when adding to a m…
…essage (#981) Fixes #980 When sending an email and providing an empty list of BCCs the request fails with BadRequest as outlined here: https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#message.personalizations.bcc We want to inform the consumer that this is the case otherwise it may lead to email sending silently failing.
- Loading branch information
1 parent
8ea9556
commit b9e1e98
Showing
2 changed files
with
90 additions
and
0 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
52 changes: 52 additions & 0 deletions
52
tests/SendGrid.Tests/PreSendEmailValidation/WhenCreatingASendGridMessage.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,52 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using SendGrid.Helpers.Mail; | ||
using Xunit; | ||
|
||
namespace SendGrid.Tests.PreSendEmailValidation | ||
{ | ||
public class WhenCreatingASendGridMessage | ||
{ | ||
[Fact] | ||
public void WithAnEmptyListOfBlindCarbonCopiesThenAnExceptionIsThrown() | ||
{ | ||
var sendGridMessage = MailHelper.CreateSingleEmail(new EmailAddress(), new EmailAddress(), string.Empty, string.Empty, string.Empty); | ||
Assert.Throws<InvalidOperationException>(() => { sendGridMessage.AddBccs(new List<EmailAddress>()); }); | ||
} | ||
|
||
[Fact] | ||
public void WithANullListOfBlindCarbonCopiesThenAnExceptionIsThrown() | ||
{ | ||
var sendGridMessage = MailHelper.CreateSingleEmail(new EmailAddress(), new EmailAddress(), string.Empty, string.Empty, string.Empty); | ||
Assert.Throws<ArgumentNullException>(() => { sendGridMessage.AddBccs(null); }); | ||
} | ||
|
||
[Fact] | ||
public void WithANullBlindCarbonCopyThenAnExceptionIsThrown() | ||
{ | ||
var sendGridMessage = MailHelper.CreateSingleEmail(new EmailAddress(), new EmailAddress(), string.Empty, string.Empty, string.Empty); | ||
Assert.Throws<ArgumentNullException>(() => { sendGridMessage.AddBcc(null, 0); }); | ||
} | ||
|
||
[Fact] | ||
public void WithAnEmptyListOfCarbonCopiesThenAnExceptionIsThrown() | ||
{ | ||
var sendGridMessage = MailHelper.CreateSingleEmail(new EmailAddress(), new EmailAddress(), string.Empty, string.Empty, string.Empty); | ||
Assert.Throws<InvalidOperationException>(() => { sendGridMessage.AddCcs(new List<EmailAddress>()); }); | ||
} | ||
|
||
[Fact] | ||
public void WithANullListOfCarbonCopiesThenAnExceptionIsThrown() | ||
{ | ||
var sendGridMessage = MailHelper.CreateSingleEmail(new EmailAddress(), new EmailAddress(), string.Empty, string.Empty, string.Empty); | ||
Assert.Throws<InvalidOperationException>(() => { sendGridMessage.AddCcs(new List<EmailAddress>()); }); | ||
} | ||
|
||
[Fact] | ||
public void WithANullCarbonCopyThenAnExceptionIsThrown() | ||
{ | ||
var sendGridMessage = MailHelper.CreateSingleEmail(new EmailAddress(), new EmailAddress(), string.Empty, string.Empty, string.Empty); | ||
Assert.Throws<ArgumentNullException>(() => { sendGridMessage.AddCc(null, 0); }); | ||
} | ||
} | ||
} |