예제 #1
0
        public void Can_publish_approved_comment_notifications()
        {
            var ws = new InMemWorkspace();
            int numberOfSentNotifications = 0;

            using (var context = GetDomainContext(ws))
                using (var scope = new TransactionScope())
                {
                    //register a handler for CommentApprovedNotification, in this test, increase a local variable to
                    //hold the number of sent CommentApprovedNotification
                    context.MessageBus.RegisterHandler <ApprovedCommentEvent>(MessageHandlerType.Synchronous, commentApproved => OnTransactionCommitted.Invoke(() => numberOfSentNotifications++), false);


                    var post = new Post();
                    post.Edit("AOP for dummies", "...");
                    post.Publish();
                    post.EnableComments();
                    Assert.AreEqual(0, post.Comments.Count());

                    post.ReplyTo("Roger Alsing", "*****@*****.**", "http://www.rogeralsing.com", "Hi there");

                    Comment comment = post.Comments.First();

                    comment.Approve();

                    //ensure that no comment approved notifications have been processed yet
                    Assert.AreEqual(0, numberOfSentNotifications);

                    ws.Commit();
                    scope.Complete();
                }

            //ensure that one comment approved notification have been processed
            Assert.AreEqual(1, numberOfSentNotifications);
        }
예제 #2
0
    public void ApproveComment(object sender, CommandEventArgs e)
    {
        if (KMAuthentication.IsUserAdmin(User) == false)
        {
            return;
        }

        int commentId;

        if (Int32.TryParse(e.CommandArgument.ToString(), out commentId) == false)
        {
            return;
        }

        Comment.Approve(commentId);
        this.LoadPostComments();
    }
        public IHttpActionResult Approve(decimal id_post, decimal id_comment)
        {
            if (!Comment.belongsToPost(db, id_comment, id_post))
            {
                return(NotFound());
            }

            Comment comment = Comment.findById(db, id_comment);

            if (comment == null)
            {
                return(NotFound());
            }

            comment.Approve(db);

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #4
0
        public void Can_approve_comment()
        {
            var ws = new InMemWorkspace();

            using (var context = GetDomainContext(ws))
            {
                var post = new Post();
                post.Edit("AOP for dummies", "...");
                post.Publish();
                post.EnableComments();
                Assert.AreEqual(0, post.Comments.Count());

                post.ReplyTo("Roger Alsing", "*****@*****.**", "http://www.rogeralsing.com", "Hi there");

                Comment comment = post.Comments.First();
                comment.Approve();

                Assert.IsTrue(comment.Approved);
            }
        }