public void Get_ShouldReturnOk_AndEmptyIEnumerable()
        {
            var result = _recipesController.Get();

            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Count());
        }
Exemplo n.º 2
0
        public async void Return_NotFound_When_No_Data()
        {
            // Act
            var result = await _controller.Get(0);

            // Assert
            Assert.IsType <NotFoundResult>(result);
        }
Exemplo n.º 3
0
        public async void CanGetCollectionOfRecipes()
        {
            DbContextOptions <CookBookDbContext> options = new DbContextOptionsBuilder <CookBookDbContext>().UseInMemoryDatabase("CanGetCollectionOfRecipes").Options;

            using (CookBookDbContext context = new CookBookDbContext(options))
            {
                //Arrange
                Recipes recipe = new Recipes();
                recipe.ID   = 1;
                recipe.Name = "Sketti n Ketchup";
                Recipes recipe2 = new Recipes();
                recipe2.ID   = 2;
                recipe2.Name = "Bread n Water";
                Recipes recipe3 = new Recipes();
                recipe3.ID   = 3;
                recipe3.Name = "Knuckle Sandwich";

                //Act
                RecipesController recipesController = new RecipesController(context, configuration);
                await recipesController.Post(recipe);

                await recipesController.Post(recipe2);

                await recipesController.Post(recipe3);

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

                //Assert
                Assert.Equal(3, data.Count);
            }
        }
Exemplo n.º 4
0
        public async void CanGetOneRecipeNotFound()
        {
            DbContextOptions <CookBookDbContext> options = new DbContextOptionsBuilder <CookBookDbContext>().UseInMemoryDatabase("CanGettRecipeOk").Options;

            using (CookBookDbContext context = new CookBookDbContext(options))
            {
                //Arrange
                Recipes recipe = new Recipes();
                recipe.ID   = 1;
                recipe.Name = "Sketti n Ketchup";
                Recipes recipe2 = new Recipes();
                recipe2.ID   = 2;
                recipe2.Name = "Bread n Water";
                Recipes recipe3 = new Recipes();
                recipe3.ID   = 3;
                recipe3.Name = "Knuckle Sandwich";

                //Act
                RecipesController recipesController = new RecipesController(context, configuration);
                await recipesController.Post(recipe);

                await recipesController.Post(recipe2);

                var data = recipesController.Get(6);

                //Assert
                Assert.IsType <NotFoundResult>(data);
            }
        }
        public void GetAllRecipe()
        {
            var repository = new Mock <IRepository <Recipe> >();
            var recipes    = new List <Recipe>();
            var r1         = new Recipe()
            {
                recipeId = 1, userId = 1, categoryId = 2, calories = 500, preparation = "zazaaza"
            };
            var r2 = new Recipe()
            {
                recipeId = 2, userId = 3, categoryId = 2, calories = 500, preparation = "zazaaza"
            };
            var r3 = new Recipe()
            {
                recipeId = 3, userId = 2, categoryId = 2, calories = 500, preparation = "zazaaza"
            };

            recipes.Add(r1);
            recipes.Add(r2);
            recipes.Add(r3);
            repository.Setup(x => x.GetAll()).Returns(recipes.AsQueryable()).Verifiable();
            var controller = new RecipesController(repository.Object);

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

            var response = controller.Get();
            IQueryable <Recipe> s;

            Assert.IsTrue(response.TryGetContentValue <IQueryable <Recipe> >(out s));
            Assert.AreEqual(recipes.AsQueryable().Count(), s.Count());
            Assert.AreEqual(recipes.AsQueryable().First(), s.First());
        }
Exemplo n.º 6
0
        public void Get_WhenCalled_ShouldReturnListOfRecipes()
        {
            var result = _controller.Get();

            _service.Verify(s => s.GetAllRecipes(), Times.Once);
            Assert.That(result, Is.TypeOf <OkObjectResult>());
        }
        public void GetRecipe()
        {
            var repository = new Mock <IRepository <Recipe> >();
            var recipe     = new Recipe()
            {
                recipeId = 1, userId = 1, categoryId = 2, calories = 500, preparation = "zazaaza"
            };

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

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

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

            Assert.IsTrue(response.TryGetContentValue <Recipe>(out s));
            Assert.AreEqual(recipe, s);
            Assert.AreNotEqual(10, s.recipeId);
        }