public void Process(BlogMLPost postml) { Log.DebugFormat("Fetching anonymous comments for PostID {0}", postml.ID); using (var query = new OxiteReader("SELECT * FROM oxite_CommentAnonymous A, oxite_Comment B WHERE A.CommentID = B.CommentID AND PostID='" + postml.ID + "'")) { var comments = query.Execute(); foreach (var comment in comments) { var commentml = new BlogMLComment { ID = comment.CommentID.ToString(), DateCreated = comment.CreatedDate, DateModified = comment.ModifiedDate, Approved = comment.State == (int)RecordStates.Normal, UserName = comment.Name, UserUrl = comment.Url, UserEMail = comment.Email, Content = new BlogMLContent { ContentType = ContentTypes.Html, Text = comment.Body } }; postml.Comments.Add(commentml); } } Log.DebugFormat("Finished adding anonymous comments."); }
public static BlogMLComment CreateCommentInstance(string id, string title, string url, string content, string email, string userName, bool approved, DateTime dateCreated, DateTime dateModified) { BlogMLComment comment = new BlogMLComment(); comment.ID = id; comment.Title = title; comment.UserUrl = url; comment.UserEMail = email; comment.UserName = userName; comment.Approved = approved; comment.Content = new BlogMLContent(); comment.Content.Text = content; comment.DateCreated = dateCreated; comment.DateModified = dateModified; return comment; }
public void Add(BlogMLComment value) { base.Add(value); }
public void Import_WithBlogPostHavingComments_CreatesCommentUsingPostId() { // arrange var blog = new BlogMLBlog(); var post = new BlogMLPost(); var comment = new BlogMLComment(); post.Comments.Add(comment); blog.Posts.Add(post); var repository = new Mock<IBlogImportRepository>(); repository.Setup(r => r.CreateBlogPost(blog, post)).Returns("98053"); bool commentCreated = false; repository.Setup(r => r.CreateComment(comment, "98053")).Callback(() => commentCreated = true); var service = new BlogImportService(repository.Object); // act service.Import(blog); // assert Assert.IsTrue(commentCreated); }
/// <summary> /// Loads the comment from data reader. /// </summary> /// <param name="reader">The reader.</param> /// <returns></returns> public static BlogMLComment LoadCommentFromDataReader(IDataReader reader) { FeedbackItem feedbackItem = DataHelper.LoadFeedbackItem(reader); BlogMLComment comment = new BlogMLComment(); comment.ID = feedbackItem.Id.ToString(CultureInfo.InvariantCulture); comment.Title = feedbackItem.Title; comment.Approved = feedbackItem.Approved; comment.Content.Text = feedbackItem.Body; comment.DateCreated = feedbackItem.DateCreated; comment.DateModified = feedbackItem.DateModified; comment.UserEMail = feedbackItem.Email; comment.UserName = feedbackItem.Author; if (feedbackItem.SourceUrl != null) comment.UserUrl = feedbackItem.SourceUrl.ToString(); return comment; }
public void CreateComment(BlogMLComment comment, string newPostId) { var newComment = Mapper.ConvertComment(comment, newPostId); CommentService.Create(newComment, false /*runfilters*/); }
private void WritePostComment(BlogMLComment bmlComment) { string commentId = this.conversionStrategy.GetConvertedId(IdScopes.Comments, bmlComment.ID); string userName = string.IsNullOrEmpty(bmlComment.UserName) ? "Anonymous" : bmlComment.UserName; WriteComment(commentId, bmlComment.Title, ContentTypes.Text, bmlComment.DateCreated, bmlComment.DateModified, bmlComment.Approved, userName, bmlComment.UserEMail, bmlComment.UserUrl, bmlComment.Content.Text, ContentTypes.Text); }
public void ConvertComment_WithInvalidUserUrl_IgnoresUrl() { // arrange var comment = new BlogMLComment { UserUrl= "not-valid-url" }; var mapper = new BlogMLImportMapper(); // act var convertComment = mapper.ConvertComment(comment, "123"); // assert Assert.AreEqual(null, convertComment.SourceUrl); }
public void ConvertComment_WithUnapprovedComment_SetsFeedbackToTrash() { // arrange var comment = new BlogMLComment { UserUrl = "not-valid-url", Approved = false}; var mapper = new BlogMLImportMapper(); // act var convertComment = mapper.ConvertComment(comment, "123"); // assert Assert.IsFalse(convertComment.Approved); Assert.AreEqual(FeedbackStatusFlag.NeedsModeration, convertComment.Status); }
public void ConvertComment_ReturnsFeedbackItemAsComment() { // arrange var comment = new BlogMLComment { UserUrl = "not-valid-url" }; var mapper = new BlogMLImportMapper(); // act var convertComment = mapper.ConvertComment(comment, "123"); // assert Assert.AreEqual(FeedbackType.Comment, convertComment.FeedbackType); }
public FeedbackItem ConvertComment(BlogMLComment comment, string parentPostId) { var feedback = new FeedbackItem(FeedbackType.Comment) { EntryId = int.Parse(parentPostId, CultureInfo.InvariantCulture), Title = comment.Title ?? string.Empty, DateCreated = comment.DateCreated, DateModified = comment.DateModified, Body = comment.Content.UncodedText ?? string.Empty, Approved = comment.Approved, Author = comment.UserName ?? string.Empty, Email = comment.UserEMail, SourceUrl = !String.IsNullOrEmpty(comment.UserUrl) ? ConvertUri(comment.UserUrl) : null }; if(!feedback.Approved) { // Have to assume it needs moderation since that's what it most likely means in other blog systems; feedback.Status = FeedbackStatusFlag.NeedsModeration; } return feedback; }
/// <summary> /// Creates a comment in the system. /// </summary> /// <param name="bmlComment"></param> /// <param name="newPostId"></param> public override void CreatePostComment(BlogMLComment bmlComment, string newPostId) { FeedbackItem newComment = new FeedbackItem(FeedbackType.Comment); newComment.BlogId = Config.CurrentBlog.Id; newComment.EntryId = int.Parse(newPostId); newComment.Title = bmlComment.Title ?? string.Empty; newComment.DateCreated = bmlComment.DateCreated; newComment.DateModified = bmlComment.DateModified; newComment.Body = StringHelper.ReturnCheckForNull(bmlComment.Content.UncodedText); newComment.Approved = bmlComment.Approved; newComment.Author = StringHelper.ReturnCheckForNull(bmlComment.UserName); newComment.Email = bmlComment.UserEMail; if (!string.IsNullOrEmpty(bmlComment.UserUrl)) { newComment.SourceUrl = new Uri(bmlComment.UserUrl); } FeedbackItem.Create(newComment, null); }
public void Write_WithBlogContainingPostsWithComments_WritesPostCommentsToWriter() { // arrange var stringWriter = new StringWriter(); var xmlWriter = new XmlTextWriter(stringWriter) {Formatting = Formatting.Indented}; var source = new Mock<IBlogMLSource>(); var dateTime = DateTime.ParseExact("20090123", "yyyyMMdd", CultureInfo.InvariantCulture); var blog = new BlogMLBlog { Title = "Subtext Blog", RootUrl = "http://subtextproject.com/", SubTitle = "A test blog", DateCreated = dateTime }; source.Setup(s => s.GetBlog()).Returns(blog); var post = new BlogMLPost { Title = "This is a blog post" }; var posts = new List<BlogMLPost> { post }; var comment = new BlogMLComment {Title = "Test Comment Title", Content = {Text = "<p>Comment Body</p>"}}; post.Comments.Add(comment); source.Setup(s => s.GetBlogPosts(false /*embedAttachments*/)).Returns(posts); var writer = new BlogMLWriter(source.Object, false /*embedAttachments*/); // act ((IBlogMLWriter)writer).Write(xmlWriter); // assert string output = stringWriter.ToString(); Assert.Contains(output, @"<title type=""text""><![CDATA[Test Comment Title]]></title>"); Assert.Contains(output, @"<content type=""text""><![CDATA[<p>Comment Body</p>]]></content>"); }
/// <summary> /// Creates a comment in the system. /// </summary> /// <param name="bmlComment"></param> public abstract void CreatePostComment(BlogMLComment bmlComment, string newPostId);