public void EmailMethodShouldAllowMultipleViews()
        {
            var mailer = new TestMailerBase();
            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new MultipartViewEngine());
            mailer.HttpContextBase = MvcHelper.GetHttpContext("/app/", null, null);
            mailer.MailAttributes.From = new MailAddress("*****@*****.**");

            // there's no need to test the built-in view engines.
            // this test just ensures that our Email() method actually
            // populates the mail body properly.
            EmailResult result = mailer.Email("TestView");

            Assert.AreEqual(2, result.MailAttributes.AlternateViews.Count());

            var textReader = new StreamReader(result.MailAttributes.AlternateViews[0].ContentStream);
            string textBody = textReader.ReadToEnd();
            StringAssert.Contains("TextView", textBody);
            Assert.AreEqual("text/plain", result.MailAttributes.AlternateViews[0].ContentType.MediaType);

            var htmlReader = new StreamReader(result.MailAttributes.AlternateViews[1].ContentStream);
            string htmlBody = htmlReader.ReadToEnd();
            StringAssert.Contains("HtmlView", htmlBody);
            Assert.AreEqual("text/html", result.MailAttributes.AlternateViews[1].ContentType.MediaType);
        }
Esempio n. 2
0
        public void EmailMethodShouldRenderViewAsMessageBody()
        {
            var mailer = new TestMailerBase();

            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new TextViewEngine());
            mailer.HttpContextBase     = MvcHelper.GetHttpContext("/app/", null, null);
            mailer.MailAttributes.From = new MailAddress("*****@*****.**");

            // there's no need to test the built-in view engines.
            // this test just ensures that our Email() method actually
            // populates the mail body properly.
            EmailResult result = mailer.Email("TestView");
            var         reader = new StreamReader(result.MailAttributes.AlternateViews[0].ContentStream);
            string      body   = reader.ReadToEnd().Trim();

            Assert.AreEqual("TextView", body);
        }
Esempio n. 3
0
        public void WhiteSpaceShouldBeTrimmedWhenRequired()
        {
            var mailer = new TestMailerBase();

            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new WhiteSpaceViewEngine());
            mailer.HttpContextBase     = MvcHelper.GetHttpContext("/app/", null, null);
            mailer.MailAttributes.From = new MailAddress("*****@*****.**");

            // there's no need to test the built-in view engines.
            // this test just ensures that our Email() method actually
            // populates the mail body properly.
            EmailResult result = mailer.Email("WhiteSpaceView", trimBody: true);
            var         reader = new StreamReader(result.MailAttributes.AlternateViews[0].ContentStream);
            string      body   = reader.ReadToEnd();

            Assert.AreEqual("This thing has leading and trailing whitespace.", body);
        }
Esempio n. 4
0
        public void WhiteSpaceShouldBeIncludedWhenRequired()
        {
            var mailer = new TestMailerBase();

            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new WhiteSpaceViewEngine());
            mailer.HttpContextBase     = MvcHelper.GetHttpContext("/app/", null, null);
            mailer.MailAttributes.From = new MailAddress("*****@*****.**");

            // there's no need to test the built-in view engines.
            // this test just ensures that our Email() method actually
            // populates the mail body properly.
            EmailResult result = mailer.Email("WhiteSpaceView", trimBody: false);
            var         reader = new StreamReader(result.MailAttributes.AlternateViews[0].ContentStream);
            string      body   = reader.ReadToEnd();

            Assert.True(body.StartsWith(Environment.NewLine));
            Assert.True(body.EndsWith(Environment.NewLine));
        }
        public void EmailMethodShouldRenderViewAsMessageBody()
        {
            var mailer = new TestMailerBase();
            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new TextViewEngine());
            mailer.HttpContextBase = MvcHelper.GetHttpContext("/app/", null, null);
            mailer.MailAttributes.From = new MailAddress("*****@*****.**");

            // there's no need to test the built-in view engines.
            // this test just ensures that our Email() method actually
            // populates the mail body properly.
            EmailResult result = mailer.Email("TestView");
            var reader = new StreamReader(result.MailAttributes.AlternateViews[0].ContentStream);
            string body = reader.ReadToEnd().Trim();

            Assert.AreEqual("TextView", body);
        }
        public void WhiteSpaceShouldBeTrimmedWhenRequired()
        {
            var mailer = new TestMailerBase();
            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new WhiteSpaceViewEngine());
            mailer.HttpContextBase = MvcHelper.GetHttpContext("/app/", null, null);
            mailer.MailAttributes.From = new MailAddress("*****@*****.**");

            // there's no need to test the built-in view engines.
            // this test just ensures that our Email() method actually
            // populates the mail body properly.
            EmailResult result = mailer.Email("WhiteSpaceView", trimBody: true);
            var reader = new StreamReader(result.MailAttributes.AlternateViews[0].ContentStream);
            string body = reader.ReadToEnd();

            Assert.AreEqual("This thing has leading and trailing whitespace.", body);
        }
        public void ViewNameShouldBeRequiredWhenUsingCallingEmailMethod()
        {
            var mailer = new TestMailerBase();
            mailer.HttpContextBase = MvcHelper.GetHttpContext("/app/", null, null);

            Assert.Throws<ArgumentNullException>(() => mailer.Email(null));
        }
        public void WhiteSpaceShouldBeIncludedWhenRequired()
        {
            var mailer = new TestMailerBase();
            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new WhiteSpaceViewEngine());
            mailer.HttpContextBase = MvcHelper.GetHttpContext("/app/", null, null);
            mailer.MailAttributes.From = new MailAddress("*****@*****.**");

            // there's no need to test the built-in view engines.
            // this test just ensures that our Email() method actually
            // populates the mail body properly.
            EmailResult result = mailer.Email("WhiteSpaceView", trimBody: false);
            var reader = new StreamReader(result.MailAttributes.AlternateViews[0].ContentStream);
            string body = reader.ReadToEnd();

            Assert.True(body.StartsWith(Environment.NewLine));
            Assert.True(body.EndsWith(Environment.NewLine));
        }
        public void ViewDataShouldCopyToEmailResult()
        {
            var mailer = new TestMailerBase();
            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new TextViewEngine());
            mailer.HttpContextBase = MvcHelper.GetHttpContext("/app/", null, null);
            mailer.MailAttributes.From = new MailAddress("*****@*****.**");

            mailer.ViewData["foo"] = "bar";
            EmailResult result = mailer.Email("TestView");

            Assert.True(result.ViewData.ContainsKey("foo"));
            Assert.AreEqual("bar", result.ViewData["foo"]);
        }
Esempio n. 10
0
        public void ViewBagDataShouldCopyToEmailResult()
        {
            var mailer = new TestMailerBase();
            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new TextViewEngine());
            mailer.HttpContextBase = MvcHelper.GetHttpContext("/app/", null, null);
            mailer.MailAttributes.From = new MailAddress("*****@*****.**");

            mailer.ViewBag.Test = "12345";
            EmailResult result = mailer.Email("TestView");

            Assert.AreEqual("12345", result.ViewBag.Test);
        }
Esempio n. 11
0
        public void PassingAMailSenderShouldWork()
        {
            var mockSender = A.Fake<IMailSender>();
            var attributes = new MailAttributes();
            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new TextViewEngine());

            var mailer = new TestMailerBase(attributes, mockSender);
            mailer.HttpContextBase = MvcHelper.GetHttpContext("/app/", null, null);
            mailer.MailAttributes.From = new MailAddress("*****@*****.**");
            EmailResult result = mailer.Email("TestView");

            Assert.AreSame(mockSender, mailer.MailSender);
            Assert.AreSame(mockSender, result.MailSender);
        }
Esempio n. 12
0
        public void ModelObjectShouldCopyToEmailResult()
        {
            var mailer = new TestMailerBase();
            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new TextViewEngine());
            mailer.HttpContextBase = MvcHelper.GetHttpContext("/app/", null, null);
            mailer.MailAttributes.From = new MailAddress("*****@*****.**");

            object model = "12345";
            EmailResult result = mailer.Email("TestView", model);

            Assert.AreSame(model, result.ViewData.Model);
        }
Esempio n. 13
0
        public void MessageEncodingOverrideShouldWork()
        {
            var mailer = new TestMailerBase();
            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new UTF8ViewEngine());
            mailer.HttpContextBase = MvcHelper.GetHttpContext("/app/", null, null);
            mailer.MailAttributes.From = new MailAddress("*****@*****.**");
            mailer.MailAttributes.MessageEncoding = Encoding.UTF8;

            EmailResult result = mailer.Email("TestView");
            var reader = new StreamReader(result.MailAttributes.AlternateViews[0].ContentStream);
            string body = reader.ReadToEnd();

            Assert.AreEqual(Encoding.UTF8, result.MessageEncoding);
            Assert.AreEqual("Umlauts are Über!", body);
        }