// GET: Restaurant public ActionResult Index(string SearchString, string sort) { List <Restaurant> allRestaurants = (List <Restaurant>)LibHelper.ShowAllRestaurants(); ViewBag.SearchString = SearchString; if (!String.IsNullOrEmpty(SearchString)) { return(View(sorter.SearchRestaurantByName(SearchString, allRestaurants))); } ViewBag.Top3 = sort == "Top3Rating" ? "sortTop3" : "Top3Rating"; ViewBag.SortByRating = sort == "RatingsDescending" ? "ByRatings" : "RatingsDescending"; ViewBag.SortByName = sort == "NamesAscending" ? "ByNames" : "NamesAscending"; if (sort == "Top3Rating") { return(View(sorter.SortByRating(3, allRestaurants))); } if (sort == "RatingsDescending") { return(View(sorter.SortByRating(allRestaurants))); } if (sort == "NamesAscending") { return(View(sorter.SortByNameAscending(allRestaurants))); } else { return(View(LibHelper.ShowAllRestaurants())); } }
public void SortByRating_Test() { actualList = new List <Restaurant>(); SortLogic sort = new SortLogic(); actualList.Add(restaurant1); actualList.Add(restaurant2); actualList.Add(restaurant3); actualList.Add(restaurant4); Restaurant actual = actualList[3]; List <Restaurant> expectedList /* = new List<Restaurant>(); * expectedList*/= (List <Restaurant>)sort.SortByRating(3, actualList); Restaurant expected = expectedList[0]; Assert.AreEqual(actual, expected, expected.CustomerRating + " " + actual.CustomerRating); }