public void Exception_throw_when_alternative_view_is_missing_Content_Type_header() { var input = @" To: [email protected] From: [email protected] Subject: Test Subject Views: Text, Html"; var text = @"incorrect: header Hello, World!"; var html = @"incorrect: header <p>Hello, World!</p>"; var email = new Email("Test"); var renderer = new Mock <IEmailViewRenderer>(); renderer.Setup(r => r.Render(email, "Test.Text")).Returns(text); renderer.Setup(r => r.Render(email, "Test.Html")).Returns(html); var parser = new EmailParser(renderer.Object); Assert.Throws <Exception>(delegate { parser.Parse(input, email); }); }
public async Task ContentType_determined_by_view_name_when_alternative_view_is_missing_Content_Type_header() { var input = @" To: [email protected] From: [email protected] Subject: Test Subject Views: Text, Html"; var text = @" Hello, World!"; var html = @" <p>Hello, World!</p>"; var email = new Email("Test"); var renderer = new Mock <IEmailViewRender>(); renderer.Setup(r => r.RenderAsync(email, "Test.Text")).Returns(Task.FromResult(text)); renderer.Setup(r => r.RenderAsync(email, "Test.Html")).Returns(Task.FromResult(html)); var parser = new EmailParser(renderer.Object); var message = await parser.ParseAsync(input, email); message.TextBody.ShouldBe("text/plain"); message.HtmlBody.MediaType.ShouldBe("text/html"); renderer.Verify(); }
public void ContentType_determined_by_view_name_when_alternative_view_is_missing_Content_Type_header() { var input = @" To: [email protected] From: [email protected] Subject: Test Subject Views: Text, Html"; var text = @" Hello, World!"; var html = @" <p>Hello, World!</p>"; var email = new Email("Test"); var renderer = new Mock <IEmailViewRenderer>(); renderer.Setup(r => r.Render(email, "Test.Text")).Returns(text); renderer.Setup(r => r.Render(email, "Test.Html")).Returns(html); var parser = new EmailParser(renderer.Object); using (var message = parser.Parse(input, email)) { message.AlternateViews[0].ContentType.MediaType.ShouldEqual("text/plain"); message.AlternateViews[1].ContentType.MediaType.ShouldEqual("text/html"); } }
public void Given_base_view_is_full_path_Then_alternative_views_are_correctly_looked_up() { var input = @" To: [email protected] From: [email protected] Subject: Test Subject Views: Text, Html"; var text = @"Content-Type: text/plain Hello, World!"; var html = @"Content-Type: text/html <p>Hello, World!</p>"; var email = new Email("~/Views/Emails/Test.cshtml"); var renderer = new Mock <IEmailViewRenderer>(); renderer.Setup(r => r.Render(email, "~/Views/Emails/Test.Text.cshtml")).Returns(text); renderer.Setup(r => r.Render(email, "~/Views/Emails/Test.Html.cshtml")).Returns(html); var parser = new EmailParser(renderer.Object); using (var message = parser.Parse(input, email)) { message.AlternateViews[0].ContentType.ShouldEqual(new ContentType("text/plain; charset=utf-16")); var textContent = new StreamReader(message.AlternateViews[0].ContentStream).ReadToEnd(); textContent.ShouldEqual("Hello, World!"); message.AlternateViews[1].ContentType.ShouldEqual(new ContentType("text/html; charset=utf-16")); var htmlContent = new StreamReader(message.AlternateViews[1].ContentStream).ReadToEnd(); htmlContent.ShouldEqual("<p>Hello, World!</p>"); } }
public async Task Parse_creates_MailMessage_with_headers_and_body() { var input = @" To: [email protected] From: [email protected] CC: [email protected] Bcc: [email protected] Reply-To: [email protected] Sender: [email protected] Priority: Urgent X-Test: test Subject: Test Subject Hello, World!"; var renderer = new Mock <IEmailViewRender>(); var parser = new EmailParser(renderer.Object); var message = await parser.ParseAsync(input, new Email("Test")); message.To[0].ToString().ShouldBe("*****@*****.**"); message.From.ToString().ShouldBe("*****@*****.**"); message.Cc[0].ToString().ShouldBe("*****@*****.**"); message.Bcc[0].ToString().ShouldBe("*****@*****.**"); message.ReplyTo[0].ToString().ShouldBe("*****@*****.**"); message.Subject.ShouldBe("Test Subject"); message.Sender.ToString().ShouldBe("*****@*****.**"); message.Priority.ShouldBe(MessagePriority.Urgent); message.Headers["X-Test"].ShouldBe("test"); message.TextBody.ShouldBe("Hello, World!"); message.HtmlBody.ShouldBeNull(); renderer.Verify(); }
public async Task Parse_creates_MailMessage_with_headers_and_body() { var input = @" To: [email protected] From: [email protected] CC: [email protected] Bcc: [email protected] Reply-To: [email protected] Sender: [email protected] Priority: high X-Test: test Subject: Test Subject Hello, World!"; var renderer = new Mock <IEmailViewRender>(); var parser = new EmailParser(renderer.Object); using (var message = await parser.ParseAsync(input, new Email("Test"))) { message.To[0].Address.ShouldBe("*****@*****.**"); message.From.Address.ShouldBe("*****@*****.**"); message.CC[0].Address.ShouldBe("*****@*****.**"); message.Bcc[0].Address.ShouldBe("*****@*****.**"); message.ReplyToList[0].Address.ShouldBe("*****@*****.**"); message.Subject.ShouldBe("Test Subject"); message.Sender.Address.ShouldBe("*****@*****.**"); message.Priority.ShouldBe(MailPriority.High); message.Headers["X-Test"].ShouldBe("test"); message.Body.ShouldBe("Hello, World!"); message.IsBodyHtml.ShouldBeFalse(); } renderer.Verify(); }
public async Task Given_base_view_is_full_path_Then_alternative_views_are_correctly_looked_up() { var input = @" To: [email protected] From: [email protected] Subject: Test Subject Views: Text, Html"; var text = @"Content-Type: text/plain Hello, World!"; var html = @"Content-Type: text/html <p>Hello, World!</p>"; var email = new Email("~/Views/Emails/Test.cshtml"); var renderer = new Mock <IEmailViewRender>(); renderer.Setup(r => r.RenderAsync(email, "~/Views/Emails/Test.Text.cshtml")).Returns(Task.FromResult(text)); renderer.Setup(r => r.RenderAsync(email, "~/Views/Emails/Test.Html.cshtml")).Returns(Task.FromResult(html)); var parser = new EmailParser(renderer.Object); var message = await parser.ParseAsync(input, email); message.TextBody.ShouldBe("Hello, World!"); message.HtmlBody.ShouldBe("<p>Hello, World!</p>"); renderer.Verify(); }
public async Task Alternative_views_are_added_to_MailMessage() { var input = @" To: [email protected] From: [email protected] Subject: Test Subject Views: Text, Html"; var text = @"Content-Type: text/plain Hello, World!"; var html = @"Content-Type: text/html <p>Hello, World!</p>"; var email = new Email("Test"); var renderer = new Mock <IEmailViewRender>(); renderer.Setup(r => r.RenderAsync(email, "Test.Text")).Returns(Task.FromResult(text)); renderer.Setup(r => r.RenderAsync(email, "Test.Html")).Returns(Task.FromResult(html)); var parser = new EmailParser(renderer.Object); using (var message = await parser.ParseAsync(input, email)) { message.AlternateViews[0].ContentType.ShouldBe(new ContentType("text/plain; charset=utf-16")); var textContent = new StreamReader(message.AlternateViews[0].ContentStream).ReadToEnd(); textContent.ShouldBe("Hello, World!"); message.AlternateViews[1].ContentType.ShouldBe(new ContentType("text/html; charset=utf-16")); var htmlContent = new StreamReader(message.AlternateViews[1].ContentStream).ReadToEnd(); htmlContent.ShouldBe("<p>Hello, World!</p>"); } renderer.Verify(); }
public async Task Alternative_views_are_added_to_MailMessage() { var input = @" To: [email protected] From: [email protected] Subject: Test Subject Views: Text, Html"; var text = @"Content-Type: text/plain Hello, World!"; var html = @"Content-Type: text/html <p>Hello, World!</p>"; var email = new Email("Test"); var renderer = new Mock <IEmailViewRender>(); renderer.Setup(r => r.RenderAsync(email, "Test.Text")).Returns(Task.FromResult(text)); renderer.Setup(r => r.RenderAsync(email, "Test.Html")).Returns(Task.FromResult(html)); var parser = new EmailParser(renderer.Object); var message = await parser.ParseAsync(input, email); message.TextBody.ShouldBe("Hello, World!"); message.HtmlBody.ShouldBe("<p>Hello, World!</p>"); renderer.Verify(); }
public void Parse_creates_MailMessage_with_headers_and_body() { var input = @" To: [email protected] From: [email protected] CC: [email protected] Bcc: [email protected] Reply-To: [email protected] X-Test: test Subject: Test Subject Hello, World!"; var renderer = new Mock <IEmailViewRenderer>(); var parser = new EmailParser(renderer.Object); using (var message = parser.Parse(input, new Email("Test"))) { message.To[0].Address.ShouldEqual("*****@*****.**"); message.From.Address.ShouldEqual("*****@*****.**"); message.CC[0].Address.ShouldEqual("*****@*****.**"); message.Bcc[0].Address.ShouldEqual("*****@*****.**"); message.ReplyToList[0].Address.ShouldEqual("*****@*****.**"); message.Subject.ShouldEqual("Test Subject"); message.Headers["X-Test"].ShouldEqual("test"); message.Body.ShouldEqual("Hello, World!"); message.IsBodyHtml.ShouldBeFalse(); } }
public void Alternative_views_are_added_to_MailMessage() { var input = @" To: [email protected] From: [email protected] Subject: Test Subject Views: Text, Html"; var text = @"Content-Type: text/plain Hello, World!"; var html = @"Content-Type: text/html <p>Hello, World!</p>"; var email = new Email("Test"); var renderer = new Mock <IEmailViewRenderer>(); renderer.Setup(r => r.Render(email, "Test.Text")).Returns(text); renderer.Setup(r => r.Render(email, "Test.Html")).Returns(html); var parser = new EmailParser(renderer.Object); using (var message = parser.Parse(input, email)) { message.AlternateViews[0].ContentType.ShouldEqual(new ContentType("text/plain")); var textContent = new StreamReader(message.AlternateViews[0].ContentStream).ReadToEnd(); textContent.ShouldEqual("Hello, World!"); message.AlternateViews[1].ContentType.ShouldEqual(new ContentType("text/html")); var htmlContent = new StreamReader(message.AlternateViews[1].ContentStream).ReadToEnd(); htmlContent.ShouldEqual("<p>Hello, World!</p>"); } }
public async Task Priority_header_can_be_set_automatically_from_MailPriorityEnum() { dynamic email = new Email("Test"); email.Priority = MessagePriority.Urgent; var parser = new EmailParser(Mock.Of <IEmailViewRender>()); var message = await parser.ParseAsync("body", (Email)email); message.Priority = MessagePriority.Urgent; }
public async Task ReplyTo_header_can_be_set_automatically() { dynamic email = new Email("Test"); email.ReplyTo = "*****@*****.**"; var parser = new EmailParser(Mock.Of <IEmailViewRender>()); var message = await parser.ParseAsync("body", (Email)email); message.ReplyTo[0].ToString().ShouldBe("*****@*****.**"); }
public async Task Subject_header_can_be_set_automatically() { dynamic email = new Email("Test"); email.Subject = "test"; var parser = new EmailParser(Mock.Of <IEmailViewRender>()); var message = await parser.ParseAsync("body", (Email)email); message.Subject.ShouldBe("test"); }
public async Task From_header_can_be_set_automatically_as_MailAddress() { dynamic email = new Email("Test"); email.From = new MailboxAddress("*****@*****.**"); var parser = new EmailParser(Mock.Of <IEmailViewRender>()); var message = await parser.ParseAsync("body", (Email)email); message.From[0].ToString().ShouldBe("*****@*****.**"); }
public void ReplyTo_header_can_be_set_automatically() { dynamic email = new Email("Test"); email.ReplyTo = "*****@*****.**"; var parser = new EmailParser(Mock.Of <IEmailViewRenderer>()); using (var message = parser.Parse("body", (Email)email)) { message.ReplyToList[0].Address.ShouldEqual("*****@*****.**"); } }
public void From_header_can_be_set_automatically_as_MailAddress() { dynamic email = new Email("Test"); email.From = new MailAddress("*****@*****.**"); var parser = new EmailParser(Mock.Of <IEmailViewRenderer>()); using (var message = parser.Parse("body", (Email)email)) { message.From.ShouldEqual(new MailAddress("*****@*****.**")); } }
public async Task Priority_header_can_be_set_automatically() { dynamic email = new Email("Test"); email.Priority = "high"; var parser = new EmailParser(Mock.Of <IEmailViewRender>()); using (var message = await parser.ParseAsync("body", (Email)email)) { message.Priority = MailPriority.High; } }
public void Priority_header_can_be_set_automatically_from_MailPriorityEnum() { dynamic email = new Email("Test"); email.Priority = MailPriority.High; var parser = new EmailParser(Mock.Of <IEmailViewRenderer>()); using (var message = parser.Parse("body", (Email)email)) { message.Priority = MailPriority.High; } }
public void Subject_header_can_be_set_automatically() { dynamic email = new Email("Test"); email.Subject = "test"; var parser = new EmailParser(Mock.Of <IEmailViewRenderer>()); using (var message = parser.Parse("body", (Email)email)) { message.Subject.ShouldEqual("test"); } }
public async Task From_header_can_be_set_automatically() { dynamic email = new Email("Test"); email.From = "*****@*****.**"; var parser = new EmailParser(Mock.Of <IEmailViewRender>()); using (var message = await parser.ParseAsync("body", (Email)email)) { message.From.Address.ShouldBe("*****@*****.**"); } }
public async Task Email_address_can_include_display_name() { var input = @"To: ""John Smith"" <*****@*****.**> From: [email protected] Subject: test message"; var parser = new EmailParser(Mock.Of <IEmailViewRender>()); var email = new Email("Test"); var message = await parser.ParseAsync(input, email); message.To[0].ToString().ShouldBe("*****@*****.**"); message.To[0].Name.ShouldBe("John Smith"); }
public async Task Can_detect_HTML_body() { var input = @" To: [email protected] From: [email protected] Subject: Test Subject <p>Hello, World!</p>"; var renderer = new Mock <IEmailViewRender>(); var parser = new EmailParser(renderer.Object); var message = await parser.ParseAsync(input, new Email("Test")); message.HtmlBody.ShouldBe("<p>Hello, World!</p>"); message.TextBody.ShouldBeNull(); }
public void Email_address_can_include_display_name() { var input = @"To: ""John Smith"" <*****@*****.**> From: [email protected] Subject: test message"; var parser = new EmailParser(Mock.Of <IEmailViewRenderer>()); var email = new Email("Test"); using (var message = parser.Parse(input, email)) { message.To[0].Address.ShouldEqual("*****@*****.**"); message.To[0].DisplayName.ShouldEqual("John Smith"); } }
public async Task Parse_creates_email_addresses_with_display_name() { var input = @" To: John H Smith [email protected] From: [email protected] Subject: Test Subject Hello, World!"; var renderer = new Mock <IEmailViewRender>(); var parser = new EmailParser(renderer.Object); var message = await parser.ParseAsync(input, new Email("Test")); message.To[0].ToString().ShouldBe("*****@*****.**"); message.To[0].ToString().ShouldBe("John H Smith"); renderer.Verify(); }
public void Parse_creates_email_addresses_with_display_name() { var input = @" To: John H Smith [email protected] From: [email protected] Subject: Test Subject Hello, World!"; var renderer = new Mock <IEmailViewRenderer>(); var parser = new EmailParser(renderer.Object); using (var message = parser.Parse(input, new Email("Test"))) { message.To[0].Address.ShouldEqual("*****@*****.**"); message.To[0].DisplayName.ShouldEqual("John H Smith"); } }
public void Attachments_are_added_to_MailMessage() { var input = @" To: [email protected] From: [email protected] Subject: Test Subject Hello, World!"; var email = new Email("Test"); email.Attach(new Attachment(new MemoryStream(), "name")); var parser = new EmailParser(Mock.Of <IEmailViewRenderer>()); var message = parser.Parse(input, email); message.Attachments.Count.ShouldEqual(1); }
public void Can_detect_HTML_body() { var input = @" To: [email protected] From: [email protected] Subject: Test Subject <p>Hello, World!</p>"; var renderer = new Mock <IEmailViewRenderer>(); var parser = new EmailParser(renderer.Object); using (var message = parser.Parse(input, new Email("Test"))) { message.Body.ShouldEqual("<p>Hello, World!</p>"); message.IsBodyHtml.ShouldBeTrue(); } }
public async Task Attachments_are_added_to_MailMessage() { var input = @" To: [email protected] From: [email protected] Subject: Test Subject Hello, World!"; var email = new Email("Test"); email.BodyBuilder.Attachments.Add("name", Array.Empty <byte>()); var parser = new EmailParser(Mock.Of <IEmailViewRender>()); var message = await parser.ParseAsync(input, email); message.Attachments.Count().ShouldBe(1); }
public async Task Can_parse_multiple_email_addresses_in_header() { var input = @" To: [email protected] From: [email protected] CC: [email protected], [email protected], [email protected] Subject: Test Subject Hello, World!"; var renderer = new Mock <IEmailViewRender>(); var parser = new EmailParser(renderer.Object); var message = await parser.ParseAsync(input, new Email("Test")); message.Cc[0].ToString().ShouldBe("*****@*****.**"); message.Cc[1].ToString().ShouldBe("*****@*****.**"); message.Cc[2].ToString().ShouldBe("*****@*****.**"); renderer.Verify(); }