CarbonFitness.BusinessLogic.Implementation.UserIngredientBusinessLogic.AddUserIngredient C# (CSharp) Method

AddUserIngredient() public method

public AddUserIngredient ( User user, string ingredientName, int measure, System.DateTime dateTime ) : UserIngredient
user CarbonFitness.Data.Model.User
ingredientName string
measure int
dateTime System.DateTime
return CarbonFitness.Data.Model.UserIngredient
        public UserIngredient AddUserIngredient(User user, string ingredientName, int measure, DateTime dateTime)
        {
            var userIngredient = new UserIngredient();
            userIngredient.User = user;
            userIngredient.Ingredient = GetExistingIngredient(ingredientName);
            userIngredient.Measure = measure;
            userIngredient.Date = dateTime.AddSeconds(1); // Otherwise it will show up on both today and yesterday
            return userIngredientRepository.SaveOrUpdate(userIngredient);
        }

Usage Example

        public void shouldAddUserIngredient()
        {
            var measure = 100;
            var ingredientName = "Pannbiff";
            var ingredientMock = new Mock<Ingredient>();

            ingredientMock.Setup(x => x.Id).Returns(1);
            ingredientMock.Setup(x => x.Name).Returns(ingredientName);

            var userIngredientRepositoryMock = new Mock<IUserIngredientRepository>();
            var ingredientRepositoryMock = new Mock<IIngredientRepository>();
            userIngredientRepositoryMock.Setup(x => x.SaveOrUpdate(It.Is<UserIngredient>(y => y.Ingredient.Name == ingredientName && y.Ingredient.Id > 0 && y.Measure == measure && y.Date == todaysDate.AddSeconds(1)))).Returns(new UserIngredient());
            ingredientRepositoryMock.Setup(x => x.Get(ingredientName)).Returns(ingredientMock.Object);

            var userIngredientLogic = new UserIngredientBusinessLogic(userIngredientRepositoryMock.Object, ingredientRepositoryMock.Object, null);
            userIngredientLogic.AddUserIngredient(new User(), ingredientName, measure, todaysDate);

            userIngredientRepositoryMock.VerifyAll();
            ingredientRepositoryMock.VerifyAll();
        }
All Usage Examples Of CarbonFitness.BusinessLogic.Implementation.UserIngredientBusinessLogic::AddUserIngredient