Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        public void Comment_Has_Content()
        {
            var comment = new Comment();

            comment.Content = "Dummy Content";

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

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

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

            comment.Id = 1;

            Assert.AreEqual(1, comment.Id);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 8
0
        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);
            }
        }
Ejemplo n.º 9
0
 public PostComment(int postId, Comment comment)
 {
     PostId = postId;
     Comment = comment;
 }
Ejemplo n.º 10
0
        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);
            }
        }
Ejemplo n.º 11
0
        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);
            }
        }
Ejemplo n.º 12
0
        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);
            }
        }
Ejemplo n.º 13
0
        public void Comment_Implements_IValidated()
        {
            var comment = new Comment();

            IValidated test = comment as IValidated;

            Assert.IsNotNull(test);
        }
Ejemplo n.º 14
0
        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);
            }
        }
Ejemplo n.º 15
0
        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);
            }
        }
Ejemplo n.º 16
0
 public virtual void RemoveComment(Comment comment)
 {
     Comments.Remove(comment);
     comment.SetPost(null);
 }
Ejemplo n.º 17
0
 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);
 }
Ejemplo n.º 18
0
 public void Delete(Comment comment)
 {
     _session.Delete(comment);
 }
Ejemplo n.º 19
0
        public void Comment_Class_Exists()
        {
            var comment = new Comment();

            Assert.IsNotNull(comment);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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)));
        }
Ejemplo n.º 22
0
        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);
            }
        }
Ejemplo n.º 23
0
        public void Comment_Has_Name()
        {
            var comment = new Comment();

            comment.Name = "Name";

            Assert.AreEqual("Name", comment.Name);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 25
0
        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);
            }
        }
Ejemplo n.º 26
0
        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);
            }
        }
Ejemplo n.º 27
0
 public virtual void AddComment(Comment comment)
 {
     Comments.Add(comment);
     comment.SetPost(this);
 }
Ejemplo n.º 28
0
        public void Comment_Has_Website()
        {
            var comment = new Comment();

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

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