public void Test_WithFrom2_ShouldAdNewVariable() { var instance = new MailerSendEmailParameters(); instance.WithTo("*****@*****.**"); instance.WithTo("*****@*****.**"); instance.WithVariable("*****@*****.**", new MailerSendEmailVariableSubstitution[] { new MailerSendEmailVariableSubstitution { Var = "v1", Value = "1", }, }); instance.WithVariable("*****@*****.**", new MailerSendEmailVariableSubstitution[] { new MailerSendEmailVariableSubstitution { Var = "v2", Value = "2", }, }); instance.Variables.Should().NotBeEmpty(); instance.Variables.Should().HaveCount(2); }
public void Test_WithFrom1_ShouldReplaceVariableCollection() { var instance = new MailerSendEmailParameters(); instance.WithTo("*****@*****.**"); instance.WithVariable( new MailerSendEmailVariable("*****@*****.**", new MailerSendEmailVariableSubstitution[] { new MailerSendEmailVariableSubstitution { Var = "v1", Value = "1", }, })); instance.WithVariable( new MailerSendEmailVariable("*****@*****.**", new MailerSendEmailVariableSubstitution[] { new MailerSendEmailVariableSubstitution { Var = "v2", Value = "2", }, })); instance.Variables.Should().NotBeEmpty(); instance.Variables.Should().HaveCount(1); }
public void Test_WithTemplateId_ShouldSetTemplateid() { var instance = new MailerSendEmailParameters(); instance.WithTemplateId("1000"); instance.TemplateId.Should().Be("1000"); }
public async Task Test_SendMail_When_UnprocessableEntity_Then_ReturnMailerSendEmailResponseWithValidationErrorMessage() { var apiToken = "my token"; var handler = new MockHttpMessageHandler(HttpStatusCode.UnprocessableEntity, responseContent: new { message = "The given data was invalid.", errors = new { fromemail = new string[] { "The from.email must be verified.", }, }, }); IMailerSendEmailClient client = new MailerSendEmailClient(new MockHttpClient(handler), apiToken); var parameters = new MailerSendEmailParameters(); parameters .WithFrom("invalidemail", "Sender") .WithTo("*****@*****.**") .WithSubject("Hi!") .WithHtmlBody("this is a test"); var response = await client.SendEmailAsync(parameters).ConfigureAwait(false); response.Should().NotBeNull(); response.Message.Should().Be("The given data was invalid."); response.Errors.Should().NotBeEmpty(); response.Errors.Should().ContainKey("fromemail"); response.Errors["fromemail"].Should().Contain("The from.email must be verified."); }
public async Task Test_SendMail_When_Accepted_Then_ReturnMailerSendEmailResponseWithMessageId() { IDictionary <string, string[]> headers = new Dictionary <string, string[]>(StringComparer.OrdinalIgnoreCase) { { "X-Message-Id", new string[] { "messageid" } } }; var apiToken = "my token"; var handler = new MockHttpMessageHandler(HttpStatusCode.Accepted, responseContent: null, responseHeaders: headers); IMailerSendEmailClient client = new MailerSendEmailClient(new MockHttpClient(handler), apiToken); var parameters = new MailerSendEmailParameters(); parameters .WithFrom("*****@*****.**", "Sender") .WithTo("*****@*****.**") .WithSubject("Hi!") .WithHtmlBody("this is a test"); var response = await client.SendEmailAsync(parameters).ConfigureAwait(false); response.Should().NotBeNull(); response.MessageId.Should().Be("messageid"); response.Message.Should().BeNullOrEmpty(); }
public void Test_WithHtmlBody_ShouldSetHtml() { var instance = new MailerSendEmailParameters(); instance.WithHtmlBody("<p>email body<p>"); instance.Html.Should().NotBeNullOrWhiteSpace(); instance.Html.Should().Be("<p>email body<p>"); }
public void Test_WithHtmlBody_ShouldSetTextToPlainText() { var instance = new MailerSendEmailParameters(); instance.WithHtmlBody("<p>email body<p>"); instance.Text.Should().NotBeNullOrWhiteSpace(); instance.Text.Should().Be("\nemail body\n"); }
public void Test_WithSubject_ShouldSetSubject() { var instance = new MailerSendEmailParameters(); instance.WithSubject("hi!"); instance.Subject.Should().NotBeNullOrWhiteSpace(); instance.Subject.Should().Be("hi!"); }
public void Test_WithPersonalization2_ShouldRequireEmailInRecipientCollection() { var instance = new MailerSendEmailParameters(); Action action = () => instance.WithPersonalization("*****@*****.**", new { p1 = "1" }); action.Should() .Throw <InvalidOperationException>() .WithMessage("The email must be in the list of recipients (to)"); }
public void Test_WithFrom2_ShouldSetFromObject() { var instance = new MailerSendEmailParameters(); instance.WithFrom("*****@*****.**", "Test"); instance.From.Should().NotBeNull(); instance.From.Email.Should().Be("*****@*****.**"); instance.From.Name.Should().Be("Test"); }
public void Test_WithTags_ShouldReplaceTagsCollection() { var instance = new MailerSendEmailParameters(); instance.Tags.Add("first tag"); instance.WithTags("tag1", "tag2", "tag3"); instance.Tags.Should().NotBeNullOrEmpty(); instance.Tags.Should().HaveCount(3); instance.Tags.Should().BeEquivalentTo(new string[] { "tag1", "tag2", "tag3" }); }
public void Test_Constructor_ShouldInitializeCollections() { var instance = new MailerSendEmailParameters(); instance.To.Should().NotBeNull(); instance.ReplyTo.Should().NotBeNull(); instance.Variables.Should().NotBeNull(); instance.Attachments.Should().NotBeNull(); instance.Personalizations.Should().NotBeNull(); instance.Tags.Should().NotBeNull(); }
public void Test_WithTo1_ShouldRecplaceToCollection() { var instance = new MailerSendEmailParameters(); instance.WithTo(new MailerSendEmailRecipient("*****@*****.**", "Test")); instance.To.Should().NotBeEmpty(); instance.To.Should().HaveCount(1); var item = instance.To.First(); item.Email.Should().Be("*****@*****.**"); item.Name.Should().Be("Test"); }
public void Test_WithTo2_ShouldAddNewRecipient() { var instance = new MailerSendEmailParameters(); instance.WithTo(new MailerSendEmailRecipient("*****@*****.**", "Test")); instance.WithTo("*****@*****.**"); instance.To.Should().NotBeEmpty(); instance.To.Should().HaveCount(2); var item = instance.To.Last(); item.Email.Should().Be("*****@*****.**"); item.Name.Should().Be(""); }
public void Test_WithAttachment1_ShouldReplaceAttachmentCollection() { var instance = new MailerSendEmailParameters(); instance.WithAttachment(new MailerSendEmailAttachment("1", "file.pdf", "<base64content>")); instance.Attachments.Should().NotBeEmpty(); instance.Attachments.Should().HaveCount(1); var attachment = instance.Attachments.First(); attachment.Id.Should().Be("1"); attachment.FileName.Should().Be("file.pdf"); attachment.Content.Should().Be("<base64content>"); }
public void Test_WithPersonalization1_ShouldReplacePersonalizationCollection() { var instance = new MailerSendEmailParameters(); instance.WithTo("*****@*****.**"); instance.WithPersonalization(new MailerSendEmailPersonalization("*****@*****.**", new { p1 = "1" })); instance.Personalizations.Should().NotBeEmpty(); instance.Personalizations.Should().HaveCount(1); var item = instance.Personalizations.First(); item.Email.Should().Be("*****@*****.**"); item.Data.Should().NotBeNull(); item.Data.Should().Be(new { p1 = "1" }); }
public void Test_WithAttachment2_ShouldAddNewAttachment() { var instance = new MailerSendEmailParameters(); instance.WithAttachment(new MailerSendEmailAttachment("1", "file.pdf", "<base64content>")); instance.WithAttachment("2", "file2.pdf", "<base64content>"); instance.Attachments.Should().NotBeEmpty(); instance.Attachments.Should().HaveCount(2); var attachment = instance.Attachments.Last(); attachment.Id.Should().Be("2"); attachment.FileName.Should().Be("file2.pdf"); attachment.Content.Should().Be("<base64content>"); }
public void Test_WithFrom2_ShouldRequireEmailInRecipientCollection() { var instance = new MailerSendEmailParameters(); Action action = () => instance.WithVariable("*****@*****.**", new MailerSendEmailVariableSubstitution[] { new MailerSendEmailVariableSubstitution { Var = "v1", Value = "1", }, }); action.Should() .Throw <InvalidOperationException>() .WithMessage("The email must be in the list of recipients (to)"); }
public void Test_SendMail_When_UnprocessableEntityAndUnknownBody_Then_ThrowApiException() { var apiToken = "my token"; var handler = new MockHttpMessageHandler(HttpStatusCode.UnprocessableEntity, responseContent: null); IMailerSendEmailClient client = new MailerSendEmailClient(new MockHttpClient(handler), apiToken); var parameters = new MailerSendEmailParameters(); parameters .WithTo("*****@*****.**") .WithSubject("Hi!") .WithHtmlBody("this is a test"); Func <Task> action = async() => { await client.SendEmailAsync(parameters).ConfigureAwait(false); }; action.Should() .Throw <ApiException>() .WithMessage("Unexpected response.\n\nStatus: 422\nResponse: \n"); }
public void Test_SendMail_When_ServerError_Then_ThrowApiException() { var apiToken = "my token"; var handler = new MockHttpMessageHandler(HttpStatusCode.InternalServerError); IMailerSendEmailClient client = new MailerSendEmailClient(new MockHttpClient(handler), apiToken); var parameters = new MailerSendEmailParameters(); parameters .WithFrom("*****@*****.**", "Sender") .WithTo("*****@*****.**") .WithSubject("Hi!") .WithHtmlBody("this is a test"); Func <Task> action = async() => { await client.SendEmailAsync(parameters).ConfigureAwait(false); }; action.Should() .Throw <ApiException>() .WithMessage("Unexpected response HTTP status code (500).\n\nStatus: 500\nResponse: \n"); }