/// <summary> /// Returns food entity item from the supplied dictionary list /// and the type of food entity item. /// Returns the pre-defined food or recipe if none found in the supplied dictionary list. /// </summary> public static string GetFoodEntities(Dictionary <string, object> paramters, BotConstants.FoodEntitiesEnum foodEntitiesEnum) { if (paramters == null) { return(foodEntitiesEnum == BotConstants.FoodEntitiesEnum.Recipe ? BotConstants.OtherConstants.DefaultRecipeDish : BotConstants.OtherConstants.DefaultIngredientsSerialized); } string foodItem = ""; foreach (var j in paramters) { if (j.Key == BotConstants.ApiAiParametersConstants.FoodItem && foodEntitiesEnum == BotConstants.FoodEntitiesEnum.FoodItem) { foodItem = string.IsNullOrEmpty(j.Value.ToString()) ? BotConstants.OtherConstants.DefaultIngredientsSerialized : j.Value.ToString(); } if (j.Key == BotConstants.ApiAiParametersConstants.Recipe && foodEntitiesEnum == BotConstants.FoodEntitiesEnum.Recipe) { foodItem = string.IsNullOrEmpty(j.Value.ToString()) ? BotConstants.OtherConstants.DefaultRecipeDish : j.Value.ToString(); } } return(GetFoodEntitiesWhenFoodItemIsNull(foodItem, foodEntitiesEnum)); }
public void GetFoodEntitiesWhenFoodItemIsNull_ReturnsExpectedString_Test(string foodItem, BotConstants.FoodEntitiesEnum foodEntitiesEnum, string expected) { Assert.Equal(expected, MiscService.GetFoodEntitiesWhenFoodItemIsNull(foodItem, foodEntitiesEnum)); }
public void GetFoodEntities_HandlesNull_Test(BotConstants.FoodEntitiesEnum foodEntitiesEnum, string expectedOutput) { Assert.Equal(expectedOutput, MiscService.GetFoodEntities(null, foodEntitiesEnum)); }
/// <summary> /// Decides what string to return when foodItem is null or empty /// </summary> public static string GetFoodEntitiesWhenFoodItemIsNull(string foodItem, BotConstants.FoodEntitiesEnum foodEntitiesEnum) { return(string.IsNullOrEmpty(foodItem) ? (foodEntitiesEnum == BotConstants.FoodEntitiesEnum.FoodItem ? BotConstants.OtherConstants.DefaultIngredientsSerialized : BotConstants.OtherConstants.DefaultRecipeDish) : foodItem); }