Пример #1
0
        public ActionResult Sort(string sort)
        {
            var bl         = new Dubuche.BL.RestaurantCRUD();
            var list       = Dubuche.BL.RestaurantCRUD.Casting(bl.GetAllRestaurants());
            var sortedList = list;

            //var sortedList = RestaurantSort.AlphaSorting(Dubuche.BL.RestaurantCRUD.Casting(list));
            //var downSortedList = RestaurantSort.BetaSorting(Dubuche.BL.RestaurantCRUD.Casting(list));
            //var ratedSortedList = RestaurantSort.AvgRatingSort(Dubuche.BL.RestaurantCRUD.Casting(list));
            //var topThreeSorted = RestaurantSort.AvgRatingSort(Dubuche.BL.RestaurantCRUD.Casting(list));

            try
            {
                if (sort == "byName")
                {
                    sortedList = RestaurantSort.AlphaSorting(list);
                }
                else if (sort == "byRating")
                {
                    sortedList = RestaurantSort.AvgRatingSort(list);
                }
                else if (sort == "topThree")
                {
                    sortedList = RestaurantSort.AvgRatingSort(list.Take(3).ToList());
                }
                return(View(sortedList));
            }
            catch
            {
                log = LogManager.GetLogger("mistakes");
                return(RedirectToAction("Index"));
            }
        }
        public void AlphaSortingTest()
        {
            List <Restaurants> restsTests = new List <Restaurants>();            //arrange
            Restaurants        rests      = new Restaurants("def");              //arrange

            restsTests.Add(rests);                                               //arrange
            List <Restaurants> expected = new List <Restaurants>();              //arrange

            Restaurants rests2 = new Restaurants("abc");                         //arrange

            restsTests.Add(rests2);                                              //arrange

            Restaurants rests3 = new Restaurants("abc");                         //arrange

            expected.Add(rests3);                                                //arrange

            Restaurants rests4 = new Restaurants("def");                         //arrange

            expected.Add(rests4);                                                //arrange

            List <Restaurants> actual = RestaurantSort.AlphaSorting(restsTests); //act

            Assert.AreEqual(expected[0].Name, actual[0].Name);                   //assert
            Assert.AreEqual(expected[1].Name, actual[1].Name);                   //assert
        }