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 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); }
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); }
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 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 ViewNameShouldBeRequiredWhenUsingCallingEmailMethod() { var mailer = new TestMailerBase(); mailer.HttpContextBase = MvcHelper.GetHttpContext("/app/", null, null); Assert.Throws<ArgumentNullException>(() => mailer.Email(null)); }
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"]); }
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); }
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); }
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); }