Пример #1
0
        // Возвращает страницу с информацией о продукте
        public ActionResult ProductInfo(string product_id, 
                                        string sessionID = "default")
        {
            // Проверяем при загрузке страницы есть ли на сервере
            // объект текущей сессии
            if (!MvcApplication.MenuSessions.ContainsKey(sessionID))
                MvcApplication.MenuSessions.Add(sessionID,
                    (new MenuSession()));

            // Выбор языка интерфейса электронного меню
            // Если текущий язык русский
            if (MvcApplication.MenuSessions[sessionID].lang_menu_flag == "RU")
            {
                ViewData["productInfoBtnText"] = "Описание";
                ViewData["productConsistBtnText"] = "Состав";
                ViewData["productRecommendBtnText"] = "Совет";
                ViewData["orderProductBtnText"] = "ЗАКАЗАТЬ";
                ViewData["portionText"] = "Порция:";
                ViewData["worthText"] = "Цена:";
            }
            else
            {
                ViewData["productInfoBtnText"] = "Description";
                ViewData["productConsistBtnText"] = "Consist";
                ViewData["productRecommendBtnText"] = "Advice";
                ViewData["orderProductBtnText"] = "ORDER";
                ViewData["portionText"] = "Portion:";
                ViewData["worthText"] = "Price:";
            }

            try
            {
                // Формируем содержимое в зависимости от product_id продукта
                // через ViewData
                string lang_flag =
                    MvcApplication.MenuSessions[sessionID].lang_menu_flag;
                Product product = new Product(Convert.ToInt32(product_id));

                ViewData["Product_ID"] = product.Product_ID;
                ViewData["Product_CurrentName"] = product.getProductName(lang_flag);
                ViewData["Product_NameRU"] = product.getProductName("RU");
                ViewData["Product_NameEN"] = product.getProductName("EN");
                ViewData["Product_Rating"] = product.getProductRate();
                ViewData["Product_Discription"] = product.getProductInfo(lang_flag);
                ViewData["Product_Consist"] = product.getProductConsist(lang_flag);
                ViewData["Product_Recommend"] = product.getProductRecommendation(lang_flag);
                ViewData["Product_Img_0"] = product.Product_Img_List[1];
                ViewData["Product_Img_1"] = product.Product_Img_List[2];
                ViewData["Product_Portion"] = product.getProductAmount(lang_flag);
                ViewData["Product_Worth"] = product.Product_Price.Replace(',', '.');
            }
            catch (Exception exception)
            {
                string msg = DateTime.Now.ToShortTimeString()
                             + ": " + exception.Message + ": "
                             + (exception.InnerException != null
                                ? exception.InnerException.Message : "");
                aosLogger.getInstance().WriteLog(msg);
            }

            return View();
        }
Пример #2
0
        public void ProductTest()
        {   
            // Тест конструктора             
            // Ожидаемые значения (взяты из тестовой БД AOS.DB.test)
            int expected_product_id = 5;                    
            string expected_product_name_ru =
                "Салат Мегаполис";
            string expected_product_name_en =
                "Salad Megapolis";
            int expected_product_class = 1;                    
            string expected_product_info_ru =
                "Ломтики нежной телятины, помидоры, огурцы, "
                    + "перец сладкий, листья салата, чеснок, заправлен "
                    + "фирменным соусом.";
            string expected_product_info_en =
                "Slices of tender veal, tomatoes, cucumbers, "
                    + "peppers, lettuce, garlic, filled with special sauce.";
            string expected_product_recommend_ru =
                "Ломтики нежной телятины, помидоры, огурцы, "
                    + "перец сладкий, листья салата, чеснок, заправлен "
                    + "фирменным соусом.";
            string expected_product_recommend_en =
                "Slices of tender veal, tomatoes, cucumbers, "
                    + "peppers, lettuce, garlic, filled with special sauce.";
            string expected_product_consist_ru =
                "Ломтики нежной телятины, помидоры, огурцы, "
                    + "перец сладкий, листья салата, чеснок, заправлен "
                    + "фирменным соусом.";
            string expected_product_consist_en =
                "Slices of tender veal, tomatoes, cucumbers, "
                    + "peppers, lettuce, garlic, filled with special sauce.";
            List<string> expected_product_img_list = new List<string>();
            expected_product_img_list.Add("megapolis_small.jpg");
            expected_product_img_list.Add("megapolis_0.jpg");
            expected_product_img_list.Add("megapolis_1.jpg");
            byte expected_product_rate;            
            using (AOSDB aos_db = new AOSDB())
            {
                // Находим элемент в таблице с рейтами БД с ID = _Product_ID
                AOS_BD_PRODUCT_RATE product_rate_list =
                    (from item in
                         aos_db.AOS_BD_PRODUCT_RATE.ToList<AOS_BD_PRODUCT_RATE>()
                         .AsParallel<AOS_BD_PRODUCT_RATE>()
                     where (item.PK_AOS_ID_PRODUCT == 5)
                     select item).Single();

                // Считаем общий бал
                int rate_sum = product_rate_list.PRODUCT_RATE_0 * (-1)
                                    + product_rate_list.PRODUCT_RATE_1
                                    + product_rate_list.PRODUCT_RATE_2 * 2
                                    + product_rate_list.PRODUCT_RATE_3 * 3
                                    + product_rate_list.PRODUCT_RATE_4 * 4
                                    + product_rate_list.PRODUCT_RATE_5 * 5;
                // Считаем количество раз, когда ставился рейт
                int rate_count = product_rate_list.PRODUCT_RATE_0
                                    + product_rate_list.PRODUCT_RATE_1
                                    + product_rate_list.PRODUCT_RATE_2
                                    + product_rate_list.PRODUCT_RATE_3
                                    + product_rate_list.PRODUCT_RATE_4
                                    + product_rate_list.PRODUCT_RATE_5;
                expected_product_rate = (byte)Math.Ceiling((double)(rate_sum / rate_count));
            }
            string expected_product_amount_ru = "200 г";
            string expected_product_amount_en = "200 g";
            string expected_product_price = "350,00";

            // Полученные значения
            Product test_product = new Product(5);
            int actual_product_id =
                test_product.Product_ID;
            string actual_product_name_ru =
                test_product.getProductName("RU");
            string actual_product_name_en =
                test_product.getProductName("EN");
            int actual_product_class =
                test_product.Product_Class;
            string actual_product_info_ru =
                test_product.getProductInfo("RU");
            string actual_product_info_en =
                test_product.getProductInfo("EN");
            string actual_product_recommend_ru =
                test_product.getProductRecommendation("RU");
            string actual_product_recommend_en =
                test_product.getProductRecommendation("EN");
            string actual_product_consist_ru =
                test_product.getProductConsist("RU");
            string actual_product_consist_en =
                test_product.getProductConsist("EN");
            List<string> actual_product_img_list =
                test_product.Product_Img_List;
            byte actual_product_rate =
                test_product.getProductRate();
            string actual_product_amount_ru =
                test_product.getProductAmount("RU");
            string actual_product_amount_en =
                test_product.getProductAmount("EN");
            string actual_product_price =
                test_product.Product_Price;

            // Утверждения
            Assert.AreEqual(expected_product_id, actual_product_id);
            Assert.AreEqual(expected_product_name_ru, actual_product_name_ru);
            Assert.AreEqual(expected_product_name_en, actual_product_name_en);
            Assert.AreEqual(expected_product_class, actual_product_class);
            Assert.AreEqual(expected_product_info_ru, actual_product_info_ru);
            Assert.AreEqual(expected_product_info_en, actual_product_info_en);
            Assert.AreEqual(expected_product_recommend_ru, actual_product_recommend_ru);
            Assert.AreEqual(expected_product_recommend_en, actual_product_recommend_en);
            Assert.AreEqual(expected_product_consist_ru, actual_product_consist_ru);
            Assert.AreEqual(expected_product_consist_en, actual_product_consist_en);
            Assert.AreEqual(expected_product_img_list, actual_product_img_list);
            Assert.AreEqual(expected_product_rate, actual_product_rate);
            Assert.AreEqual(expected_product_amount_ru, actual_product_amount_ru);
            Assert.AreEqual(expected_product_amount_en, actual_product_amount_en);
            Assert.AreEqual(expected_product_price, actual_product_price);

            // Тест установки нового рейта продукта
            // Устанавливаем новый рейт продукта
            test_product.setProductRate(0);
            using (AOSDB aos_db = new AOSDB())
            {
                // Находим элемент в таблице с рейтами БД с ID = _Product_ID
                AOS_BD_PRODUCT_RATE product_rate_list =
                    (from item in
                         aos_db.AOS_BD_PRODUCT_RATE.ToList<AOS_BD_PRODUCT_RATE>()
                         .AsParallel<AOS_BD_PRODUCT_RATE>()
                     where (item.PK_AOS_ID_PRODUCT == 5)
                     select item).Single();

                // Считаем общий бал
                int rate_sum = product_rate_list.PRODUCT_RATE_0 * (-1)
                                    + product_rate_list.PRODUCT_RATE_1
                                    + product_rate_list.PRODUCT_RATE_2 * 2
                                    + product_rate_list.PRODUCT_RATE_3 * 3
                                    + product_rate_list.PRODUCT_RATE_4 * 4
                                    + product_rate_list.PRODUCT_RATE_5 * 5;
                // Считаем количество раз, когда ставился рейт
                int rate_count = product_rate_list.PRODUCT_RATE_0
                                    + product_rate_list.PRODUCT_RATE_1
                                    + product_rate_list.PRODUCT_RATE_2
                                    + product_rate_list.PRODUCT_RATE_3
                                    + product_rate_list.PRODUCT_RATE_4
                                    + product_rate_list.PRODUCT_RATE_5;
                expected_product_rate = (byte)Math.Ceiling((double)(rate_sum / rate_count));
            }
            actual_product_rate =
                test_product.getProductRate();

            // Утверждения
            Assert.AreEqual(expected_product_rate, actual_product_rate);
        }