Exemple #1
0
        public async Task GetAmountIngrediets_Should_Count()
        {
            // Arrange
            List <AmountIngredient> amountIngredients = new List <AmountIngredient>
            {
                new AmountIngredient()
                {
                    Id           = It.IsAny <int>(),
                    Amount       = It.IsAny <double>(),
                    Unit         = It.IsAny <string>(),
                    IngredientId = It.IsAny <int>(),
                    RecipeId     = It.IsAny <int>()
                },
                new AmountIngredient()
                {
                    Id           = It.IsAny <int>(),
                    Amount       = It.IsAny <double>(),
                    Unit         = It.IsAny <string>(),
                    IngredientId = It.IsAny <int>(),
                    RecipeId     = 2
                },
                new AmountIngredient()
                {
                    Id           = It.IsAny <int>(),
                    Amount       = It.IsAny <double>(),
                    Unit         = It.IsAny <string>(),
                    IngredientId = It.IsAny <int>(),
                    RecipeId     = 2
                },
            };

            repositoryMock.Setup(o => o.GetListWhereAsync(It.IsAny <Expression <Func <AmountIngredient, bool> > >()))
            .ReturnsAsync(amountIngredients.Where(x => x.RecipeId == 2).ToList());

            unitOfWorkMock = new Mock <IUnitOfWork>();
            unitOfWorkMock.Setup(o => o.Repository)
            .Returns(repositoryMock.Object);

            AmountRecipeIngredientsController controller = new AmountRecipeIngredientsController(unitOfWorkMock.Object, optionsMock.Object);
            // Act
            int amountIngredientsCount = (await controller.GetAmountIngredietsAsync(2)).Count;

            // Assert
            Assert.Equal(2, amountIngredientsCount);
        }
Exemple #2
0
        public async Task DeleteAmountIngredient_Should_True()
        {
            // Arrange
            bool isDelete = false;

            repositoryMock.Setup(o => o.DeleteAsync(It.IsAny <AmountIngredient>())).Callback(() => isDelete = true);

            unitOfWorkMock = new Mock <IUnitOfWork>();
            unitOfWorkMock.Setup(o => o.Repository)
            .Returns(repositoryMock.Object);

            AmountRecipeIngredientsController controller = new AmountRecipeIngredientsController(unitOfWorkMock.Object, optionsMock.Object);
            // Act
            await controller.DeleteAsync(It.IsAny <int>());

            // Assert
            Assert.True(isDelete);
        }
Exemple #3
0
        public async Task GetAmountIngredientName_Should_IngredientName()
        {
            // Arrange
            Ingredient ingredient = new Ingredient()
            {
                Id = 1, Name = "Banana"
            };

            repositoryMock.Setup(o => o.GetByIdAsync <Ingredient>(It.IsAny <int>()))
            .ReturnsAsync(ingredient);

            unitOfWorkMock = new Mock <IUnitOfWork>();
            unitOfWorkMock.Setup(o => o.Repository)
            .Returns(repositoryMock.Object);
            // Act
            AmountRecipeIngredientsController controller = new AmountRecipeIngredientsController(unitOfWorkMock.Object, optionsMock.Object);
            string ingredientName = (await controller.GetAmountIngredientNameAsync(It.IsAny <int>()));

            // Assert
            Assert.Equal("Banana", ingredientName);
        }