예제 #1
0
        public void ShouldFailToRemoveMealFromDietTwice()
        {
            Diet diet = GetNewDiet();
            Meal meal = diet.AddMeal("Breakfast", "A faster breakfast", new Time(9, 0, 0));

            diet.RemoveMeal(meal);
            diet.RemoveMeal(meal);

            Assert.IsFalse(diet.IsValid);
            Assert.AreEqual("A lista de refeições dessa dieta não contém essa refeição.", diet.GetNotifications().FirstOrDefault().Description);
        }
예제 #2
0
        public void ShouldAddAndRemoveMealFromDiet()
        {
            Diet diet = GetNewDiet();
            Meal meal = diet.AddMeal("Breakfast", "A faster breakfast", new Time(9, 0, 0));

            diet.RemoveMeal(meal);

            Assert.AreEqual(0, diet.MealCount);
        }
예제 #3
0
        public void ShouldRecalculateDietTotalMacrosOnRemoveMeal()
        {
            Diet diet = GetNewDiet();
            Meal meal = diet.AddMeal("Breakfast", "A faster breakfast", new Time(9, 0, 0));
            Food food = new Food("Peito de Frango", "Peito de Frango cozido", Guid.NewGuid(), new MacronutrientTable(20, 48, 21), MicronutrientTable.Default(), new FoodUnit(UnitType.Grams, 1));

            meal.AddMealFood(new MealFood(food, 1));

            diet.RecalculateDietTotalMacros();

            Assert.AreEqual(20, diet.TotalMacronutrients.Carbohydrate);
            Assert.AreEqual(48, diet.TotalMacronutrients.Protein);
            Assert.AreEqual(21, diet.TotalMacronutrients.Fat);

            diet.RemoveMeal(meal);

            Assert.AreEqual(0, diet.TotalMacronutrients.Carbohydrate);
            Assert.AreEqual(0, diet.TotalMacronutrients.Protein);
            Assert.AreEqual(0, diet.TotalMacronutrients.Fat);
        }
예제 #4
0
        public async Task <CommandResult> Handle(RemoveDietMealCommand request, CancellationToken cancellationToken)
        {
            Diet diet = await _dietRepository.GetByIdAsync(request.DietId);

            if (!FoundValidDiet(diet))
            {
                return(FailureDueToDietNotFound());
            }

            Meal meal = diet.FindMeal(request.DietMealId);

            diet.RemoveMeal(meal);
            if (!diet.IsValid)
            {
                return(FailureDueToEntityStateInconsistency(diet));
            }

            await _mealRepository.RemoveAsync(meal);

            await _dietRepository.UpdateAsync(diet);

            return(await CommitAndPublishDefaultAsync());
        }