コード例 #1
0
        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);
            });
        }
コード例 #2
0
        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();
        }
コード例 #3
0
ファイル: EmailParserTests.cs プロジェクト: Farami/postal
        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");
            }
        }
コード例 #4
0
ファイル: EmailParserTests.cs プロジェクト: Farami/postal
        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>");
            }
        }
コード例 #5
0
        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();
        }
コード例 #6
0
        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();
        }
コード例 #7
0
        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();
        }
コード例 #8
0
        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();
        }
コード例 #9
0
        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();
        }
コード例 #10
0
        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();
            }
        }
コード例 #11
0
        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>");
            }
        }
コード例 #12
0
        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;
        }
コード例 #13
0
        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("*****@*****.**");
        }
コード例 #14
0
        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");
        }
コード例 #15
0
        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("*****@*****.**");
        }
コード例 #16
0
        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("*****@*****.**");
            }
        }
コード例 #17
0
        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("*****@*****.**"));
            }
        }
コード例 #18
0
        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;
            }
        }
コード例 #19
0
ファイル: EmailParserTests.cs プロジェクト: Farami/postal
        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;
            }
        }
コード例 #20
0
        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");
            }
        }
コード例 #21
0
        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("*****@*****.**");
            }
        }
コード例 #22
0
        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");
        }
コード例 #23
0
        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();
        }
コード例 #24
0
        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");
            }
        }
コード例 #25
0
        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();
        }
コード例 #26
0
ファイル: EmailParserTests.cs プロジェクト: Farami/postal
        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");
            }
        }
コード例 #27
0
        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);
        }
コード例 #28
0
        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();
            }
        }
コード例 #29
0
        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);
        }
コード例 #30
0
        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();
        }