public async void Can_get_ingredient_without_recipe() { using var context = new RecAPIContext(ContextOptions); var controller = new IngredientsController(context); var ingredientActionResult = await controller.GetIngredient(1); var ingredient = ingredientActionResult.Value; Assert.Equal("Fusilli", ingredient.Name); }
public async void Can_get_ingredients_by_name_substring() { using var context = new RecAPIContext(ContextOptions); var controller = new IngredientsController(context); var ingredientActionResult = await controller.GetIngredientsByNameSubstring("Fu"); var ingredients = (ingredientActionResult.Result as OkObjectResult).Value as IEnumerable <IngredientDTO>; Assert.Equal(2, ingredients.Count()); }
public async void Can_get_recipe() { using var context = new RecAPIContext(ContextOptions); var controller = new RecipesController(context); var recipeActionResult = await controller.GetRecipe(1); var recipe = recipeActionResult.Value; Assert.Equal("Pasta with garlic", recipe.Name); }
public async void Can_get_ingredient_with_recipe() { using var context = new RecAPIContext(ContextOptions); var controller = new IngredientsController(context); var ingredientActionResult = await controller.GetRecipeIngredientsOfIngredient(2); var recipeIngredients = (ingredientActionResult.Result as OkObjectResult).Value as IEnumerable <RecipeIngredientDTO>; Assert.Equal("Pure Garlic", recipeIngredients.FirstOrDefault().RecipeName); }
public async void Get_recipe_includes_ingredients() { using var context = new RecAPIContext(ContextOptions); var controller = new RecipesController(context); var recipeActionResult = await controller.GetRecipe(1); var recipe = recipeActionResult.Value; Assert.Equal("Garlic", recipe.RecipeIngredients.FirstOrDefault().IngredientName); }
private void Seed() { using var context = new RecAPIContext(ContextOptions); context.Database.EnsureDeleted(); context.Database.EnsureCreated(); var fusilli = new Ingredient { Id = 1, Name = "Fusilli", RecipeIngredients = new List <RecipeIngredient>() }; var garlic = new Ingredient { Id = 2, Name = "Garlic", RecipeIngredients = new List <RecipeIngredient>() }; var fugu = new Ingredient { Id = 3, Name = "Fugu", RecipeIngredients = new List <RecipeIngredient>() }; var recipe = new Recipe { Id = 1, Name = "Pure Garlic", Description = "For the true fans of garlic", Instructions = "Peel garlic. Consume garlic.", RecipeIngredients = new List <RecipeIngredient>() }; var riGarlic = new RecipeIngredient { IngredientId = 1, Ingredient = garlic, RecipeId = 1, Recipe = recipe, Amount = 1000, Unit = (Unit)5 }; garlic.RecipeIngredients.Add(riGarlic); context.Ingredients.Add(garlic); context.Ingredients.Add(fusilli); context.Ingredients.Add(fugu); context.SaveChanges(); }
public async void Can_post_ingredient() { using var context = new RecAPIContext(ContextOptions); var controller = new IngredientsController(context); var ingredientDTO = new IngredientDTO { Name = "Fusilli" }; var ingredientActionResult = await controller.PostIngredient(ingredientDTO); var ingredient = (ingredientActionResult.Result as CreatedAtActionResult).Value as IngredientDTO; Assert.Equal("Fusilli", ingredient.Name); }
public async void Can_post_recipe() { using var context = new RecAPIContext(ContextOptions); var controller = new RecipesController(context); var riFusilliDTO = new RecipeIngredientDTO { IngredientId = 2, IngredientName = "Fusilli", Amount = 200, Unit = (Unit)1 }; var riKetchupDTO = new RecipeIngredientDTO { IngredientId = 3, IngredientName = "Ketchup", Amount = 200, Unit = (Unit)1 }; var recipeDTO = new RecipeDTO { Name = "Pasta with ketchup", Description = "Better than with garlic", Instructions = "Boil pasta. Add ketchup.", RecipeIngredients = new List <RecipeIngredientDTO> { riFusilliDTO, riKetchupDTO } }; var recipeActionResult = await controller.PostRecipe(recipeDTO); var recipe = (recipeActionResult.Result as CreatedAtActionResult).Value as RecipeDTO; Assert.Equal("Pasta with ketchup", recipe.Name); Assert.Equal("Fusilli", recipe.RecipeIngredients.FirstOrDefault().IngredientName); }
private void Seed() { using var context = new RecAPIContext(ContextOptions); context.Database.EnsureDeleted(); context.Database.EnsureCreated(); var garlic = new Ingredient { Id = 1, Name = "Garlic", RecipeIngredients = new List <RecipeIngredient>() }; var fusilli = new Ingredient { Id = 2, Name = "Fusilli", RecipeIngredients = new List <RecipeIngredient>() }; var ketchup = new Ingredient { Id = 3, Name = "Ketchup", RecipeIngredients = new List <RecipeIngredient>() }; var recipe = new Recipe { Id = 1, Name = "Pasta with garlic", Description = "Garlic is tasty. Fusilli is screw-shaped.", Instructions = "Boil pasta. Add all of the cloves of garlic.", RecipeIngredients = new List <RecipeIngredient>() }; var riGarlic = new RecipeIngredient { RecipeId = recipe.Id, Recipe = recipe, IngredientId = garlic.Id, Ingredient = garlic, Amount = 200, Unit = (Unit)1 }; var riFusilli = new RecipeIngredient { RecipeId = recipe.Id, Recipe = recipe, IngredientId = fusilli.Id, Ingredient = fusilli, Amount = 200, Unit = (Unit)1 }; recipe.RecipeIngredients.Add(riGarlic); recipe.RecipeIngredients.Add(riFusilli); garlic.RecipeIngredients.Add(riGarlic); fusilli.RecipeIngredients.Add(riFusilli); context.Ingredients.Add(ketchup); context.Recipes.Add(recipe); context.SaveChanges(); }
public RecipesController(RecAPIContext context) { _context = context; }
public IngredientsController(RecAPIContext context) { _context = context; }