Пример #1
0
        public async Task <ActionResult <Recipe> > CreateRecipe(CreatedRecipeDto newCreatedRecipe)
        {
            var ingredients = _ingredientDomain.CreateIngredientList(newCreatedRecipe.Ingredients);
            var recipe      = new Recipe
            {
                Name        = newCreatedRecipe.Name,
                Description = newCreatedRecipe.Description,
                Ingredients = ingredients
            };
            await _databaseActions.CreateRecipe(recipe);

            return(recipe);
        }
Пример #2
0
        public async Task PostRecipeWithoutIngredients()
        {
            var ingredientList = new List <CreatedIngredientDto>();
            var controller     = CreateRecipesController();
            var newRecipe      = new CreatedRecipeDto("Test recipe", "Test description", ingredientList);

            var result = await controller.PostRecipe(newRecipe);

            Assert.IsType <ActionResult <Recipe> >(result);
            Assert.Equal("Test recipe", result.Value.Name);
            Assert.Equal("Test description", result.Value.Description);
            Assert.Empty(result.Value.Ingredients);
        }
Пример #3
0
        public async Task PostRecipeWithIngredients()
        {
            var controller     = CreateRecipesController();
            var newIngredient  = new CreatedIngredientDto("ui", 2, "unit");
            var newIngredient2 = new CreatedIngredientDto("knoflook", 3, "unit");
            var ingredientList = new[] { newIngredient, newIngredient2 };

            var newRecipe     = new CreatedRecipeDto("Test recipe", "Test description", ingredientList);
            var createdRecipe = await controller.PostRecipe(newRecipe);

            Assert.Equal("Test recipe", createdRecipe.Value.Name);
            Assert.Equal("Test description", createdRecipe.Value.Description);
            Assert.Equal(2, createdRecipe.Value.Ingredients.Count);
        }
Пример #4
0
        public async Task PostRecipeWithIngredient()
        {
            var controller     = CreateRecipesController();
            var newIngredient  = new CreatedIngredientDto("ui", 2, "unit");
            var ingredientList = new[] { newIngredient };
            var newRecipe      = new CreatedRecipeDto("Test recipe", "Test description", ingredientList);

            var createdRecipe = await controller.PostRecipe(newRecipe);

            Assert.Equal("Test recipe", createdRecipe.Value.Name);
            Assert.Equal("Test description", createdRecipe.Value.Description);
            var firstIngredient = createdRecipe.Value.Ingredients.ToList()[0];

            Assert.Equal("ui", firstIngredient.Name);
            Assert.Equal(2, firstIngredient.Amount);
            Assert.Equal("unit", firstIngredient.Unit);
        }
Пример #5
0
        public async Task <ActionResult <Recipe> > PostRecipe(CreatedRecipeDto newCreatedRecipe)
        {
            var recipe = await _recipesDomain.CreateRecipe(newCreatedRecipe);

            return(recipe);
        }