Ejemplo n.º 1
0
        public void DeleteRecipe_Success()
        {
            var result = _recipesController.DeleteRecipe(new Guid());
            var res    = (Microsoft.AspNetCore.Mvc.OkObjectResult)result;

            res.StatusCode.Should().Be((int)HttpStatusCode.OK);
            result.Should().NotBeNull();
        }
        public void DeleteRecipe_Returns404NotFound_WhenNonExistentResourceIDSubmitted()
        {
            mockRepo.Setup(repo =>
                           repo.GetRecipeById(0)).Returns(() => null);
            var controller = new RecipesController(mockRepo.Object, mapper);
            var result     = controller.DeleteRecipe(0);

            Assert.IsType <NotFoundResult>(result);
        }
Ejemplo n.º 3
0
        public async Task TestDeleteFailRecipe()
        {
            using (var context = new MyRecipesContext(options))
            {
                RecipesController recipeController = new RecipesController(context, configuration);
                IActionResult     failResult       = await recipeController.DeleteRecipe(4) as IActionResult;

                // Assert
                Assert.IsNotNull(failResult);
                Assert.IsInstanceOfType(failResult, typeof(NotFoundResult));
            }
        }
Ejemplo n.º 4
0
        public async Task DeleteRecipe_Returns_Ok()
        {
            // Arrange
            var mockRepository = new Mock <IRecipesRepository>();
            var controller     = new RecipesController(mockRepository.Object);

            // Act
            IHttpActionResult actionResult = await controller.DeleteRecipe(10);

            // Assert
            Assert.IsInstanceOfType(actionResult, typeof(OkResult));
        }
Ejemplo n.º 5
0
        public void DeleteRecipe_Failure()
        {
            _mockService.Setup(s => s.DeleteRecipe(It.IsAny <Guid>()))
            .Returns(new RecipeResponse("Bad Request"));
            _recipesController = new RecipesController(_mockService.Object, _logger.Object, _mappingConfig.CreateMapper());
            var result = _recipesController.DeleteRecipe(new Guid());

            result.Should().NotBeNull();
            var res = (Microsoft.AspNetCore.Mvc.BadRequestObjectResult)result;

            res.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
        }
Ejemplo n.º 6
0
        public async Task TestDeleteRecipe()
        {
            using (var context = new MyRecipesContext(options))
            {
                string name    = "deleteRecipe";
                Recipe recipe1 = context.Recipe.Where(x => x.Name == recipeNames[0]).Single();
                recipe1.Name = name;

                RecipesController recipeController = new RecipesController(context, configuration);
                IActionResult     okResult         = await recipeController.DeleteRecipe(recipe1.Id) as IActionResult;

                // Assert
                Assert.IsNotNull(okResult);
                Assert.IsInstanceOfType(okResult, typeof(OkObjectResult));
            }
        }
        public void DeleteRecipeTest()
        {
            var recipe = new Recipe()
            {
                Id     = 1,
                UserId = "user1"
            };

            _recipesService.Setup(i => i.DeleteRecipe(1, "user1")).Returns(new MyResponse(true));
            _recipesService.Setup(i => i.GetRecipe(1)).Returns(recipe);

            var result = _recipesController.DeleteRecipe(1).Result;

            _recipesService.Verify(i => i.DeleteRecipe(1, "user1"), Times.Once);

            Assert.IsInstanceOf <ContentResult>(result);
        }
Ejemplo n.º 8
0
        public void DeleteRecipe_InvalidRecipeId_ReturnsNotFound()
        {
            // Arrange
            int invalidRecipeId = 2;

            recipesServiceMock = new Mock <IRecipesService>();
            recipesServiceMock
            .Setup(m => m.GetRecipe(invalidRecipeId))
            .Returns(null as RecipeDto);

            recipesController = new RecipesController(recipesServiceMock.Object, mapper);

            // Act
            var result = recipesController.DeleteRecipe(invalidRecipeId);

            // Assert
            Assert.IsTrue(result.GetType() == typeof(NotFoundResult));
        }
Ejemplo n.º 9
0
        public void DeleteRecipe_ValidRecipeId_ReturnsNoContent()
        {
            // Arrange
            int validRecipeId = 1;

            recipesServiceMock = new Mock <IRecipesService>();
            recipesServiceMock
            .Setup(m => m.GetRecipe(validRecipeId))
            .Returns(new RecipeDto());

            recipesController = new RecipesController(recipesServiceMock.Object, mapper);

            // Act
            var result = recipesController.DeleteRecipe(validRecipeId);

            // Assert
            Assert.IsTrue(result.GetType() == typeof(NoContentResult));
        }
        public async Task DeleteRecipeWithIngredients()
        {
            var options        = _fixture.options;
            var recipesContext = new RecipesContext(options);

            var controller = new RecipesController(recipesContext);

            // add existing ingredients to database
            var ingredientList      = new List <Ingredient>();
            var existingIngredient1 = new Ingredient {
                Name = "Ingredient1", Amount = 100, Unit = "gr"
            };
            var existingIngredient2 = new Ingredient {
                Name = "Ingredient2", Amount = 200, Unit = "kg"
            };

            ingredientList.Add(existingIngredient1);
            ingredientList.Add(existingIngredient2);
            await recipesContext.Ingredients.AddAsync(existingIngredient1);

            await recipesContext.Ingredients.AddAsync(existingIngredient2);

            // add recipe to context
            var existingRecipe = new Recipe
            {
                Description = "existing description", Name = "existing title", Ingredients = ingredientList, Id = 3
            };

            recipesContext.Recipes.Add(existingRecipe);

            await controller.DeleteRecipe(3);

            var deletedRecipe = await recipesContext.Recipes.FindAsync((long)3);

            Assert.Null(deletedRecipe);
            var ingredient1 = await recipesContext.Ingredients.FindAsync(existingIngredient1.Id);

            var ingredient2 = await recipesContext.Ingredients.FindAsync(existingIngredient2.Id);

            Assert.Null(ingredient1);
            Assert.Null(ingredient2);
        }
        public void DeleteRecipe_Returns204NoContent_WhenValidResourceIDSubmitted()
        {
            mockRepo.Setup(repo =>
                           repo.GetRecipeById(1)).Returns(new Recipe
            {
                Id           = 1,
                Title        = "mock",
                Ingredients  = "mock",
                Instructions = "mock",
                Description  = "mock",
                Source       = "mock",
                Rating       = 5,
                PrepTime     = "mock",
                ImageURL     = "sampleURL.com/image.jpg"
            });
            var controller = new RecipesController(mockRepo.Object, mapper);
            var result     = controller.DeleteRecipe(1);

            Assert.IsType <NoContentResult>(result);
        }
        public async Task DeleteRecipeWithoutIngredients()
        {
            var options        = _fixture.options;
            var recipesContext = new RecipesContext(options);

            var controller          = new RecipesController(recipesContext);
            var emptyIngredientList = new List <Ingredient>();


            // add recipe to context
            var existingRecipe = new Recipe
            {
                Description = "existing description", Name = "existing title", Ingredients = emptyIngredientList, Id = 3
            };

            recipesContext.Recipes.Add(existingRecipe);

            await controller.DeleteRecipe(3);

            var deletedRecipe = await recipesContext.Recipes.FindAsync((long)3);

            Assert.Null(deletedRecipe);
        }