Пример #1
0
        private static UrlHelper GetUrlHelper()
        {
            HttpContextBase httpcontext = MvcHelper.GetHttpContext("/app/", null, null);
            UrlHelper       urlHelper   = new UrlHelper(new RequestContext(httpcontext, GetRouteData()), GetRouteCollection());

            return(urlHelper);
        }
Пример #2
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);
        }
Пример #3
0
        private static RequestContext GetRequestContext()
        {
            HttpContextBase httpcontext = MvcHelper.GetHttpContext("/app/", null, null);
            RouteData       rd          = new RouteData();

            return(new RequestContext(httpcontext, rd));
        }
Пример #4
0
        public void ViewNameShouldBeRequiredWhenUsingCallingEmailMethod()
        {
            var mailer = new TestMailerBase();

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

            Assert.Throws <ArgumentNullException>(() => mailer.Email(null));
        }
Пример #5
0
        public void ViewNameShouldBePassedProperly()
        {
            var mailer = new TestMailController();

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

            EmailResult email = mailer.TestMail();

            Assert.AreEqual("TestView", email.ViewName);
        }
Пример #6
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);
        }
Пример #7
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);
        }
Пример #8
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"]);
        }
Пример #9
0
        public void AreasAreDetectedProperly()
        {
            var rd = new RouteData();

            rd.Values.Add("area", "TestArea");
            var mailer = new MailController();

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

            mailer.TestEmail();

            Assert.NotNull(mailer.ControllerContext.RouteData.DataTokens["area"]);
            Assert.AreEqual("TestArea", mailer.ControllerContext.RouteData.DataTokens["area"]);
        }
Пример #10
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);
        }
Пример #11
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);
        }
Пример #12
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);
        }
Пример #13
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);
        }
Пример #14
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));
        }