Exemplo n.º 1
0
        public void Author_FailModelValidationIfContentIsAnEmptyString()
        {
            var sut = new Comment { Author = AuthorValue, Email = EmailValue, Content = string.Empty };

            int errorCount = Mother.ValidateModel(sut).Count;

            Assert.AreEqual(1, errorCount);
        }
Exemplo n.º 2
0
        public void Author_FailModelValidationIfAuthorIsMissing()
        {
            var sut = new Comment { Author = null, Email = EmailValue, Content = ContentValue };

            int errorCount = Mother.ValidateModel(sut).Count;

            Assert.AreEqual(1, errorCount);
        }
Exemplo n.º 3
0
        public void Author_GenerateTheCorrectErrorMessageIfContentIsAnEmptyString()
        {
            var sut = new Comment { Author = AuthorValue, Email = EmailValue, Content = null };

            IList<ValidationResult> result = Mother.ValidateModel(sut);
            string errorMessage = result[0].ErrorMessage;

            Assert.AreEqual("A comment is required", errorMessage);
        }
Exemplo n.º 4
0
        public void Author_GenerateTheCorrectErrorMessageIfAuthorIsMissing()
        {
            var sut = new Comment { Author = null, Email = EmailValue, Content = ContentValue };

            IList<ValidationResult> result = Mother.ValidateModel(sut);
            string errorMessage = result[0].ErrorMessage;

            Assert.AreEqual("Author name is required", errorMessage);
        }
Exemplo n.º 5
0
        public void Content_ErrorMessageDisplayedIfCharsOver500()
        {
            var chars71 = new string('a', 501);

            var sut = new Comment { Author = AuthorValue, Email = EmailValue, Content = chars71 };

            IList<ValidationResult> result = Mother.ValidateModel(sut);
            string errorMessage = result[0].ErrorMessage;

            Assert.AreEqual("Max of 500 characters allowed", errorMessage);
        }
Exemplo n.º 6
0
        public void AddCommentToPost(Comment comment, int postId)
        {
            Post post = _dataContext.Posts.SingleOrDefault(p => p.Id == postId);
            comment.CreationTime = DateTime.Now;

            if (post != null)
            {
                post.Comments.Add(comment);
                _dataContext.SetModified(post);
            }
            _dataContext.SaveChanges();
        }
Exemplo n.º 7
0
        public void Email_ErrorMessageDisplayedIfCharsOver70()
        {
            var chars71 = new string('a', 71);

            var sut = new Comment { Author = AuthorValue, Email = chars71, Content = ContentValue };

            IList<ValidationResult> result = Mother.ValidateModel(sut);
            string errorMessage = result[0].ErrorMessage;

            Assert.AreEqual("E-mail address Too Long", errorMessage);
        }
Exemplo n.º 8
0
        public ViewResult LeaveComment(Comment comment)
        {
            comment.CreationTime = DateTime.Now;

            if (ModelState.IsValid)
            {
                PostRepository.AddCommentToPost(comment, comment.PostId);

                MessagingService.Contact = new Contact
                    {
                        Name = comment.Author,
                        Email = comment.Email,
                        Message = comment.Content,
                        Subject = "comment to moderate post id: " + comment.PostId
                    };
                MessagingService.Message();
            }
            else
            {
                return View("_CommentSubmittedFailed");
            }

            return View("_CommentSubmitted");
        }