Пример #1
0
        public async void CanGetAllRecipeIngredient()
        {
            DbContextOptions <CookBookDbContext> options = new DbContextOptionsBuilder <CookBookDbContext>().UseInMemoryDatabase("CanGetAllRecipeIngredient").Options;

            using (CookBookDbContext context = new CookBookDbContext(options))
            {
                //Arrange
                RecipeIngredients recipeIng = new RecipeIngredients();
                recipeIng.RecipeID      = 1;
                recipeIng.IngredientsID = 1;
                recipeIng.Quantity      = "1 pound";
                RecipeIngredients recipeIng2 = new RecipeIngredients();
                recipeIng2.RecipeID      = 1;
                recipeIng2.IngredientsID = 2;
                recipeIng2.Quantity      = "1 cup";
                RecipeIngredients recipeIng3 = new RecipeIngredients();
                recipeIng3.RecipeID      = 1;
                recipeIng3.IngredientsID = 3;
                recipeIng3.Quantity      = "10 stone";

                //Act
                RecipeIngredientsController recipeIngredientsController = new RecipeIngredientsController(context, configuration);
                await recipeIngredientsController.Post(recipeIng);

                await recipeIngredientsController.Post(recipeIng2);

                await recipeIngredientsController.Post(recipeIng3);

                var result = recipeIngredientsController.Get().ToList();

                //Assert
                Assert.Equal(3, result.Count);
            }
        }
Пример #2
0
        public async void CannotCreateRecipeIngredient()
        {
            DbContextOptions <CookBookDbContext> options = new DbContextOptionsBuilder <CookBookDbContext>().UseInMemoryDatabase("CannotCreateRecipeIngredient").Options;

            using (CookBookDbContext context = new CookBookDbContext(options))
            {
                //Arrange
                RecipeIngredients recipeIng = new RecipeIngredients();
                recipeIng.RecipeID      = 1;
                recipeIng.IngredientsID = 1;
                recipeIng.Quantity      = "1 pound";
                RecipeIngredients recipeIng2 = new RecipeIngredients();
                recipeIng2.RecipeID      = 1;
                recipeIng2.IngredientsID = 2;
                recipeIng2.Quantity      = "1 cup";

                //Act
                RecipeIngredientsController recipeIngredientsController = new RecipeIngredientsController(context, configuration);
                await recipeIngredientsController.Post(recipeIng);

                await recipeIngredientsController.Post(recipeIng2);

                var result = await recipeIngredientsController.Delete(4, 4);

                //Assert
                Assert.IsType <NotFoundResult>(result);
            }
        }
Пример #3
0
        public async void CannotEditRecipeIngredient()
        {
            DbContextOptions <CookBookDbContext> options = new DbContextOptionsBuilder <CookBookDbContext>().UseInMemoryDatabase("CannotEditRecipeIngredient").Options;

            using (CookBookDbContext context = new CookBookDbContext(options))
            {
                //Arrange
                RecipeIngredients recipeIng = new RecipeIngredients();
                recipeIng.RecipeID      = 1;
                recipeIng.IngredientsID = 1;
                recipeIng.Quantity      = "1 pound";
                RecipeIngredients recipeIng2 = new RecipeIngredients();
                recipeIng2.RecipeID      = 1;
                recipeIng2.IngredientsID = 2;
                recipeIng2.Quantity      = "1 cup";
                RecipeIngredients recipeIng3 = new RecipeIngredients();
                recipeIng3.RecipeID      = 1;
                recipeIng3.IngredientsID = 3;
                recipeIng3.Quantity      = "10 stone";

                //Act
                RecipeIngredientsController recipeIngredientsController = new RecipeIngredientsController(context, configuration);
                await recipeIngredientsController.Post(recipeIng);

                await recipeIngredientsController.Post(recipeIng2);

                var result = await recipeIngredientsController.Put(5, 5, recipeIng3);

                //Assert
                Assert.IsType <BadRequestObjectResult>(result);
            }
        }