public void ListOfFoodsIdStringsToFoodListTest_withBadInput()
        {
            //Arrange
            var stringFoodId1       = "1";
            var stringFoodId2       = "2";
            var stringFoodId3       = "      ";
            var stringFoodId4       = "4";
            var listOfFoodIdStrings = new List <string> {
                stringFoodId1, stringFoodId2, stringFoodId3, stringFoodId4
            };

            #region Setup4FoodDto
            var food1 = new FoodDTO
            {
                Description      = "Some Test Description, for FoodDTO1",
                FoodCategoryName = "Mad",
                Id    = 1,
                Name  = "Oats Large Flake",
                Price = 218
            };
            var food2 = new FoodDTO
            {
                Description      = "Some Test Description, for FoodDTO2",
                FoodCategoryName = "Drikkevare",
                Id    = 2,
                Name  = "Oil - Food, Lacquer Spray",
                Price = 202
            };
            var food3 = new FoodDTO
            {
                Description      = "Some Test Description, for FoodDTO2",
                FoodCategoryName = "Mad",
                Id    = 3,
                Name  = "Turkey Leg With Drum And Thigh",
                Price = 179
            };
            var food4 = new FoodDTO
            {
                Description      = "Some Test Description, for FoodDTO2",
                FoodCategoryName = "Drikkevare",
                Id    = 4,
                Name  = "Ecolab - Lime - A - Way 4/4 L",
                Price = 112
            };


            #endregion

            var completeFoodInAList = new List <FoodDTO> {
                food1, food2, food3, food4
            };

            // Act => Assert
            Assert.ThrowsException <FormatException>(() => ConvertStringToFoodLists
                                                     .ListOfFoodsIdStringsToFoodList(listOfFoodIdStrings, completeFoodInAList));
        }
Esempio n. 2
0
        public ActionResult OrderFood(CustomViewModel cvm)
        {
            //  data from view
            var foods  = Request.Form["listFood"];
            var drinks = Request.Form["listDrink"];
            var orders = Request.Form["OrderSummary"];
            var data3  = Request.Form["ReservationNumber"];

            var orderSummaryListOfStrings = orders?.Split(',').ToList();
            var foodListOfStrings         = foods?.Split(',').ToList();
            var drinkListOfStrings        = drinks?.Split(',').ToList();
            var foodsListFromApi          = _foodService.GetAll().ToList();

            var foodList = ConvertStringToFoodLists
                           .ListOfFoodsIdStringsToFoodList(foodListOfStrings, foodsListFromApi);
            var drinkList = ConvertStringToFoodLists
                            .ListOfFoodsIdStringsToFoodList(drinkListOfStrings, foodsListFromApi);

            var allGood = int.TryParse(data3, out var ReservationId);

            cvm.ListFood     = foodList;
            cvm.ListDrink    = drinkList;
            cvm.Reservation  = new ReservationDTO(ReservationId);
            cvm.OrderSummary = new List <FoodDTO>();

            if (orderSummaryListOfStrings != null && orderSummaryListOfStrings.Count > 0 && allGood)
            {
                var orderLineList =
                    ConvertStringToOrderLines
                    .ListOfFoodsIdToOrderLines(orderSummaryListOfStrings, foodsListFromApi);
                var r = new ReservationDTO(ReservationId);

                var order = new OrderDTO
                {
                    ReservationID    = r.Id,
                    OrderDate        = DateTime.Today,
                    EmployeeID       = 1,
                    PaymentCondition = PaymentCondition.Bestilt.ToString(),
                    OrderLines       = orderLineList
                };

                var response = _orderService.Create(order);

                if (response != null)
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            else
            {
                //TODO add error msg that no res id matched/wasChanged or was not net from the creation of reservation
                //if all good fails

                //TODO add error msg to view
                //NO Food were selected
                //throw new NotImplementedException("NO Food were selected or no food return from post");
                return(View(cvm));
            }

            return(View(cvm));
        }
        public void ListOfFoodsIdStringsToFoodListTest_withValidInput()
        {
            //Arrange
            var stringFoodId1       = "1";
            var stringFoodId2       = "2";
            var stringFoodId3       = "3";
            var stringFoodId4       = "4";
            var listOfFoodIdStrings = new List <string> {
                stringFoodId1, stringFoodId2, stringFoodId3, stringFoodId4
            };

            #region Setup4FoodDto
            var food1 = new FoodDTO
            {
                Description      = "Some Test Description, for FoodDTO1",
                FoodCategoryName = "Mad",
                Id    = 1,
                Name  = "Oats Large Flake",
                Price = 218
            };
            var food2 = new FoodDTO
            {
                Description      = "Some Test Description, for FoodDTO2",
                FoodCategoryName = "Drikkevare",
                Id    = 2,
                Name  = "Oil - Food, Lacquer Spray",
                Price = 202
            };
            var food3 = new FoodDTO
            {
                Description      = "Some Test Description, for FoodDTO2",
                FoodCategoryName = "Mad",
                Id    = 3,
                Name  = "Turkey Leg With Drum And Thigh",
                Price = 179
            };
            var food4 = new FoodDTO
            {
                Description      = "Some Test Description, for FoodDTO2",
                FoodCategoryName = "Drikkevare",
                Id    = 4,
                Name  = "Ecolab - Lime - A - Way 4/4 L",
                Price = 112
            };


            #endregion

            var completeFoodInAList = new List <FoodDTO> {
                food1, food2, food3, food4
            };

            //Act
            var foods = ConvertStringToFoodLists.ListOfFoodsIdStringsToFoodList(listOfFoodIdStrings,
                                                                                completeFoodInAList);

            //Assert
            Assert.IsNotNull(foods);
            Assert.AreEqual(4, foods.Count);

            Assert.IsNotNull(foods.ElementAt(0));
            Assert.IsNotNull(foods.ElementAt(1));
            Assert.IsNotNull(foods.ElementAt(2));
            Assert.IsNotNull(foods.ElementAt(3));

            Assert.AreEqual(food1.Id, foods.ElementAt(0).Id);
            Assert.AreEqual(food2.Id, foods.ElementAt(1).Id);
            Assert.AreEqual(food3.Id, foods.ElementAt(2).Id);
            Assert.AreEqual(food4.Id, foods.ElementAt(3).Id);
        }