Beispiel #1
0
        public void TestDisplayRestaurantsContaining()
        {
            // Act
            string     sPartName = "Don";
            Restaurant test1     = new Restaurant("Arbys", "2010 Somwhere", 4.4m);
            Restaurant test2     = new Restaurant("Taco Bell", "2010 Somwhere", 2.4m);
            Restaurant test3     = new Restaurant("Burger King", "2010 Somwhere", 3.1m);
            Restaurant test4     = new Restaurant("McDonalds", "2010 Somwhere", 5.0m);
            Restaurant test5     = new Restaurant("Fazolis", "2010 Somwhere", 1.4m);
            Restaurant test6     = new Restaurant("Steak n Shake", "2010 Somwhere", 3.2m);
            Restaurant test7     = new Restaurant("Subway", "2010 Somwhere", 4.8m);
            Restaurant test8     = new Restaurant("Dunkin Donuts", "2010 Somwhere", 4.1m);
            Restaurant test9     = new Restaurant("KFC", "2010 Somwhere", 0.4m);
            Restaurant test10    = new Restaurant("Sonic", "2010 Somwhere", 1.1m);

            List <Restaurant> lsExpectedList = new List <Restaurant> {
                test4, test8
            };

            // Arrange
            List <Restaurant> lsTestList = new List <Restaurant> {
                test1, test2, test3,
                test4, test5, test6, test7, test8, test9, test10
            };
            List <Restaurant> lsActualList = RestaurantSearch.DisplayRestaurantsContaining(lsTestList,
                                                                                           sPartName);

            // Assert
            CollectionAssert.AreEqual(lsExpectedList, lsActualList);
        }
        public IEnumerable <RestaurantDto> Execute(RestaurantSearch search)
        {
            var query = _context.Restaurants.AsQueryable();

            if (!string.IsNullOrEmpty(search.Name) || !string.IsNullOrWhiteSpace(search.Name))
            {
                query = query.Where(restaurant => restaurant.Name.ToLower().Contains(search.Name.ToLower()));
            }

            var restaurants = query.Select(r => _mapper.Map <RestaurantDto>(r)).ToList();


            foreach (var res in restaurants)
            {
                var rating = _context.Ratings.Where(r => r.RestaurantId == res.Id).Select(r => r.Rating);

                if (rating.Sum() != 0)
                {
                    res.Rating = rating.Average();
                }
                else
                {
                    res.Rating = 0;
                }
            }


            return(restaurants);
        }
Beispiel #3
0
        public void TestDisplayRestaurantsContaining()
        {
            // Arrange
            string     sPartName = "Don";
            Restaurant test1     = new Restaurant("Arbys", "E Fletcher Ave Tampa Florida 33612", 4.4m);
            Restaurant test2     = new Restaurant("Taco Bell", "5318 E Fowler Ave Tampa Florida 33617", 2.4m);
            Restaurant test3     = new Restaurant("Burger King", "5301 E Fowler Ave Temple Terrace Florida 33617", 3.1m);
            Restaurant test4     = new Restaurant("McDonalds", "11707 N 56th St Tampa Florida 33617", 5.0m);
            Restaurant test5     = new Restaurant("Fazolis", "238 W Alexander St Plant City Florida 33563", 1.4m);
            Restaurant test6     = new Restaurant("Steak n Shake", "1450 E Fowler Ave Temple Terrace Florida 33617", 3.2m);
            Restaurant test7     = new Restaurant("Subway", "4202 E Fowler Ave Tampa Florida 33620", 4.8m);
            Restaurant test8     = new Restaurant("Dunkin Donuts", "5610 E Fowler Ave Temple Terrace Florida 33617", 4.1m);
            Restaurant test9     = new Restaurant("KFC", "2212 E Fowler Ave Tampa Florida 33612", 0.4m);
            Restaurant test10    = new Restaurant("Sonic", "1915 E Fowler Ave Tampa Florida 33612", 1.1m);

            List <Restaurant> lsExpectedList = new List <Restaurant> {
                test4, test8
            };

            // Act
            List <Restaurant> lsTestList = new List <Restaurant> {
                test1, test2, test3,
                test4, test5, test6, test7, test8, test9, test10
            };
            List <Restaurant> lsActualList = RestaurantSearch.DisplayRestaurantsContaining(sPartName, lsTestList);

            // Assert
            CollectionAssert.AreEqual(lsExpectedList, lsActualList);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="_city"></param>
        /// <returns></returns>
        public RestaurantSearch GetRestaurantsByCity(City _city)
        {
            RestaurantSearch _restaurantSearch = new RestaurantSearch();

            _restaurantSearch.Restaurants = bringlyEntities.tblRestaurants
                                            .Select(r => new Restaurant
            {
                RestaurantImage = r.RestaurantImage,
                RestaurantGuid  = r.RestaurantGuid,
                RestaurantName  = r.RestaurantName,
                CityGuid        = r.CityGuid,
                CityName        = _city.CityName,
                IsFavorite      = false
            }).ToList();

            if (_city.CityGuid != null)
            {
                _restaurantSearch.Restaurants = _restaurantSearch.Restaurants.Where(s => s.CityGuid == _city.CityGuid).ToList();
            }
            UserDomainLogic   userDomainLogic      = new UserDomainLogic();
            List <Restaurant> favouriteRestaurants = userDomainLogic.FavouriteRestaurants();

            _restaurantSearch.CityGuid = _city.CityGuid;
            _restaurantSearch.CityName = _city.CityName;
            List <Guid> restaurentGuid = favouriteRestaurants.Select(c => c.RestaurantGuid).ToList();

            foreach (Restaurant restaurant in _restaurantSearch.Restaurants)
            {
                if (restaurentGuid.Contains(restaurant.RestaurantGuid))
                {
                    restaurant.IsFavorite = true;
                }
            }
            return(_restaurantSearch);
        }
Beispiel #5
0
        //Search
        public ActionResult Search(string Name)
        {
            var bl = new Dubuche.BL.RestaurantCRUD();

            List <Restaurant> newRestList = new List <Restaurant>();

            newRestList = bl.GetAllRestaurants();
            return(View(RestaurantSearch.Lookup(newRestList, Name)));
        }
 public IActionResult Get([FromQuery] RestaurantSearch search, [FromServices] IGetRestaurantsQuery query)
 {
     return(Ok(query.Execute(search)));
 }