public async Task AddIngredientsInRecipe_IfNewItem_AddItem() { // Arrange var ingredientsInRecipes = new List <IngredientsInRecipe>(); _controller.CurrentRecipe = new Recipe { Id = 1 }; var count = "expected"; var ingredientId = 1; var ingredientsId = new List <int> { ingredientId }; var countIngredietns = new List <string> { count }; // Act // Run method which should be tested for (int steps = 0; steps < ingredientsId.Count; steps++) { ingredientsInRecipes .Add(new IngredientsInRecipe(_controller.CurrentRecipe.Id, ingredientsId[steps], countIngredietns[steps])); } await _controller.AddedIngredientsInRecipeAsync(ingredientsId, countIngredietns); // Assert _repositoryMock.VerifyAll(); _repositoryMock.Verify(o => o.AddRangeAsync( It.Is <List <IngredientsInRecipe> >(entity => entity.Count == ingredientsInRecipes.Count)), Times.Once); }
public static async Task AddRecipeAsync(CategoryController categoryController, RecipeController recipeController, IngredientController ingredientController, string answer = "", int count = 0) { Console.WriteLine("Введите название рецепта: "); var name = Console.ReadLine(); DisplayCategoryTree(await categoryController.GetCategoriesAsync(), null, false); Console.Write("Ввидите категорию блюда (id) : "); await categoryController.WalkCategoriesAsync(Console.ReadLine()); var categoryNew = categoryController.CurrentCategory; if (categoryNew == null) { throw new ArgumentException(nameof(categoryNew), "Null categoryNew in new Recipe"); } Console.Clear(); Console.WriteLine("Введите описание блюда: "); var description = Console.ReadLine(); Console.Clear(); do { Console.WriteLine("Введите колличество ингредиентов: "); answer = Console.ReadLine(); } while (!int.TryParse(answer, out count)); var ingredientsId = new List <int>(); for (int i = 1; i <= count; i++) { Console.WriteLine("Введите ингредиент:"); Console.Write($"{i}. "); ingredientsId.Add(await ingredientController.AddedIfNewAsync(Console.ReadLine())); } Console.WriteLine("\t\t*enter*"); Console.ReadKey(); Console.Clear(); List <string> countIngred = new List <string>(); var tempIngredients = await ingredientController.GetIngredientsAsync(); for (int id = 0; id < ingredientsId.Count; id++) { Console.WriteLine("Введите колличество для " + $"\"{tempIngredients.First(i => i.Id == ingredientsId[id]).Name}\": "); countIngred.Add(Console.ReadLine()); } int countSteps = 0; do { Console.WriteLine(); Console.Clear(); Console.Write("Введите колличество шагов приготовления: "); answer = Console.ReadLine(); } while(!int.TryParse(answer, out countSteps)); List <string> stepsHowCooking = new List <string>(); Console.WriteLine(); for (int i = 1; i <= countSteps; i++) { Console.WriteLine($"Введите описания шага {i} : "); answer = Console.ReadLine(); stepsHowCooking.Add(answer); } await recipeController.CreateRecipeAsync(name, categoryNew.Id, description); await recipeController.AddedIngredientsInRecipeAsync(ingredientsId, countIngred); await recipeController.AddedStepsInRecipeAsync(stepsHowCooking); }