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);
            }
        }
        public void Can_reply_to_post_when_comments_are_enabled()
        {
            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");

                //ensure the comment is added to the post
                Assert.AreEqual(1, post.Comments.Count());
            }
        }
        public void Can_publish_comment_notifications()
        {
            var ws = new InMemWorkspace();
            int numberOfSentNotifications = 0;
            using (var context = GetDomainContext(ws))
            using (var scope = new TransactionScope())
            {
                //register a handler for CommentNotifications, in this test, increase a local variable to
                //hold the number of sent CommentNotifications
                context.MessageBus.RegisterHandler<RepliedToPostEvent>(MessageHandlerType.Synchronous, commentCreated => OnTransactionCommitted.Invoke(() => numberOfSentNotifications++), false);

                
                var post = new Post();
                post.Edit("AOP for dummies", "...");
                post.Publish();
                post.EnableComments();
                //pass the DomainEvent container to the method so we can raise domain events in the current context.
                post.ReplyTo("Roger Alsing", "*****@*****.**", "http://www.rogeralsing.com", "Hi there");

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

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

            //ensure that one comment notification have been processed
            Assert.AreEqual(1, numberOfSentNotifications);

        }
        public void Can_remove_post()
        {
            var ws = new InMemWorkspace();
            using(var context = GetDomainContext(ws))
            {
                
                var post = new Post();
                post.Edit("AOP for dummies", "...");
                post.Publish();

                ws.Add(post);
                ws.ClearUoW();

                Assert.AreEqual(0, ws.GetRemovedEntityCount<Post>());

                post = context.Posts.FindById(0);
                context.Posts.Remove(post);

                Assert.AreEqual(1, ws.GetRemovedEntityCount<Post>());
            }
        }
        public void Can_not_reply_to_post_when_comments_are_disabled()
        {
            var ws = new InMemWorkspace();
            using (var context = GetDomainContext(ws))
            {
                
                var post = new Post();
                post.Edit("AOP for dummies", "...");
                post.Publish();

                Assert.AreEqual(0, post.Comments.Count());
                post.ReplyTo("Roger Alsing", "*****@*****.**", "http://www.rogeralsing.com", "Boom boom pow");
            }
        }