public void CommentPost_CreateNewComment() { DateTime today = DateTime.Now.Date; BlogPost post = new BlogPost("title", "content"); CommentPost comment = new CommentPost("commentAuthor", "commentContent", post.BlogPostId); Assert.IsTrue(comment.Content == "commentContent"); Assert.IsTrue(comment.Author == "commentAuthor"); Assert.IsTrue(comment.PostDate == today); Assert.IsNotNull(comment.CommentPostId); }
public void CreateComment(int? blogId, string author, string content) { if (String.IsNullOrWhiteSpace(author)) throw new ArgumentNullException("Author"); if (String.IsNullOrWhiteSpace(content)) throw new ArgumentNullException("Content"); BlogPost bPost = SafeGetBlogPost(blogId); CommentPost cPost = new CommentPost(author, content, bPost.BlogPostId); bPost.Comments.Add(cPost); _context.SaveChanges(); Global.Logger.LogMessage("A new comment has been added to blog post " + bPost.Title); }