public void MultipleDishesNightRuleIsFalse()
        {
            IOrder order = new Order();

            order.SetTimeOfDay(Enums.TimeOfDay.Night);
            Assert.IsFalse(OrderValidation.ValidateMultipleDishes(order, Enums.DishTypes.Dessert));
        }
        public void MultipleDishesMorningRuleIsFalse()
        {
            IOrder order = new Order();

            order.SetTimeOfDay(Enums.TimeOfDay.Morning);
            Assert.IsFalse(OrderValidation.ValidateMultipleDishes(order, Enums.DishTypes.Entree));
        }
예제 #3
0
        /// <summary>
        /// Process dishes in the order list.
        /// It will validate multiple dishes rule and increment the dish's counter.
        /// </summary>
        /// <param name="order">The order wich will be processed.</param>
        /// <param name="inputString">Input string with order info.</param>
        /// <returns>Returns true if process completes ok, or false if not.</returns>
        public static bool ProcessDishes(IOrder order, string inputString)
        {
            try
            {
                if (order == null)
                {
                    return(false);
                }

                Enums.DishTypes dishType = GetDishType(inputString);

                if (dishType == Enums.DishTypes.Error)
                {
                    order.SetError();
                    return(false);
                }

                if (OrderValidation.ValidateMultipleDishes(order, dishType))
                {
                    // If dish allows multiple choices, increment counter
                    order.DishCounter(dishType, true);
                }
                else
                {
                    // If dish doesn't allow multiple choices, but counter is 0 AND
                    // is not dessert on morning, increment counter
                    if (order.DishCounter(dishType) == 0 && OrderValidation.ValidateMorningDessertRule(order, dishType))
                    {
                        order.DishCounter(dishType, true);
                    }
                    else
                    {
                        // Otherwise, set error in the order
                        order.SetError();
                        return(false);
                    }
                }
                return(true);
            }
            catch (Exception)
            {
                order.SetError();
                return(false);
            }
        }