public void TrackbackShowsUpInFeedbackList() { string hostname = UnitTestHelper.GenerateUniqueString(); var repository = new DatabaseObjectProvider(); repository.CreateBlog("", "username", "password", hostname, "blog"); UnitTestHelper.SetHttpContextWithBlogRequest(hostname, "blog", string.Empty); Blog blog = repository.GetBlog(hostname, "blog"); BlogRequest.Current.Blog = blog; Entry parentEntry = UnitTestHelper.CreateEntryInstanceForSyndication("philsath aeuoa asoeuhtoensth", "sntoehu title aoeuao eu", "snaot hu aensaoehtu body"); int parentId = UnitTestHelper.Create(parentEntry); ICollection<FeedbackItem> entries = repository.GetFeedbackForEntry(parentEntry); Assert.AreEqual(0, entries.Count, "Did not expect any feedback yet."); var trackback = new Trackback(parentId, "title", new Uri("http://url"), "phil", "body"); Config.CurrentBlog.DuplicateCommentsEnabled = true; var subtextContext = new Mock<ISubtextContext>(); subtextContext.Setup(c => c.Cache).Returns(new TestCache()); subtextContext.SetupBlog(Config.CurrentBlog); subtextContext.SetupRepository(repository); subtextContext.Setup(c => c.HttpContext.Items).Returns(new Hashtable()); var commentService = new CommentService(subtextContext.Object, null); int trackbackId = commentService.Create(trackback, true/*runFilters*/); new DatabaseObjectProvider().Approve(trackback, null); entries = repository.GetFeedbackForEntry(parentEntry); Assert.AreEqual(1, entries.Count, "Expected a trackback."); Assert.AreEqual(trackbackId, entries.First().Id, "The feedback was not the same one we expected. The IDs do not match."); }
public void CreateTrackbackSetsFeedbackTypeCorrectly() { string hostname = UnitTestHelper.GenerateUniqueString(); var repository = new DatabaseObjectProvider(); repository.CreateBlog("", "username", "password", hostname, string.Empty); UnitTestHelper.SetHttpContextWithBlogRequest(hostname, string.Empty, string.Empty); Blog blog = repository.GetBlog(hostname, string.Empty); BlogRequest.Current.Blog = blog; Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("phil", "title", "body"); int parentId = UnitTestHelper.Create(entry); var trackback = new Trackback(parentId, "title", new Uri("http://url"), "phil", "body"); var subtextContext = new Mock<ISubtextContext>(); subtextContext.Setup(c => c.Blog).Returns(Config.CurrentBlog); //TODO: FIX!!! subtextContext.Setup(c => c.Repository).Returns(repository); subtextContext.Setup(c => c.Cache).Returns(new TestCache()); subtextContext.Setup(c => c.HttpContext.Items).Returns(new Hashtable()); var commentService = new CommentService(subtextContext.Object, null); int id = commentService.Create(trackback, true/*runFilters*/); FeedbackItem loadedTrackback = repository.Get(id); Assert.IsNotNull(loadedTrackback, "Was not able to load trackback from storage."); Assert.AreEqual(FeedbackType.PingTrack, loadedTrackback.FeedbackType, "Feedback should be a PingTrack"); }
public void CreateTrackbackSetsFeedbackTypeCorrectly() { string hostname = UnitTestHelper.GenerateRandomString(); Assert.IsTrue(Config.CreateBlog("", "username", "password", hostname, string.Empty)); UnitTestHelper.SetHttpContextWithBlogRequest(hostname, string.Empty, string.Empty); Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("phil", "title", "body"); int parentId = Entries.Create(entry); Trackback trackback = new Trackback(parentId, "title", new Uri("http://url"), "phil", "body"); int id = FeedbackItem.Create(trackback, null); FeedbackItem loadedTrackback = FeedbackItem.Get(id); Assert.IsNotNull(loadedTrackback, "Was not able to load trackback from storage."); Assert.AreEqual(FeedbackType.PingTrack, loadedTrackback.FeedbackType, "Feedback should be a PingTrack"); }
public void TrackbackShowsUpInFeedbackList() { string hostname = UnitTestHelper.GenerateRandomString(); Assert.IsTrue(Config.CreateBlog("", "username", "password", hostname, "blog")); UnitTestHelper.SetHttpContextWithBlogRequest(hostname, "blog", string.Empty); Entry parentEntry = UnitTestHelper.CreateEntryInstanceForSyndication("philsath aeuoa asoeuhtoensth", "sntoehu title aoeuao eu", "snaot hu aensaoehtu body"); int parentId = Entries.Create(parentEntry); IList<FeedbackItem> entries = Entries.GetFeedBack(parentEntry); Assert.AreEqual(0, entries.Count, "Did not expect any feedback yet."); Trackback trackback = new Trackback(parentId, "title", new Uri("http://url"), "phil", "body"); Config.CurrentBlog.DuplicateCommentsEnabled = true; int trackbackId = FeedbackItem.Create(trackback, null); FeedbackItem.Approve(trackback); entries = Entries.GetFeedBack(parentEntry); Assert.AreEqual(1, entries.Count, "Expected a trackback."); Assert.AreEqual(trackbackId, entries[0].Id, "The feedback was not the same one we expected. The IDs do not match."); }
private void CreateTrackbackAndSendResponse(HttpContext context, Entry entry, int entryId) { string title = SafeParam(context, "title"); string excerpt = SafeParam(context, "excerpt"); string urlText = SafeParam(context, "url"); string blog_name = SafeParam(context, "blog_name"); Uri url = HtmlHelper.ParseUri(urlText); if (url == null) { SendTrackbackResponse(context, 1, "no url parameter found, please try harder!"); return; } if (entry == null || !IsSourceVerification(url, entry.FullyQualifiedUrl)) { SendTrackbackResponse(context, 2, "Sorry couldn't find a relevant link in " + url); return; } Trackback trackback = new Trackback(entryId, title, url, blog_name, excerpt); FeedbackItem.Create(trackback, new CommentFilter(HttpContext.Current.Cache)); }
public void WritingBlogMLWithEverythingWorks() { CreateBlogAndSetupContext(); LinkCategory category = new LinkCategory(); category.Title = "CategoryA"; category.BlogId = Config.CurrentBlog.Id; category.CategoryType = CategoryType.PostCollection; category.IsActive = true; Links.CreateLinkCategory(category); //Add a few entries. Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("phil", "blah blah", "full bodied goodness"); entry.Categories.Add("CategoryA"); Entries.Create(entry); //Add a comment. FeedbackItem comment = UnitTestHelper.CreateCommentInstance(entry.Id, "joe", "re: blah", UnitTestHelper.GenerateRandomString(), DateTime.Now); comment.FeedbackType = FeedbackType.Comment; FeedbackItem.Create(comment, null); FeedbackItem.Approve(comment); //Add a trackback. Trackback trackback = new Trackback(entry.Id, "blah", new Uri("http://example.com/"), "you", "your post is great" + UnitTestHelper.GenerateRandomString()); FeedbackItem.Create(trackback, null); FeedbackItem.Approve(trackback); //setup provider // Not using BlogMlProvider.Instance() because we need to reset the state. SubtextBlogMLProvider provider = new SubtextBlogMLProvider(); provider.ConnectionString = Config.ConnectionString; BlogMLWriter writer = BlogMLWriter.Create(provider); // TODO- BlogML 2.0 // writer.EmbedAttachments = false; //Note, once the next version of BlogML is released, we can cleanup some of this. StringBuilder builder = new StringBuilder(); StringWriter textWriter = new StringWriter(builder); XmlTextWriter xml = new XmlTextWriter(textWriter); XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = " "; XmlWriter xmlWriter = XmlWriter.Create(xml); writer.Write(xmlWriter); XmlDocument doc = new XmlDocument(); doc.LoadXml(builder.ToString()); XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("bml", "http://www.blogml.com/2006/09/BlogML"); Console.WriteLine(doc.InnerXml); XmlNode postNode = doc.SelectSingleNode("bml:blog/bml:posts/bml:post[@id='1']", nsmgr); Assert.IsNotNull(postNode, "The post node is null"); XmlNode firstPostCategoryNode = doc.SelectSingleNode("bml:blog/bml:posts/bml:post[@id='1']/bml:categories/bml:category", nsmgr); Assert.IsNotNull(firstPostCategoryNode, "Expected a category for the first post"); XmlNode firstPostCommentNode = doc.SelectSingleNode("bml:blog/bml:posts/bml:post[@id='1']/bml:comments/bml:comment", nsmgr); Assert.IsNotNull(firstPostCommentNode, "Expected a comment for the first post"); XmlNode firstPostTrackbackNode = doc.SelectSingleNode("bml:blog/bml:posts/bml:post[@id='1']/bml:trackbacks/bml:trackback", nsmgr); Assert.IsNotNull(firstPostTrackbackNode, "Expected a trackback for the first post"); }
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)); } }
protected void lkbPost_Click(object sender, EventArgs e) { try { Trackback entry = new Trackback(EntryID, txbTitle.Text, HtmlHelper.CheckForUrl(txbUrl.Text), string.Empty, txbBody.Text.Trim().Length > 0 ? txbBody.Text.Trim() : txbTitle.Text, Config.CurrentBlog.TimeZone.Now); if(FeedbackItem.Create(entry, null) > 0) { CommentFilter filter = new CommentFilter(HttpContext.Current.Cache); filter.FilterAfterPersist(entry); this.Messages.ShowMessage(Constants.RES_SUCCESSNEW); this.Edit.Visible = false; this.Results.Visible = true; } else { this.Messages.ShowError(Constants.RES_FAILUREEDIT + " There was a baseline problem posting your Trackback."); } } catch(Exception ex) { log.Error(ex.Message, ex); this.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); }
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); }