Esempio n. 1
0
        public void UpdateRecipe_Success()
        {
            var result = _recipesController.UpdateRecipe(new Guid(), CreateRandomRecipe());
            var res    = (Microsoft.AspNetCore.Mvc.OkObjectResult)result;

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

            Assert.IsType <NotFoundResult>(result);
        }
        public void UpdateRecipe_Test()
        {
            mockRepo.Setup(repo => repo.Recipes.FindByCondition(r => r.Id == It.IsAny <int>())).Returns(GetRecipes());
            mockRepo.Setup(repo => repo.Recipes.Update(GetRecipe()));
            var controllerActionResult = recipeController.UpdateRecipe(It.IsAny <int>());

            Assert.NotNull(controllerActionResult);
            Assert.IsType <ViewResult>(controllerActionResult);
        }
Esempio n. 4
0
        public void UpdateRecipe_Failure()
        {
            _mockService.Setup(s => s.UpdateRecipe(It.IsAny <Guid>(), It.IsAny <Recipe>()))
            .Returns(new RecipeResponse("Bad Request"));
            _recipesController = new RecipesController(_mockService.Object, _logger.Object, _mappingConfig.CreateMapper());
            var result = _recipesController.UpdateRecipe(new Guid(), CreateRandomRecipe());

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

            res.StatusCode.Should().Be((int)HttpStatusCode.NotFound);
        }
Esempio n. 5
0
        public void UpdateRecipe_ReturnsUnprocessableEntityResult_IfUpdateWasUnsuccessful()
        {
            //Arrange
            var repoMock = new Mock <IRecipesRepository>();

            repoMock.Setup(repo => repo.UpdateRecipe(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>())).Returns(false);
            var controller      = new RecipesController(repoMock.Object);
            var updateRecipeDto = new UpdateRecipeDto();

            //Act
            var result = controller.UpdateRecipe(updateRecipeDto);

            //Assert
            Assert.IsType <UnprocessableEntityResult>(result);
        }
        public void UpdateRecipe_Returns204NoContent_WhenValidObjectSubmitted()
        {
            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.UpdateRecipe(1, new RecipeUpdateDto {
            });

            Assert.IsType <NoContentResult>(result);
        }