public async Task GetReviewWithReviewId_ShouldOk() { var testReviewDto = new ReviewDto { reviewId = 1, productId = 1, userId = 1, userName = "******", reviewRating = 5, reviewContent = "Great Product. You can believe me, I'm not a bot.", hidden = false }; var mock = new Mock <IReviewService>(MockBehavior.Strict); mock.Setup(repo => repo.GetReviewAsync(1)).ReturnsAsync(testReviewDto).Verifiable(); var controller = new ReviewController(mock.Object); var result = await controller.GetReviewAsync(1); var controllerResult = result as OkObjectResult; Assert.IsNotNull(controllerResult); Assert.IsNotNull(controllerResult); var reviewsResult = controllerResult.Value as ReviewDto; Assert.IsNotNull(reviewsResult); Assert.AreEqual(testReviewDto.productId, reviewsResult.productId); Assert.AreEqual(testReviewDto.userId, reviewsResult.userId); Assert.AreEqual(testReviewDto.userName, reviewsResult.userName); Assert.AreEqual(testReviewDto.reviewRating, reviewsResult.reviewRating); Assert.AreEqual(testReviewDto.reviewContent, reviewsResult.reviewContent); mock.Verify(); mock.Verify(repo => repo.GetReviewAsync(1), Times.Once); }
public async Task GetReviewWithReviewId_ShouldNotFound() { var mock = new Mock <IReviewService>(MockBehavior.Strict); mock.Setup(repo => repo.GetReviewAsync(10)).ReturnsAsync(null as ReviewDto).Verifiable(); var controller = new ReviewController(mock.Object); var result = await controller.GetReviewAsync(10); var controllerResult = result as NotFoundResult; Assert.IsNotNull(controllerResult); mock.Verify(); mock.Verify(repo => repo.GetReviewAsync(10), Times.Once); }