public void UpdateComment() { //-- arrange var comment = new Comment { UserId = 1, Body = "old-body", TimeCreated = DateTime.Now }; _repository.AddComment(1, comment); _repository.Save(); comment.Body = "new-body"; //-- act _repository.UpdateComment(comment); _repository.Save(); var actual = _repository.GetComment(1); //-- assert Assert.AreEqual("new-body", actual.Body); //-- cleanup _repository.DeleteComment(comment); _repository.Save(); }
public IActionResult UpdateComment(int userId, int blogId, int postId, int commentId, [FromBody] CommentForUpdateDto comment) { if (!_weblogDataRepository.UserExists(userId) || !_weblogDataRepository.BlogExists(blogId) || !_weblogDataRepository.PostExists(postId)) { return(NotFound()); } var commentFromRepo = _weblogDataRepository.GetComment(commentId); if (commentFromRepo is null) { return(NotFound()); } var emailAddress = comment.Credentials.EmailAddress; var password = comment.Credentials.Password; if (!_weblogDataRepository.Authorized(commentFromRepo.UserId, emailAddress, password)) { return(Unauthorized()); } _mapper.Map(comment, commentFromRepo); _weblogDataRepository.UpdateComment(commentFromRepo); _weblogDataRepository.Save(); return(NoContent()); }