public void GetEntityAsync_WithNonexistentCommentId_ReturnsNotFoundException() { var comment = CommentHelper.GetRandomTestComments(1).First(); _mockRepository.Setup(repo => repo.Find(comment.Id)); var exception = Assert.ThrowsAsync <NotFoundException>(() => _commentService.GetEntityAsync(comment.Id)); Assert.Equal("not found comment", exception.Result.Message); }
public void DeleteEntityAsyncTest_WithNonexistentCommentId_ReturnsNotFoundException() { var commentId = Guid.NewGuid(); _mockRepository.Setup(repo => repo.GetAll()).ReturnsAsync(CommentHelper.GetRandomTestComments(10)); _mockRepository.Setup(m => m.Remove(commentId)).ReturnsAsync(true); var exception = Assert.ThrowsAsync <NotFoundException>(() => _commentService.DeleteEntityAsync(commentId)); Assert.Equal("there is no comment with such id", exception.Result.Message); }
public void DeleteEntityAsyncTest_WithCommentId_ReturnsBooleanValue() { var comments = CommentHelper.GetRandomTestComments(10); var commentId = comments.First().Id; _mockRepository.Setup(repo => repo.GetAll()).ReturnsAsync(comments); _mockRepository.Setup(m => m.Remove(commentId)).ReturnsAsync(true); var result = _commentService.DeleteEntityAsync(commentId).Result; Assert.True(result); }
public void GetEntityAsyncTest_WithNonexistentCommentId_ReturnsNotFoundException() { var comment = CommentHelper.GetRandomTestComments(1).First(); _mockRepository.Setup(repo => repo.Find(comment.Id)).ReturnsAsync(comment); var result = _commentService.GetEntityAsync(comment.Id).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); }
public void GetEntityAsyncTest_WithCommentId_ReturnsCommentObject() { var comments = CommentHelper.GetRandomTestComments(10); _mockRepository.Setup(repo => repo.GetAll()).ReturnsAsync(comments); var result = _commentService.GetEntitiesAsync().Result; Assert.Contains(comments, comment => result.Any(a => a.UserName == comment.UserName && a.Content == comment.Content && a.CreatedDate == comment.CreatedDate && a.Id == comment.Id && a.ArticleId == comment.ArticleId )); }
public void GetCommentsByArticleIdTest_WithArticleId_ReturnsListOfCommentsObjects() { var comments = CommentHelper.GetRandomTestComments(10); var articleId = Guid.NewGuid(); for (int i = 0; i < comments.Count / 2; i++) { comments[i].ArticleId = articleId; } _mockRepository.Setup(repo => repo.GetAll()).ReturnsAsync(comments); var expected = comments.GetRange(0, comments.Count / 2); var result = _commentService.GetCommentsByArticleId(articleId).Result; Assert.Contains(expected, comment => result.Any(a => a.UserName == comment.UserName && a.Content == comment.Content && a.CreatedDate == comment.CreatedDate && a.Id == comment.Id && a.ArticleId == comment.ArticleId )); }