public void UpdateEntityAsyncTest_WithCommentIdAndCommentRequestWhenCommentWasNotUpdated_ReturnsResponseException() { var commentRequest = CommentHelper.CreateCommentRequest(null); var comment = _mapper.Map <CommentRequest, Comment>(commentRequest); _mockRepository.Setup(repo => repo.Update(comment)).ReturnsAsync(false); _mockMapper.Setup(m => m.Map <CommentRequest, Comment>(commentRequest)).Returns(comment); var exception = Assert.ThrowsAsync <ResponseException>(() => _commentService.UpdateEntityAsync(comment.Id, commentRequest)); Assert.Equal("comment did not update", exception.Result.Message); }
public void CreateEntityAsyncTest_WithCommentRequestWithContentLengthMoreThan200Symbols_ReturnsBadRequestException() { var commentRequest = CommentHelper.CreateCommentRequest(null); var comment = _mapper.Map <CommentRequest, Comment>(commentRequest); _mockRepository.Setup(repo => repo.Add(comment)); _mockMapper.Setup(m => m.Map <CommentRequest, Comment>(commentRequest)).Returns(comment); commentRequest.Content = new string('$', 352); var exception = Assert.ThrowsAsync <BadRequestException>(() => _commentService.CreateEntityAsync(commentRequest)); Assert.Equal("comments bad content length", exception.Result.Message); }
public void UpdateEntityAsyncTest_WithCommentIdAndCommentRequestWithContentLengthMoreThan200Symbols_ReturnsBadRequestException() { var commentRequest = CommentHelper.CreateCommentRequest(null); commentRequest.Content = new string('4', 234); var comment = _mapper.Map <CommentRequest, Comment>(commentRequest); _mockRepository.Setup(repo => repo.Update(comment)).ReturnsAsync(false); var exception = Assert.ThrowsAsync <BadRequestException>(() => _commentService.UpdateEntityAsync(comment.Id, commentRequest)); Assert.Equal("comment has more than 200 symbols content length", exception.Result.Message); }
public void CreateEntityAsyncTest_WithCommentRequest_ReturnsCommentObject() { var commentRequest = CommentHelper.CreateCommentRequest(null); var comment = _mapper.Map <CommentRequest, Comment>(commentRequest); _mockRepository.Setup(repo => repo.Add(comment)); _mockMapper.Setup(m => m.Map <CommentRequest, Comment>(commentRequest)).Returns(comment); var result = _commentService.CreateEntityAsync(commentRequest).Result; Assert.Equal(comment.Id, result.Id); Assert.Equal(comment.ArticleId, result.ArticleId); Assert.Equal(comment.Content, result.Content); Assert.Equal(comment.UserName, result.UserName); Assert.Equal(comment.CreatedDate, result.CreatedDate); }