Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public void Can_assign_category_to_post()
        {
            var ws = new InMemWorkspace();

            using (var context = GetDomainContext(ws))
            {
                var category = new Category("C#");
                var post     = new Post();
                post.AssignCategory(category);

                Assert.AreEqual(1, post.Categories.Count());
            }
        }
Esempio n. 3
0
        public void Can_assign_category_to_post()
        {
            var ws = new InMemWorkspace();
            using (var context = GetDomainContext(ws))
            {

                var category = new Category("C#");
                var post = new Post();
                post.AssignCategory(category);

                Assert.AreEqual(1, post.Categories.Count());
            }
        }
Esempio n. 4
0
        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");
            }
        }
Esempio n. 5
0
        public void Can_add_new_post()
        {
           
            var ws = new InMemWorkspace();
            using (var context = GetDomainContext(ws))
            {
                var postAboutAOP = new Post();
                postAboutAOP.Edit("AOP for dummies", "...");
                ws.ClearUoW();

                context.Posts.Add(postAboutAOP);

                //should be one inserted item
                Assert.AreEqual(1, ws.GetAddedEntityCount<Post>());
            }
        }
Esempio n. 6
0
        public void Can_edit_post()
        {
            var ws = new InMemWorkspace();

            using (var context = GetDomainContext(ws))
            {
                var          post            = new Post();
                const string expectedSubject = "AOP for dummies";
                const string expectedBody    = "...";

                post.Edit(expectedSubject, expectedBody);

                Assert.AreEqual(expectedSubject, post.Subject);
                Assert.AreEqual(expectedBody, post.Body);
            }
        }
Esempio n. 7
0
        public void Can_add_new_post()
        {
            var ws = new InMemWorkspace();

            using (var context = GetDomainContext(ws))
            {
                var postAboutAOP = new Post();
                postAboutAOP.Edit("AOP for dummies", "...");
                ws.ClearUoW();

                context.Posts.Add(postAboutAOP);

                //should be one inserted item
                Assert.AreEqual(1, ws.GetAddedEntityCount <Post>());
            }
        }
Esempio n. 8
0
        public void Can_find_post_by_id()
        {
            var ws = new InMemWorkspace();

            using (var context = GetDomainContext(ws))
            {
                var postAboutAOP = new Post();
                postAboutAOP.Edit("AOP for dummies", "...");
                ws.Add(postAboutAOP);

                ws.ClearUoW();

                //auto inc id's are not good for tests... get id "0"
                Post foundPost = context.Posts.FindById(0);

                Assert.IsTrue(foundPost != null);
            }
        }
Esempio n. 9
0
        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());
            }
        }
Esempio n. 10
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);
            }
        }
Esempio n. 11
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);
            }
        }
Esempio n. 12
0
        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>());
            }
        }
Esempio n. 13
0
        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());
            }
        }
Esempio n. 14
0
        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>());
            }
        }
Esempio n. 15
0
        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);

        }
Esempio n. 16
0
        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");
            }
        }
Esempio n. 17
0
        public void Can_edit_post()
        {
            var ws = new InMemWorkspace();
            using (var context = GetDomainContext(ws))
            {
                
                var post = new Post();
                const string expectedSubject = "AOP for dummies";
                const string expectedBody = "...";

                post.Edit(expectedSubject, expectedBody);

                Assert.AreEqual(expectedSubject, post.Subject);
                Assert.AreEqual(expectedBody, post.Body);
            }
        }
Esempio n. 18
0
        public void Can_find_post_by_id()
        {
            var ws = new InMemWorkspace();
            using (var context = GetDomainContext(ws))
            {
                
                var postAboutAOP = new Post();
                postAboutAOP.Edit("AOP for dummies", "...");
                ws.Add(postAboutAOP);

                ws.ClearUoW();

                //auto inc id's are not good for tests... get id "0"
                Post foundPost = context.Posts.FindById(0);

                Assert.IsTrue(foundPost != null);
            }
        }