Esempio n. 1
0
        public void CreateIngredient_WithValidationError_ReturnsBadRequestResult()
        {
            // Arrange
            ingredientsServiceMock = new Mock <IIngredientsService>();
            ingredientsController  = new IngredientsController(ingredientsServiceMock.Object, mapper);
            ingredientsController.ModelState.AddModelError("Some Key", "Some Error Message");

            // Act
            var result = ingredientsController.CreateIngredient(new IngredientForCreationDto());

            // Assert
            Assert.IsTrue(result.GetType() == typeof(BadRequestObjectResult));
        }
Esempio n. 2
0
        public void CreateIngredient_WithNameAndDescription_ReturnsCreatedResult()
        {
            // Arrange
            ingredientsServiceMock = new Mock <IIngredientsService>();
            ingredientsServiceMock
            .Setup(m => m.Insert(It.IsAny <IngredientDto>()))
            .Returns(1);
            ingredientsController = new IngredientsController(ingredientsServiceMock.Object, mapper);

            var ingredientForCreation = new IngredientForCreationDto
            {
                Name        = "Cooking is fun",
                Description = "You should cook the meal"
            };

            // Act
            var result = ingredientsController.CreateIngredient(ingredientForCreation);

            // Assert
            Assert.IsTrue(result.GetType() == typeof(CreatedAtRouteResult));
        }
Esempio n. 3
0
        public void CreateIngredient_SomethinWentWrongWhileInserting_Returns500InternalServerError()
        {
            // Arrange
            ingredientsServiceMock = new Mock <IIngredientsService>();
            ingredientsServiceMock
            .Setup(m => m.Insert(It.IsAny <IngredientDto>()))
            .Returns(0);
            ingredientsController = new IngredientsController(ingredientsServiceMock.Object, mapper);

            var ingredientForCreation = new IngredientForCreationDto
            {
                Name        = "Black Pepper",
                Description = "Black Pepper is spicy and thus healthy"
            };

            // Act
            var result = ingredientsController.CreateIngredient(ingredientForCreation);

            // Assert
            Assert.IsTrue(result.GetType() == typeof(StatusCodeResult));
            Assert.IsTrue(((StatusCodeResult)result).StatusCode == StatusCodes.Status500InternalServerError);
        }