public void ConvertToAkismetItem_WithContactPageFeedback_DoesNotSetPermalink() { // arrange var feedback = new FeedbackItem(FeedbackType.ContactPage); var urlHelper = new Mock<BlogUrlHelper>(); urlHelper.Setup(helper => helper.FeedbackUrl(It.IsAny<FeedbackItem>())).Returns((VirtualPath)null); urlHelper.Setup(helper => helper.BlogUrl()).Returns("/"); var service = new AkismetSpamService("abracadabra", new Blog {Host = "localhost"}, null, urlHelper.Object); // act var comment = service.ConvertToAkismetItem(feedback); // assert Assert.IsNull(comment.Permalink); }
public void ConvertToAkismetItem_WithFeedback_SetsProperties() { // arrange var feedback = new FeedbackItem(FeedbackType.ContactPage) { SourceUrl = new Uri("http://example.com/author-source") }; var urlHelper = new Mock<BlogUrlHelper>(); urlHelper.Setup(helper => helper.FeedbackUrl(It.IsAny<FeedbackItem>())).Returns("/foo"); urlHelper.Setup(helper => helper.BlogUrl()).Returns("/"); var service = new AkismetSpamService("abracadabra", new Blog { Host = "localhost" }, null, urlHelper.Object); // act var comment = service.ConvertToAkismetItem(feedback); // assert Assert.AreEqual("http://example.com/author-source", comment.AuthorUrl.ToString()); Assert.AreEqual("http://localhost/foo", comment.Permalink.ToString()); }
public void Service_WithUrlHelper_UsesItForFeedbackUrl() { //arrange var akismetClient = new Mock<AkismetClient>(); IComment submittedSpam = null; akismetClient.Setup(c => c.SubmitSpam(It.IsAny<IComment>())).Callback<IComment>( comment => submittedSpam = comment); var urlHelper = new Mock<BlogUrlHelper>(); urlHelper.Setup(helper => helper.FeedbackUrl(It.IsAny<FeedbackItem>())).Returns("/feedback-item"); var service = new AkismetSpamService("apikey" , new Blog {Host = "localhost"} , akismetClient.Object , urlHelper.Object); //act service.SubmitSpam(new FeedbackItem(FeedbackType.Comment)); //assert Assert.AreEqual("http://localhost/feedback-item", submittedSpam.Permalink.ToString()); }
private int ApplyActionToCheckedFeedback(Action<FeedbackItem, ICommentSpamService> action) { ICommentSpamService feedbackService = null; if(Blog.FeedbackSpamServiceEnabled) { feedbackService = new AkismetSpamService(Config.CurrentBlog.FeedbackSpamServiceKey, Config.CurrentBlog, null, Url); } int actionsApplied = 0; foreach(RepeaterItem item in feedbackRepeater.Items) { // Get the checkbox from the item or the alternating item. var deleteCheck = item.FindControl("chkDelete") as CheckBox ?? item.FindControl("chkDeleteAlt") as CheckBox; if(deleteCheck != null && deleteCheck.Checked) { // Get the FeedbackId from the item or the alternating item. var feedbackId = item.FindControl("FeedbackId") as HtmlInputHidden ?? item.FindControl("FeedbackIdAlt") as HtmlInputHidden; int id; if(feedbackId != null && int.TryParse(feedbackId.Value, out id)) { FeedbackItem feedbackItem = FeedbackItem.Get(id); if(feedbackItem != null) { actionsApplied++; action(feedbackItem, feedbackService); } } } } return actionsApplied; }
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; } }
protected void lkbPost_Click(object sender, EventArgs e) { try { var entry = new Trackback(EntryId, txbTitle.Text, txbUrl.Text.EnsureUrl(), string.Empty, txbBody.Text.Trim().Length > 0 ? txbBody.Text.Trim() : txbTitle.Text, Config.CurrentBlog.TimeZone.Now); var commentService = new CommentService(SubtextContext, null); if(commentService.Create(entry, true/*runFilters*/) > 0) { ICommentSpamService feedbackService = null; if(Config.CurrentBlog.FeedbackSpamServiceEnabled) { feedbackService = new AkismetSpamService(Config.CurrentBlog.FeedbackSpamServiceKey, Config.CurrentBlog, null, Url); } var filter = new CommentFilter(SubtextContext, feedbackService); filter.FilterAfterPersist(entry); Messages.ShowMessage(Constants.RES_SUCCESSNEW); Edit.Visible = false; Results.Visible = true; } else { Messages.ShowError(Constants.RES_FAILUREEDIT + " There was a baseline problem posting your Trackback."); } } catch(Exception ex) { Log.Error(ex.Message, ex); Messages.ShowError(String.Format(Constants.RES_EXCEPTION, Constants.RES_FAILUREEDIT, ex.Message)); } }
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); }
private void CreateCommentWithContactMessage(FeedbackItem contactMessage) { try { 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(contactMessage, true/*runFilters*/); } catch (BaseCommentException exc) { lblMessage.Text = exc.Message; } }
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); }