public void Get_ExplicitParams_ReturnsList() { IEnumerable <Review> expected = new List <Review> { new Review { Id = 1, UserId = 2, RestaurantId = 3 }, new Review { Id = 1, UserId = 4, RestaurantId = 7 } }; var reviewRepository = new Mock <IReviewRepository>(); DbFilter <Review> actualFilter = null; reviewRepository.Setup(x => x.GetReviewsAsync(3, 2, It.IsAny <DbFilter <Review> >())) .Callback <int, int, DbFilter <Review> >((page, pagesize, filter) => { actualFilter = filter; }) .Returns(Task.FromResult(expected)); var sut = new ReviewsController(reviewRepository.Object); var actual = sut.Get(111, 3, 2).Result; Assert.AreEqual(expected, actual); Assert.IsNotNull(actualFilter); Assert.AreEqual("UserId", actualFilter.Field); Assert.AreEqual(OperatorEnum.Equal, actualFilter.Operator); Assert.AreEqual(111, actualFilter.Value); reviewRepository.VerifyAll(); }
public async Task CheckNoDuplicateReviewIsAllowed() { _output.WriteLine($"EndPointUrl: {_cosmosDBFixture.CosmosDbConfig.EndPointUrl}"); _output.WriteLine($"CollectionName: {_cosmosDBFixture.CosmosDbConfig.CollectionName}"); _output.WriteLine($"DatabaseName: {_cosmosDBFixture.CosmosDbConfig.DatabaseName}"); _output.WriteLine($"AuthorizationKey: {_cosmosDBFixture.CosmosDbConfig.AuthorizationKey}"); var repository = new ReviewRepository(_cosmosDBFixture.CosmosDbConfig); var controller = new ReviewsController(repository); var newReview1 = new ReviewDocument { Id = "review2", Content = "Another review with existing Id" }; var newReview2 = new ReviewDocument { Id = "review3", Content = "This is boring" }; await controller.PostAsync(newReview1); await controller.PostAsync(newReview2); var reviews = await controller.Get(); // We rely on the fact that we already had review2 // and another review in our test data Assert.Equal(3, reviews.Count); }
public void Get_Review() { var controller = new ReviewsController(new ReviewRepositoryMock(), new ClientRepositoryMock()); var result = controller.Get(ReviewRepositoryMock.TestReview.Id); var okResult = result.Should().BeOfType <OkObjectResult>().Subject; var review = okResult.Value.Should().BeAssignableTo <ReviewWithClientDto>().Subject; review.Content.Should().Be(ReviewRepositoryMock.TestReview.Content); }
public void Get_All_Review() { var controller = new ReviewsController(new ReviewRepositoryMock(), new ClientRepositoryMock()); var result = controller.Get(); var okResult = result.Should().BeOfType <OkObjectResult>().Subject; var reviews = okResult.Value.Should().BeAssignableTo <IEnumerable <ReviewWithClientDto> >().Subject; reviews.Count().Should().Be(1); }
public void GetTest_RejectsInValid() { //Arrange var RC = new ReviewsController(connection); //Act var result = RC.Get("HocusPocus"); //Assert Assert.IsType <ObjectResult>(result); }
public void GetTest_ReturnsValid() { //Arrange var RC = new ReviewsController(connection); //Act var result = RC.Get("user1"); //Assert Assert.IsType <OkObjectResult>(result); }
public ActionResult <IEnumerable <int> > List() { var list = new List <ReviewListViewModel>(); //get the list of REviews to display var result = _reviewsController.Get(); if (result.Result.GetType() == typeof(OkObjectResult)) { //If the response was OK, map the result to a ViewModel and set the View URL link var reviews = ((result.Result as OkObjectResult).Value as IEnumerable <Review>); list = reviews.Select(x => x.ToListVm(Url.Action("Get", "Review", new { id = x.ReviewId }))).ToList(); } else { //Error SetResultsMessage("An unknown error occured while trying to get the list of reviews.", true); } return(Json(new { data = list })); }
private void ExecuteAndValidateExpectedOkResponses(int restaurantId, List <Review> expectedResponse, int expectedCuisineCount) { var ctrl = new ReviewsController(MockRepository.Object, MockLogger.Object, MockIdentity.Object); //act var actionResult = ctrl.Get(restaurantId); var contentResult = actionResult as OkNegotiatedContentResult <IEnumerable <API.ViewModels.Review> >; //assert Assert.IsNotNull(contentResult, "Ok-200 status was not returned"); Assert.IsNotNull(contentResult.Content, "No content was returned"); ValidateReviewCollectionResponse(contentResult.Content, expectedResponse, expectedCuisineCount); }
public void GetAllReviewsForRestaurant_InvalidRestaruntId_NotFound() { //arrange var restaurantId = 1; var repoResonse = new List <Domain.Review>(); MockRepository.Setup(m => m.GetReviewsForRestaurant(restaurantId)).Returns(repoResonse); MockIdentity.Setup(m => m.GetRequestingUserId()).Returns(10); var ctrl = new ReviewsController(MockRepository.Object, MockLogger.Object, MockIdentity.Object); //act var actionResult = ctrl.Get(restaurantId); // assert Assert.IsInstanceOfType(actionResult, typeof(NotFoundResult)); }
public void Get_CallsRepository_ReturnsReview() { var expected = new Review { Id = 1, UserId = 2, RestaurantId = 3 }; var reviewRepository = new Mock <IReviewRepository>(); reviewRepository.Setup(x => x.GetReviewAsync(123)).Returns(Task.FromResult <Review>(expected)); var sut = new ReviewsController(reviewRepository.Object); var actual = sut.Get(123).Result; Assert.AreEqual(expected, actual); reviewRepository.VerifyAll(); }
public void GetAllReviewsForRestaurant_DatabaseException_BadData() { //arrange var restaurantId = 1; //arrange MockRepository.Setup(m => m.DoseRestaurentIdExist(restaurantId)) .Returns(true); MockRepository.Setup(m => m.GetReviewsForRestaurant(restaurantId)) .Throws(new Exception()); MockIdentity.Setup(m => m.GetRequestingUserId()).Returns(10); var ctrl = new ReviewsController(MockRepository.Object, MockLogger.Object, MockIdentity.Object); //act var actionResult = ctrl.Get(restaurantId); // assert Assert.IsInstanceOfType(actionResult, typeof(BadRequestResult)); }