コード例 #1
0
ファイル: EmailServiceTests.cs プロジェクト: rhoadsce/Subtext
        public void EmailCommentToBlogAuthor_WithBlog_UsesBlogEmailForToEmail()
        {
            //arrange
            var comment = new FeedbackItem(FeedbackType.Comment)
            {Id = 121, Author = "me", Title = "the subject", FlaggedAsSpam = false};
            var emailProvider = new Mock<EmailProvider>();
            var templateEngine = new Mock<ITemplateEngine>();
            var template = new Mock<ITextTemplate>();
            templateEngine.Setup(t => t.GetTemplate(It.IsAny<string>())).Returns(template.Object);
            template.Setup(t => t.Format(It.IsAny<object>())).Returns("message");
            var urlHelper = new Mock<BlogUrlHelper>();
            urlHelper.Setup(u => u.FeedbackUrl(comment)).Returns("/");
            var context = new Mock<ISubtextContext>();
            context.Setup(c => c.UrlHelper).Returns(urlHelper.Object);
            context.Setup(c => c.Blog).Returns(new Blog
            {Email = "*****@*****.**", Author = "to", Host = "localhost", Title = "the blog"});

            string toEmail = null;
            emailProvider.Setup(
                e => e.Send(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Callback
                <string, string, string, string>((to, from, title, message) => toEmail = to);
            var emailService = new EmailService(emailProvider.Object, templateEngine.Object, context.Object);

            //act
            emailService.EmailCommentToBlogAuthor(comment);

            //assert
            Assert.AreEqual("*****@*****.**", toEmail);
        }
コード例 #2
0
ファイル: EmailServiceTests.cs プロジェクト: rhoadsce/Subtext
        public void EmailCommentToBlogAuthor_WithBlogHavingNullEmail_DoesNotSendEmail()
        {
            //arrange
            var comment = new FeedbackItem(FeedbackType.Comment) {};
            var blog = new Blog {Email = string.Empty};
            var emailProvider = new Mock<EmailProvider>();
            var context = new Mock<ISubtextContext>();
            context.Setup(c => c.UrlHelper).Returns(new Mock<BlogUrlHelper>().Object);
            context.Setup(c => c.Blog).Returns(blog);
            var emailService = new EmailService(emailProvider.Object, new Mock<ITemplateEngine>().Object, context.Object);
            emailProvider.Setup(
                e => e.Send(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Throws(
                new Exception());

            //act
            emailService.EmailCommentToBlogAuthor(comment);
        }
コード例 #3
0
ファイル: EmailServiceTests.cs プロジェクト: rhoadsce/Subtext
        public void EmailCommentToBlogAuthor_WithCommentHavingNullSource_SendsEmail()
        {
            //arrange
            var comment = new FeedbackItem(FeedbackType.Comment) { Id = 121, Author = "me", Title = "the subject", FlaggedAsSpam = false, Entry = null };
            var emailProvider = new Mock<EmailProvider>();
            var context = new Mock<ISubtextContext>();
            context.Setup(c => c.Blog).Returns(new Blog {Title = "the blog", Email = "*****@*****.**"});
            context.Setup(c => c.User.IsInRole("Admins")).Returns(false);
            context.Setup(c => c.UrlHelper.FeedbackUrl(It.IsAny<FeedbackItem>())).Returns((VirtualPath)null);
            var templateEngine = new Mock<ITemplateEngine>();
            var template = new Mock<ITextTemplate>();
            template.Setup(t => t.Format(It.IsAny<Object>())).Returns("whatever");
            templateEngine.Setup(t => t.GetTemplate("CommentReceived")).Returns(template.Object);
            var emailService = new EmailService(emailProvider.Object, templateEngine.Object, context.Object);
            string subject = null;
            emailProvider.Setup(
                e => e.Send(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Callback
                <string, string, string, string>((to, from, title, message) => subject = title);

            //act
            emailService.EmailCommentToBlogAuthor(comment);

            //assert
            Assert.AreEqual("Comment: the subject (via the blog)", subject);
        }
コード例 #4
0
ファイル: EmailServiceTests.cs プロジェクト: rhoadsce/Subtext
        public void EmailCommentToBlogAuthor_WithCurrentUserIsAnAdmin_DoesNotSendEmail()
        {
            //arrange
            var comment = new FeedbackItem(FeedbackType.Comment) {};
            var blog = new Blog {Email = "*****@*****.**", UserName = "******"};
            var emailProvider = new Mock<EmailProvider>();
            var context = new Mock<ISubtextContext>();
            context.Setup(c => c.UrlHelper).Returns(new Mock<BlogUrlHelper>().Object);
            context.Setup(c => c.Blog).Returns(blog);
            context.Setup(c => c.User.Identity.Name).Returns("cody");
            context.Setup(c => c.User.IsInRole("Admins")).Returns(true);
            var emailService = new EmailService(emailProvider.Object, new Mock<ITemplateEngine>().Object, context.Object);
            emailProvider.Setup(
                e => e.Send(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Throws(
                new Exception());

            //act
            emailService.EmailCommentToBlogAuthor(comment);
        }
コード例 #5
0
ファイル: PostComment.cs プロジェクト: ChrisPelatari/SubText
        private void OnSubmitButtonClick(object sender, EventArgs e)
        {
            Thread.Sleep(5000);
            if(!Page.IsValid)
            {
                return;
            }

            LastDitchValidation();
            try
            {
                Entry currentEntry = RealEntry;
                if(IsCommentAllowed)
                {
                    FeedbackItem feedbackItem = CreateFeedbackInstanceFromFormInput(currentEntry);
                    ICommentSpamService feedbackService = null;
                    if(Blog.FeedbackSpamServiceEnabled)
                    {
                        feedbackService = new AkismetSpamService(Blog.FeedbackSpamServiceKey, Blog, null, Url);
                    }
                    var commentService = new CommentService(SubtextContext,
                                                            new CommentFilter(SubtextContext, feedbackService));
                    commentService.Create(feedbackItem, true/*runFilters*/);
                    var emailService = new EmailService(EmailProvider.Instance(), new EmbeddedTemplateEngine(),
                                                        SubtextContext);
                    emailService.EmailCommentToBlogAuthor(feedbackItem);

                    if(chkRemember == null || chkRemember.Checked)
                    {
                        SetRememberedUserCookie();
                    }

                    DisplayResultMessage(feedbackItem);
                }
            }
            catch(BaseCommentException exception)
            {
                Message.Text = exception.Message;
            }
        }
コード例 #6
0
        private void CreateTrackbackAndSendResponse(ISubtextContext subtextContext, IEntryIdentity entry, int entryId)
        {
            HttpContextBase context = subtextContext.RequestContext.HttpContext;
            string title = SafeParam(context, "title");
            string excerpt = SafeParam(context, "excerpt");
            string urlText = SafeParam(context, "url");
            string blogName = SafeParam(context, "blog_name");

            Uri url = urlText.ParseUri();
            if (url == null)
            {
                SendTrackbackResponse(context, 1, Resources.TrackbackResponse_NoUrl);
                return;
            }

            if (entry == null ||
               !IsSourceVerification(url,
                                     subtextContext.UrlHelper.EntryUrl(entry).ToFullyQualifiedUrl(subtextContext.Blog)))
            {
                SendTrackbackResponse(context, 2,
                                      String.Format(CultureInfo.InvariantCulture,
                                                    Resources.TrackbackResponse_NoRelevantLink, url));
                return;
            }

            var trackback = new Trackback(entryId, title, url, blogName, excerpt);
            ICommentSpamService feedbackService = null;
            Blog blog = subtextContext.Blog;
            if (blog.FeedbackSpamServiceEnabled)
            {
                feedbackService = new AkismetSpamService(blog.FeedbackSpamServiceKey, blog, null, Url);
            }
            var commentService = new CommentService(SubtextContext, new CommentFilter(SubtextContext, feedbackService));
            commentService.Create(trackback, true/*runFilters*/);
            //TODO: Create this using IoC container
            var emailService = new EmailService(EmailProvider.Instance(), new EmbeddedTemplateEngine(), subtextContext);
            emailService.EmailCommentToBlogAuthor(trackback);
        }
コード例 #7
0
ファイル: Contact.cs プロジェクト: rsaladrigas/Subtext
        private void OnSendButtonClick(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                var contactMessage = new FeedbackItem(FeedbackType.ContactPage)
                {
                    Author = tbName.Text,
                    Email = tbEmail.Text,
                    Body = tbMessage.Text,
                    Title = string.Format("CONTACT: {0}", tbSubject.Text),
                    IpAddress = HttpHelper.GetUserIpAddress(SubtextContext.HttpContext)
                };

                if (SendContactMessageToFeedback || String.IsNullOrEmpty(Blog.Email))
                {
                    CreateCommentWithContactMessage(contactMessage);
                }
                else
                {
                    try
                    {
                        var emailService = new EmailService(EmailProvider.Instance(), new EmbeddedTemplateEngine(),
                                                        SubtextContext);
                        emailService.EmailCommentToBlogAuthor(contactMessage);
                    }
                    catch (Exception)
                    {
                        lblMessage.Text =
                            "Your message could not be sent, most likely due to a problem with the mail server.";
                        return;
                    }
                }
                if (!Context.User.IsAdministrator())
                {
                    lblMessage.Text = "Your message was sent.";
                }
                else
                {
                    lblMessage.Text = "Message submitted successfully, but no email was sent because you&#8217;re logged in as administrator.";
                }
                SwapWithLabel(tbName);
                SwapWithLabel(tbEmail);
                SwapWithLabel(tbMessage);
                SwapWithLabel(tbSubject);
                if (captcha != null)
                {
                    Controls.Remove(captcha);
                }
                Controls.Remove(btnSend);
            }
        }
コード例 #8
0
ファイル: Contact.cs プロジェクト: ChrisPelatari/SubText
        private void OnSendButtonClick(object sender, EventArgs e)
        {
            if(Page.IsValid)
            {
                var contactMessage = new FeedbackItem(FeedbackType.ContactPage)
                {
                    Author = tbName.Text,
                    Email = tbEmail.Text,
                    Body = tbMessage.Text,
                    Title = string.Format("CONTACT: {0}", tbSubject.Text),
                    IpAddress = HttpHelper.GetUserIpAddress(SubtextContext.HttpContext)
                };

                if(SendContactMessageToFeedback || String.IsNullOrEmpty(Blog.Email))
                {
                    CreateCommentWithContactMessage(contactMessage);
                }
                else
                {

                    try
                    {
                        var emailService = new EmailService(EmailProvider.Instance(), new EmbeddedTemplateEngine(),
                                                        SubtextContext);
                        emailService.EmailCommentToBlogAuthor(contactMessage);
                    }
                    catch(Exception)
                    {
                        lblMessage.Text =
                            "Your message could not be sent, most likely due to a problem with the mail server.";
                        return;
                    }
                }
                lblMessage.Text = "Your message was sent.";
            }
        }
コード例 #9
0
        public string pingBack(string sourceURI, string targetURI)
        {
            if (!Blog.TrackbacksEnabled)
            {
                return "Pingbacks are not enabled for this site.";
            }

            string pageTitle;

            // GetPostIDFromUrl returns the postID
            int? id = SubtextContext.RequestContext.GetIdFromRequest();
            if (id == null)
            {
                throw new XmlRpcFaultException(33, Resources.XmlRcpFault_DidNotLinkToPermalink);
            }

            Uri sourceUrl = sourceURI.ParseUri();
            Uri targetUrl = targetURI.ParseUri();

            // does the sourceURI actually contain the permalink ?
            if (sourceUrl == null || targetUrl == null ||
               !Verifier.SourceContainsTarget(sourceUrl, targetUrl, out pageTitle))
            {
                throw new XmlRpcFaultException(17, Resources.XmlRcpFault_InvalidLink);
            }

            //PTR = Pingback - TrackBack - Referral
            var trackback = new Trackback(id.Value, HtmlHelper.SafeFormat(pageTitle, SubtextContext.HttpContext.Server),
                                          new Uri(sourceURI), string.Empty,
                                          HtmlHelper.SafeFormat(pageTitle, SubtextContext.HttpContext.Server));
            ICommentSpamService feedbackService = null;
            if (Blog.FeedbackSpamServiceEnabled)
            {
                feedbackService = new AkismetSpamService(Blog.FeedbackSpamServiceKey, Blog, null, Url);
            }
            var commentService = new CommentService(SubtextContext, new CommentFilter(SubtextContext, feedbackService));
            commentService.Create(trackback, true/*runFilters*/);

            //TODO: Create this using IoC container
            var emailService = new EmailService(EmailProvider.Instance(), new EmbeddedTemplateEngine(), SubtextContext);
            emailService.EmailCommentToBlogAuthor(trackback);

            return String.Format(CultureInfo.InvariantCulture, Resources.XmlRpcMessage_ThanksForThePingback, sourceURI);
        }