示例#1
0
        public void AddIngredientsListItem_ValidInput_ReturnsCreatedResult()
        {
            // Arrange
            int validRecipeId = 1;

            ingredientsListServiceMock = new Mock <IIngredientsListService>();
            ingredientsListServiceMock
            .Setup(m => m.RecipeExists(validRecipeId))
            .Returns(true);
            ingredientsListServiceMock
            .Setup(m => m.UnitExists(It.IsAny <int>()))
            .Returns(true);
            ingredientsListServiceMock
            .Setup(m => m.IngredientExists(It.IsAny <int>()))
            .Returns(true);
            ingredientsListServiceMock
            .Setup(m => m.InsertIngredientsListItem(validRecipeId, It.IsAny <IngredientsListItemForCreationDto>()))
            .Returns(1);
            ingredientsListController = new IngredientsListController(ingredientsListServiceMock.Object);

            // Act
            var result = ingredientsListController.AddIngredientsListItem(validRecipeId, new IngredientsListItemForCreationDto());

            // Assert
            Assert.IsTrue(result.GetType() == typeof(CreatedAtRouteResult));
        }
示例#2
0
        public void AddIngredientsListItem_WithValidationError_ReturnsBadRequestResult()
        {
            // Arrange
            ingredientsListServiceMock = new Mock <IIngredientsListService>();
            ingredientsListController  = new IngredientsListController(ingredientsListServiceMock.Object);
            ingredientsListController.ModelState.AddModelError("Some Key", "Some Error Message");
            int validRecipeId = 1;

            // Act
            var result = ingredientsListController.AddIngredientsListItem(validRecipeId, new IngredientsListItemForCreationDto());

            // Assert
            Assert.IsTrue(result.GetType() == typeof(BadRequestObjectResult));
        }
示例#3
0
        public void GetIngredientsList_InvalidRecipeId_ReturnsNotFound()
        {
            // Arrange
            int invalidRecipeId = 1;

            ingredientsListServiceMock = new Mock <IIngredientsListService>();
            ingredientsListServiceMock
            .Setup(m => m.GetByRecipeId(invalidRecipeId))
            .Returns(null as IngredientsListDto);
            ingredientsListController = new IngredientsListController(ingredientsListServiceMock.Object);

            // Act
            var result = ingredientsListController.GetIngredientsList(invalidRecipeId);

            // Assert
            Assert.IsTrue(result.GetType() == typeof(NotFoundResult));
        }
示例#4
0
        public void GetIngredientsList_ValidRecipeId_ReturnsOk()
        {
            // Arrange
            int validRecipeId = 1;

            ingredientsListServiceMock = new Mock <IIngredientsListService>();
            ingredientsListServiceMock
            .Setup(m => m.GetByRecipeId(validRecipeId))
            .Returns(new IngredientsListDto());
            ingredientsListController = new IngredientsListController(ingredientsListServiceMock.Object);

            // Act
            var result = ingredientsListController.GetIngredientsList(validRecipeId);

            // Assert
            Assert.IsTrue(result.GetType() == typeof(OkObjectResult));
        }
示例#5
0
        public void DeleteIngredient_InvalidId_ReturnsNotFound()
        {
            // Arrange
            int recipeId = 1;
            int invalidIngredientsListItemId = 2;

            ingredientsListServiceMock = new Mock <IIngredientsListService>();
            ingredientsListServiceMock
            .Setup(m => m.IngredientsListItemExists(invalidIngredientsListItemId))
            .Returns(false);

            ingredientsListController = new IngredientsListController(ingredientsListServiceMock.Object);

            // Act
            var result = ingredientsListController.DeleteIngredientsListItem(recipeId, invalidIngredientsListItemId);

            // Assert
            Assert.IsTrue(result.GetType() == typeof(NotFoundResult));
        }
示例#6
0
        public void AddIngredientsListItem_InvalidUnitId_ReturnsBadRequestResult()
        {
            // Arrange
            int validRecipeId = 1;
            int invalidUnitId = 5;

            ingredientsListServiceMock = new Mock <IIngredientsListService>();
            ingredientsListServiceMock
            .Setup(m => m.UnitExists(invalidUnitId))
            .Returns(false);
            ingredientsListController = new IngredientsListController(ingredientsListServiceMock.Object);

            // Act
            var result = ingredientsListController.AddIngredientsListItem(validRecipeId, new IngredientsListItemForCreationDto()
            {
                UnitId = invalidUnitId
            });

            // Assert
            Assert.IsTrue(result.GetType() == typeof(BadRequestObjectResult));
        }
示例#7
0
        public void AddIngredientsListItem_InvalidRecipeId_ReturnsNotFoundResult()
        {
            // Arrange
            int invalidRecipeId = 2;

            ingredientsListServiceMock = new Mock <IIngredientsListService>();
            ingredientsListServiceMock
            .Setup(m => m.RecipeExists(invalidRecipeId))
            .Returns(false);
            ingredientsListServiceMock
            .Setup(m => m.UnitExists(It.IsAny <int>()))
            .Returns(true);
            ingredientsListServiceMock
            .Setup(m => m.IngredientExists(It.IsAny <int>()))
            .Returns(true);
            ingredientsListController = new IngredientsListController(ingredientsListServiceMock.Object);

            // Act
            var result = ingredientsListController.AddIngredientsListItem(invalidRecipeId, new IngredientsListItemForCreationDto());

            // Assert
            Assert.IsTrue(result.GetType() == typeof(NotFoundResult));
        }