Пример #1
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);
            }
        }
Пример #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);
            }
        }
        public void GetSingle_IngredientNotFound_ReturnsNoResult()
        {
            var sut = new IngredientsController(_mealService.Object, _dtoConverter);

            var response = sut.Get("doesn't exist");

            Assert.IsType <NotFoundObjectResult>(response.Result);
        }
        public void GetSingle_IngredientFound_ReturnsResult()
        {
            var sut = new IngredientsController(_mealService.Object, _dtoConverter);

            var response = sut.Get(_ingredientName);

            Assert.IsType <DTO.Response.Ingredient>(response.Value);
            Assert.NotNull(response.Value);
        }
        public void GetIngredientsList_IfNotEmpty()
        {
            var repo = new Mock <IIngredientsRepository>();

            repo.Setup(x => x.Get(0, 10)).Returns(new Ingredient[3].AsQueryable());
            var controller = new IngredientsController(repo.Object);
            var result     = controller.Get();

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

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

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

            var        response = controller.Get(5);
            Ingredient s;

            Assert.IsTrue(response.TryGetContentValue <Ingredient>(out s));
            Assert.AreEqual(ingredient, s);
            Assert.AreNotEqual(10, s.ingredientId);
        }
Пример #7
0
        public void Get_returns_list_of_toppings()
        {
            var result = target.Get();

            Assert.IsTrue(result.Any());
        }