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

            using (CookBookDbContext context = new CookBookDbContext(options))
            {
                //Arrange
                Ingredients ingredient = new Ingredients();
                ingredient.ID   = 1;
                ingredient.Name = "Swag";
                Ingredients ingredient2 = new Ingredients();
                ingredient2.ID   = 2;
                ingredient2.Name = "Energy";

                //Act
                IngredientsController ingredientsController = new IngredientsController(context, configuration);
                await ingredientsController.Post(ingredient);

                await ingredientsController.Post(ingredient2);

                await ingredientsController.Delete(ingredient.ID);

                var result = context.Ingredients.FirstOrDefault(c => c.ID == ingredient.ID);

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

            using (CookBookDbContext context = new CookBookDbContext(options))
            {
                //Arrange
                Ingredients ingredient = new Ingredients();
                ingredient.ID   = 1;
                ingredient.Name = "Swag";
                Ingredients ingredient2 = new Ingredients();
                ingredient2.ID   = 2;
                ingredient2.Name = "Energy";

                //Act
                IngredientsController ingredientsController = new IngredientsController(context, configuration);
                await ingredientsController.Post(ingredient);

                await ingredientsController.Post(ingredient2);

                var data = ingredientsController.Get(2);

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

            using (CookBookDbContext context = new CookBookDbContext(options))
            {
                //Arrange
                Ingredients ingredient = new Ingredients();
                ingredient.ID   = 1;
                ingredient.Name = "Swag";
                Ingredients ingredient2 = new Ingredients();
                ingredient2.ID   = 2;
                ingredient2.Name = "Energy";
                Ingredients ingredient3 = new Ingredients();
                ingredient3.ID   = 3;
                ingredient3.Name = "Heart";

                //Act
                IngredientsController ingredientsController = new IngredientsController(context, configuration);
                await ingredientsController.Post(ingredient);

                await ingredientsController.Post(ingredient2);

                await ingredientsController.Post(ingredient3);

                var data = ingredientsController.Get().ToList();

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

            using (CookBookDbContext context = new CookBookDbContext(options))
            {
                //Arrange
                Ingredients ingredient = new Ingredients();
                ingredient.ID   = 1;
                ingredient.Name = "Swag";
                Ingredients ingredient2 = new Ingredients();
                ingredient2.ID   = 2;
                ingredient2.Name = "Energy";
                Ingredients ingredient3 = new Ingredients();
                ingredient3.ID   = 3;
                ingredient3.Name = "Heart";

                //Act
                IngredientsController ingredientsController = new IngredientsController(context, configuration);
                await ingredientsController.Post(ingredient);

                await ingredientsController.Post(ingredient2);

                var data = await ingredientsController.Put(6, ingredient3);

                //Assert
                Assert.IsType <BadRequestObjectResult>(data);
            }
        }
Пример #5
0
        public void TestPostIngredient()
        {
            var repository = new Mock <IRepository <Ingredient> >();
            var ingredient = new Ingredient()
            {
                ingredientId = 1, categoryId = 2, calories = 500, name = "tomate"
            };

            repository.Setup(x => x.Add(ingredient)).Returns(true).Verifiable();
            var controller = new IngredientsController(repository.Object);

            controller.Request       = new HttpRequestMessage();
            controller.Configuration = new HttpConfiguration();

            var        response = controller.Post(ingredient);
            Ingredient s;

            Assert.IsTrue(response.TryGetContentValue <Ingredient>(out s));
            Assert.AreEqual(ingredient, s);
            Assert.AreNotEqual(10, s.ingredientId);
        }