public async Task <IActionResult> DeleteReview(Guid reviewId) { using (RestaurantReviewsUnitOfWork uow = new RestaurantReviewsUnitOfWork(dbPath)) { var _results = await uow.DeleteRestaurantReviewAsync(reviewId); if (_results.Successful) { return(Ok()); } else { return(NotFound()); } } }
public async Task DeleteRestaurantReviewAsyncTests() { RestaurantAddress address1 = new RestaurantAddress() { streetAddress = "100 Main St", addrLine2 = string.Empty, city = "Pittsburgh", state = "PA", zipcode = "15108" }; Restaurant restaurant1 = new Restaurant() { name = "Restaurant 1", address = address1, addressId = address1.id, dateCreated = DateTime.Now, dateModified = DateTime.Now, phoneNumber = "412-444-4444", acceptsReservations = false }; RestaurantReview review1 = new RestaurantReview() { restaurant = restaurant1, restaurantId = restaurant1.id, reviewDate = DateTime.Now, reviewText = "This restaurant served us quickly and the food was great!", userRating = 5, dateCreated = DateTime.Now, dateModified = DateTime.Now, username = "******" }; // Test the 'Happy Path' bool isDeleted = true; repositoryMock.Setup(m => m.DeleteReviewAsync(It.IsAny <Guid>())).ReturnsAsync(isDeleted); using (RestaurantReviewsUnitOfWork uow = new RestaurantReviewsUnitOfWork(repositoryMock.Object)) { var _results = await uow.DeleteRestaurantReviewAsync(review1.id); Assert.IsNotNull(_results); Assert.IsTrue(_results.Results); Assert.IsNull(_results.Exception); } // Test Review NOT FOUND scenario isDeleted = false; repositoryMock.Setup(m => m.DeleteReviewAsync(It.IsAny <Guid>())).ReturnsAsync(isDeleted); using (RestaurantReviewsUnitOfWork uow = new RestaurantReviewsUnitOfWork(repositoryMock.Object)) { var _results = await uow.DeleteRestaurantReviewAsync(review1.id); Assert.IsNotNull(_results); Assert.IsFalse(_results.Results); Assert.IsNull(_results.Exception); Assert.AreEqual(_results.Message, "No matching review found"); } // Test Exception Handling Exception ex = new Exception("Any Exception"); repositoryMock.Setup(m => m.DeleteReviewAsync(It.IsAny <Guid>())).ThrowsAsync(ex); using (RestaurantReviewsUnitOfWork uow = new RestaurantReviewsUnitOfWork(repositoryMock.Object)) { var _results = await uow.DeleteRestaurantReviewAsync(review1.id); Assert.IsNotNull(_results); Assert.IsNotNull(_results.Exception); Assert.IsFalse(_results.Successful); } }