Esempio n. 1
0
        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);
        }
        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. 3
0
        public void ViewNameShouldBeRequiredWhenUsingCallingEmailMethod()
        {
            var mailer = new TestMailerBase();

            mailer.HttpContextBase = MvcHelper.GetHttpContext("/app/", null, null);

            Assert.Throws <ArgumentNullException>(() => mailer.Email(null));
        }
Esempio n. 4
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. 5
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. 6
0
        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. 7
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. 8
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);
        }
Esempio n. 9
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. 10
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. 11
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));
        }
Esempio n. 12
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);
        }
Esempio n. 13
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. 14
0
        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. 15
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. 16
0
        public void ViewNameShouldBeRequiredWhenUsingCallingEmailMethod()
        {
            var mailer = new TestMailerBase();
            mailer.HttpContextBase = MvcHelper.GetHttpContext("/app/", null, null);

            Assert.Throws<ArgumentNullException>(() => mailer.Email(null));
        }
Esempio n. 17
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));
        }
Esempio n. 18
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. 19
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. 20
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);
        }