public void APostWithMultipleComments_OnlyReturnsOnePost()
        {
            Initialize(true);
            using (var repository = new NHibernateBlogService())
            {
                var post = DummyLivePost();

                for (int i = 0; i < 5; i++)
                {
                    var comment = new Comment()
                    {
                        Name="tetst",
                        Content="Comment2"
                    };

                    post.Comments.Add(comment);

                    repository.Save(comment);
                }

                repository.Save(post);

            }
            using (var repository = new NHibernateBlogService())
            {
                Assert.AreEqual(1, repository.GetPublishedPosts().Count);
            }
        }
Exemple #2
0
        public void Comment_Has_Content()
        {
            var comment = new Comment();

            comment.Content = "Dummy Content";

            Assert.AreEqual("Dummy Content", comment.Content);
        }
Exemple #3
0
        public void Comment_Has_Email()
        {
            var comment = new Comment();

            comment.Email = "*****@*****.**";

            Assert.AreEqual("*****@*****.**", comment.Email);
        }
Exemple #4
0
        public void Comment_Has_Id()
        {
            var comment = new Comment();

            comment.Id = 1;

            Assert.AreEqual(1, comment.Id);
        }
Exemple #5
0
        public void Can_Add_Comments_To_Post()
        {
            var post = new Post();

            var comment = new Comment();

            post.AddComment(comment);

            Assert.AreEqual(comment.Post, post);

            Assert.AreEqual(post.Comments.Count, 1);
        }
Exemple #6
0
        public static string GetCommentDescriptionString(this HtmlHelper helper, Comment comment)
        {
            if (string.IsNullOrEmpty(comment.Website) && string.IsNullOrEmpty(comment.Email))
            {
                return String.Format("Posted by {0} on {1:dd MMMM yyyy h:mm tt}", comment.Name, comment.DateCreated);
            }
            else if (!string.IsNullOrEmpty(comment.Website) && string.IsNullOrEmpty(comment.Email))
            {
                return String.Format("Posted by <a href=\"{2}\">{0}</a> on {1:dd MMMM yyyy h:mm tt}", comment.Name, comment.DateCreated, comment.Website);

            }
            else if (string.IsNullOrEmpty(comment.Website) && !string.IsNullOrEmpty(comment.Email))
            {
                return String.Format("Posted by <a href=\"mailto:{2}\">{0}</a> on {1:dd MMMM yyyy h:mm tt}", comment.Name, comment.DateCreated, comment.Email);
            }
            else
            {
                return String.Format("Posted by <a href=\"mailto:{2}\">{0}</a> (<a href=\"{3}\">{3}</a>) on {1:dd MMMM yyyy h:mm tt}", comment.Name, comment.DateCreated, comment.Email, comment.Website);
            }
        }
Exemple #7
0
        public virtual ActionResult AddComment(int postId, Comment comment)
        {
            try
            {
                using (var repository = ObjectFactory.GetInstance<IBlogService>())
                {
                    var post = repository.GetPostById(postId);

                    repository.Save(comment);
                    post.Comments.Add(comment);
                    repository.Save(post);
                }

            }
            catch (InvalidOperationException ex)
            {
                TempData["Name"] = comment.Name;
                TempData["Content"] = comment.Content;
                TempData["Website"] = comment.Website;
                TempData["CommentError"] = comment.RuleViolations;
            }
            return RedirectToAction(Actions.Post(postId));
        }
        public void Can_Associate_Posts_And_Comments()
        {
            Initialize(true);

            using (var repository = new NHibernateBlogService())
            {
                var post = DummyLivePost();

                var comment = new Comment() { Name = "test", Content = "Test" };

                post.Comments.Add(comment);

                repository.Save(post);
                repository.Save(comment);

                Assert.AreEqual(1, post.Comments.Count);
            }
            using (var repository = new NHibernateBlogService())
            {
                var post = repository.GetPosts().First();

                Assert.AreEqual(1, post.Comments.Count);
            }
        }
Exemple #9
0
 public PostComment(int postId, Comment comment)
 {
     PostId = postId;
     Comment = comment;
 }
        public void Can_Get_Comments_By_Post_Id_Paged_Accuracy_Check()
        {
            Initialize(true);

            using (var repository = new NHibernateBlogService())
            {
                var post = DummyLivePost();
                for (int i = 0; i < 21; i++)
                {
                    var comment = new Comment() { Name = String.Format("test{0}", i), Content = String.Format("{0}Test", i) };

                    post.Comments.Add(comment);

                    repository.Save(comment);

                }

                repository.Save(post);

                Assert.AreEqual(10, repository.GetCommentsByPostPaged(post.Id, 10, 1).Count);
                Assert.AreEqual(10, repository.GetCommentsByPostPaged(post.Id, 10, 2).Count);
                Assert.AreEqual(1, repository.GetCommentsByPostPaged(post.Id, 10, 3).Count);
            }
        }
        public void Can_Get_Comments_By_Post_Id()
        {
            Initialize(true);

            using (var repository = new NHibernateBlogService())
            {
                var post = DummyLivePost();

                var comment = new Comment() { Name = "test", Content = "Test" };

                post.Comments.Add(comment);

                repository.Save(post);
                repository.Save(comment);

                var retrievedComment = repository.GetCommentsByPost(post.Id).First();

                Assert.AreEqual(comment, retrievedComment);
            }
        }
        public void Can_Get_Comments_By_Id()
        {
            Initialize(true);

            using (var repository = new NHibernateBlogService())
            {
                var comment = new Comment() { Name = "test", Content = "test" };

                repository.Save(comment);

                var retrievedComment = repository.GetCommentById(comment.Id);

                Assert.AreEqual(comment, retrievedComment);
            }
        }
Exemple #13
0
        public void Comment_Implements_IValidated()
        {
            var comment = new Comment();

            IValidated test = comment as IValidated;

            Assert.IsNotNull(test);
        }
        public void Will_Fail_Saving_An_Invalid_Comment()
        {
            Initialize(true);

            using (var repository = new NHibernateBlogService())
            {
                var comment = new Comment();

                Assert.IsFalse(comment.IsValid);

                repository.Save(comment);
            }
        }
        public void Can_Save_Comment()
        {
            Initialize(true);

            using (var repository = new NHibernateBlogService())
            {
                var comment = new Comment() { Name = "Test Comment", Content = "Test Content" };

                repository.Save(comment);
            }
        }
Exemple #16
0
 public virtual void RemoveComment(Comment comment)
 {
     Comments.Remove(comment);
     comment.SetPost(null);
 }
 public void Save(Comment comment)
 {
     if (!comment.IsValid)
     {
         var errorParser = new StringBuilder();
         comment.RuleViolations.ToList().ForEach(vio =>
         {
             errorParser.AppendLine(String.Format("- {0}: {1}", vio.Property, vio.Violation));
         });
         throw new InvalidOperationException(String.Format("Cannot save an invalid comment.{0}{0} Current Violations: {0}{1}", Environment.NewLine, errorParser));
     }
     save(comment);
 }
 public void Delete(Comment comment)
 {
     _session.Delete(comment);
 }
Exemple #19
0
        public void Comment_Class_Exists()
        {
            var comment = new Comment();

            Assert.IsNotNull(comment);
        }
Exemple #20
0
        public void Post_Comments_Can_Be_Removed()
        {
            var post = new Post();

            var comment = new Comment() { Name = "test", Content = "test" };

            post.AddComment(comment);

            Assert.AreEqual(1, post.Comments.Count);
            Assert.AreEqual(post, comment.Post);

            post.RemoveComment(comment);

            Assert.AreEqual(0, post.Comments.Count);
            Assert.AreEqual(null, comment.Post);
        }
Exemple #21
0
        public void DateCreated_Should_Be_Set_On_Construction()
        {
            var comment = new Comment();

            Assert.IsTrue(comment.DateCreated > DateTime.Now.AddSeconds(-2), String.Format("DateCreated: {0}, Actual (less 2 seconds): {1}", comment.DateCreated, DateTime.Now.AddSeconds(-2)));
        }
        public void Can_Retrieve_Saved_Comment_And_It_Is_Correct()
        {
            Initialize(true);

            using (var repository = new NHibernateBlogService())
            {
                var comment = new Comment() { Name = "Test Comment", Content = "Test Content" };

                repository.Save(comment);

                var retrievedComment = repository.GetComments().First();

                Assert.AreEqual(comment, retrievedComment);
            }
        }
Exemple #23
0
        public void Comment_Has_Name()
        {
            var comment = new Comment();

            comment.Name = "Name";

            Assert.AreEqual("Name", comment.Name);
        }
Exemple #24
0
        public void Comment_Has_Post_Associated_With_It()
        {
            var comment = new Comment();

            var post = new Post();

            post.AddComment(comment);

            Assert.AreEqual(post, comment.Post);
        }
        public void Comments_Are_Ordered_By_Date_Descending()
        {
            Initialize(true);

            using (var repository = new NHibernateBlogService())
            {
                var comments = new List<Comment>();
                for (int i = 0; i < 10; i++)
                {
                    var comment = new Comment() { Name = "test", Content = "Test" };

                    comments.Add(comment);

                    Thread.Sleep(1);
                }

                comments.Reverse();
                comments.ForEach(x => repository.Save(x));

                Assert.IsTrue(comments.First().DateCreated > comments.Last().DateCreated);
            }

            using (var repository = new NHibernateBlogService())
            {
                var loadedComments = repository.GetComments();

                Assert.IsFalse(loadedComments.First().DateCreated > loadedComments.Last().DateCreated);
            }
        }
        public void Can_Delete_Comment()
        {
            Initialize(true);

            using (var repository = new NHibernateBlogService())
            {
                var comment = new Comment() { Name = "test", Content = "Test" };

                repository.Save(comment);

                Assert.AreEqual(1, repository.GetComments().Count);

                repository.Delete(comment);

                Assert.AreEqual(0, repository.GetComments().Count);
            }
        }
Exemple #27
0
 public virtual void AddComment(Comment comment)
 {
     Comments.Add(comment);
     comment.SetPost(this);
 }
Exemple #28
0
        public void Comment_Has_Website()
        {
            var comment = new Comment();

            comment.Website = "http://test.com";

            Assert.AreEqual("http://test.com", comment.Website);
        }