public void GetRestaurantsByCity()
        {
            // Arrange
            var restaurantsByCityDto = new RestaurantsByCityDto
            {
                City    = "Niles",
                Country = "USA",
                State   = "OH"
            };
            var seededRestaurants = DataSeeder.Restaurants.Where(r =>
                                                                 r.City == restaurantsByCityDto.City &&
                                                                 r.Country == restaurantsByCityDto.Country &&
                                                                 r.State == restaurantsByCityDto.State
                                                                 );

            Mock.Get(_repositoryWrapper.Restaurant).Setup(x => (x.GetRestaurantsByCity(restaurantsByCityDto.City, restaurantsByCityDto.State, restaurantsByCityDto.Country))).ReturnsAsync(seededRestaurants);
            var controller = new RestaurantReviewsController(_loggerManager, _mapper, _repositoryWrapper);
            // Act
            var actionResult = controller.GetRestaurantsByCity(restaurantsByCityDto).Result;
            // Assert
            var okObjectResult = actionResult as OkObjectResult;

            Assert.IsNotNull(okObjectResult);
            var restaurants = okObjectResult.Value as IEnumerable <Restaurant>;

            Assert.IsTrue(restaurants.Count() == seededRestaurants.Count());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetRestaurantsByCity([FromQuery] RestaurantsByCityDto restaurantsByCityDto)
        {
            try
            {
                var restaurants = await _repositoryWrapper.Restaurant.GetRestaurantsByCity(restaurantsByCityDto.City, restaurantsByCityDto.State, restaurantsByCityDto.Country);

                _loggerManager.LogInfo($"Returned { restaurants.Count() } restaurants for RestaurantsByCityDto: {restaurantsByCityDto}");
                return(Ok(restaurants));
            }
            catch (Exception ex)
            {
                _loggerManager.LogError($"Something went wrong inside GetRestaurantsByCity action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }