Ejemplo n.º 1
0
        public async Task AddStepsInRecipe_IfNewItem_AddItem()
        {
            // Arrange
            _controller.CurrentRecipe = new Recipe {
                Id = 1
            };
            var stepsInRecipes = new List <StepsInRecipe>();
            var step           = "expected";

            var stepsInRecipe = new List <string>
            {
                step
            };

            // Act
            // Run method which should be tested
            for (int it = 0; it < stepsInRecipe.Count; it++)
            {
                stepsInRecipes.Add(new StepsInRecipe(_controller.CurrentRecipe.Id, stepsInRecipe[it]));
            }

            await _controller.AddedStepsInRecipeAsync(stepsInRecipe);

            // Assert
            _repositoryMock.Verify(o => o.AddRangeAsync(It.Is <List <StepsInRecipe> >(entity => entity.Count == stepsInRecipes.Count)), Times.Once);
            _repositoryMock.VerifyAll();
        }
Ejemplo n.º 2
0
        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);
        }