public void EmailWithNoViewNameShouldThrow()
        {
            var mockSender = A.Fake<IMailSender>();
            var attribute = new MailAttributes();
            var mailer = new TestMailerBase(attribute, mockSender);

            Assert.Throws<ArgumentNullException>(() => mailer.Email(null));
        }
        public void PassingAMailSenderShouldWork()
        {
            var mockSender = A.Fake<IMailSender>();
            var attribute = new SmtpMailAttributes();
            var mailer = new TestMailerBase(attribute, mockSender);
            var email = mailer.Email("TextViewNoModel");

            Assert.AreSame(mockSender, mailer.MailSender);
            Assert.AreSame(mockSender, email.MailSender);
        }
        public void MultipartMessagesShouldRenderBothViews()
        {
            var mockSender = A.Fake<IMailSender>();
            var attribute = new MailAttributes();
            var mailer = new TestMailerBase(attribute, mockSender);

            var email = mailer.Email("MultipartNoModel");
            var textBody = new StreamReader(email.MailAttributes.AlternateViews[0].ContentStream).ReadToEnd().Trim();
            var htmlBody = new StreamReader(email.MailAttributes.AlternateViews[1].ContentStream).ReadToEnd().Trim();

            Assert.AreEqual("Testing multipart.", textBody);
            Assert.AreEqual("<p>Testing multipart.</p>", htmlBody);
        }
        public void PassingAModelShouldWork()
        {
            var mockSender = A.Fake<IMailSender>();
            var attribute = new MailAttributes();
            var mailer = new TestMailerBase(attribute, mockSender);
            var model = new TestModel
            {
                Name = "Foo"
            };

            var email = mailer.Email("TextViewWithModel", model);
            var body = new StreamReader(email.MailAttributes.AlternateViews[0].ContentStream).ReadToEnd().Trim();

            Assert.AreEqual("Your name is:  Foo", body);
        }
        public void RazorViewWithNoModelShouldRenderProperly()
        {
            var mockSender = A.Fake<IMailSender>();
            var attribute = new MailAttributes();
            var mailer = new TestMailerBase(attribute, mockSender);

            var email = mailer.Email("TextViewNoModel");
            var body = new StreamReader(email.MailAttributes.AlternateViews[0].ContentStream).ReadToEnd().Trim();

            Assert.AreEqual("This is a test", body);
        }
        public void WhiteSpaceShouldBeTrimmedWhenRequired()
        {
            var mockSender = A.Fake<IMailSender>();
            var attribute = new MailAttributes();
            var mailer = new TestMailerBase(attribute, mockSender);

            var email = mailer.Email("WhitespaceTrimTest", trimBody: true);
            var body = new StreamReader(email.MailAttributes.AlternateViews[0].ContentStream).ReadToEnd();

            Assert.AreEqual("This thing has leading and trailing whitespace.", body);
        }
        public void WhiteSpaceShouldBeIncludedWhenRequired()
        {
            var mockSender = A.Fake<IMailSender>();
            var attribute = new MailAttributes();
            var mailer = new TestMailerBase(attribute, mockSender);

            var email = mailer.Email("WhitespaceTrimTest", null, false);
            var body = new StreamReader(email.MailAttributes.AlternateViews[0].ContentStream).ReadToEnd();

            Assert.True(char.IsWhiteSpace(body,0));
            Assert.True(char.IsWhiteSpace(body, body.Length-1));
        }
        public void WhiteSpaceShouldBeIncludedWhenRequired()
        {
            var mockSender = A.Fake<IMailSender>();
            var attribute = new SmtpMailAttributes();
            var mailer = new TestMailerBase(attribute, mockSender);

            var email = mailer.Email("WhitespaceTrimTest", false);
            var body = new StreamReader(email.Mail.AlternateViews[0].ContentStream).ReadToEnd();

            Assert.True(body.StartsWith(Environment.NewLine));
            Assert.True(body.EndsWith(Environment.NewLine));
        }