Exemple #1
0
        public async Task <IActionResult> CreateRecipe(CreateRecipeDto recipeDto)
        {
            if (await _recipeRepo.ExistsAsync(recipeDto.Id))
            {
                return(Conflict("Recipe already exists!"));
            }

            var recipe = new Recipe
            {
                Id                = recipeDto.Id,
                CategoryId        = recipeDto.CategoryId,
                Cook              = TestData.TestUser,
                DurationInMinutes = recipeDto.DurationInMinutes,
                Ingredients       = recipeDto.Ingredients,
                NumberOfPortions  = recipeDto.NumberOfPortions,
                Steps             = recipeDto.Steps,
                Story             = recipeDto.Story,
                Tags              = recipeDto.Tags,
                Title             = recipeDto.Title,
                UserId            = TestData.TestUser.Id
            };

            await _recipeRepo.CreateRecipeAsync(recipe);

            return(Ok());
        }
Exemple #2
0
        public async Task CreateRecipeSuccess(DBModel.Recipe recipe, IEnumerable <DBModel.RecipeIngredient> ingredients)
        {
            A.CallTo(() => recipeRepository.CreateRecipeAsync(recipe.Name, transaction)).Returns(recipe.Id);

            var newRecipe = new NewRecipe
            {
                Name        = recipe.Name,
                Ingredients = ingredients.Select(x => new RecipeIngredient
                {
                    Amount = x.Amount,
                    Name   = x.IngredientName,
                    Unit   = x.UnitName
                }).ToList()
            };

            await sut.CreateRecipeAsync(newRecipe).ConfigureAwait(false);

            A.CallTo(() => recipeRepository.CreateRecipeAsync(recipe.Name, transaction)).MustHaveHappenedOnceExactly();
            A.CallTo(() => recipeRepository.UpsertRecipeIngredientsAsync(recipe.Id, A <IEnumerable <DBModel.RecipeIngredient> > ._, transaction)).MustHaveHappenedOnceExactly();
        }
Exemple #3
0
        public async Task <int> CreateRecipeAsync(NewRecipe newRecipe)
        {
            if (newRecipe is null)
            {
                throw new ArgumentNullException(nameof(newRecipe));
            }

            var ingredients = newRecipe.Ingredients.Select(mapper.Map <DBModel.RecipeIngredient>);

            using var tran = transactionFactory.BeginTransaction();
            var recipeId = await recipeRepository.CreateRecipeAsync(newRecipe.Name, tran).ConfigureAwait(false);

            await recipeRepository.UpsertRecipeIngredientsAsync(recipeId, ingredients, tran).ConfigureAwait(false);

            tran.Commit();
            return(recipeId);
        }