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); }
public void Author_FailModelValidationIfAuthorIsMissing() { var sut = new Comment { Author = null, Email = EmailValue, Content = ContentValue }; int errorCount = Mother.ValidateModel(sut).Count; Assert.AreEqual(1, errorCount); }
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); }
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); }
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); }
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(); }
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); }
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"); }