public void Input_MealType_Night_OK() { string input = "Night"; MealType c = new OrderingValidator().GetMealType(input); Assert.IsTrue(c == MealType.NIGHT); }
public void Input_MealType_Error() { string input = "MORaiNG"; MealType c = new OrderingValidator().GetMealType(input); Assert.IsTrue(c == MealType.NOTAVAILABLE); }
public void Input_MealType_Morning_OK() { string input = "MORniNG"; MealType c = new OrderingValidator().GetMealType(input); Assert.IsTrue(c == MealType.MORNING); }
public void CreateMeal(string input) { Logger.Info("Input: " + input); this._meal = (Meal)this._cache.Get(input); if (this._meal == null) { #region Create Meal MealType meal = MealType.NOTAVAILABLE; var validator = new OrderingValidator(); if (validator.isInputValid(input, out meal)) { if (meal != MealType.NOTAVAILABLE) { #region Create Meal this._meal = MealFactory.CreateMeal(meal); var listDishes = validator.GetListDishes().OrderBy(x => x).GroupBy(x => x); bool hasError = false; foreach (var item in listDishes) { DishType? currentDishType = validator.GetToDishType(item.Key); int dishRepetition = item.Count(); if (currentDishType != null) { var dish = this._meal.Dishes.Where(x => x.DishType == currentDishType).FirstOrDefault(); if (dishRepetition > 1) { if (dish.HasMultipleOrder()) { dish.HasOrdered = true; dish.Order(dishRepetition); } else dish = new ErrorDish(); } else { if (dish != null) { dish.HasOrdered = true; dish.Order(1); } if (currentDishType == DishType.DESERT && meal == MealType.MORNING) { this._meal.Add(new ErrorDish()); } } } else { if (!hasError) this._meal.Add(new ErrorDish()); } } //Check if there is any previous dish that isn't ordered ValidOrder(); #endregion #region Adding Meal to Cache this._cache.Set(input, this._meal); #endregion } else { #region Meal Type Not Found this._meal = new Meal("Error"); this._meal.Add(new ErrorDish()); #endregion } } #endregion } }