Esempio n. 1
0
        private async Task RecalculateDietTotalMacrosAsync(Guid dietId)
        {
            Diet diet = await _dietRepository.GetByIdAsync(dietId);

            diet.RecalculateDietTotalMacros();

            await _dietRepository.UpdateAsync(diet);

            await CommitAsync();
        }
Esempio n. 2
0
        public void ShouldRecalculateDietTotalMacros()
        {
            Diet     diet     = GetNewDiet();
            Meal     meal     = diet.AddMeal("Breakfast", "A faster breakfast", new Time(9, 0, 0));
            FoodUnit foodUnit = new FoodUnit(UnitType.Grams, 1);
            Food     food     = new Food("Peito de Frango", "Peito de Frango cozido", Guid.NewGuid(), new MacronutrientTable(0, 24, 2), MicronutrientTable.Default(), foodUnit);
            Food     foodTwo  = new Food("Brócolis", "Brócolis Verde", Guid.NewGuid(), new MacronutrientTable(6, 2, 0), MicronutrientTable.Default(), foodUnit);

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

            diet.RecalculateDietTotalMacros();

            Assert.AreEqual(6, diet.TotalMacronutrients.Carbohydrate);
            Assert.AreEqual(26, diet.TotalMacronutrients.Protein);
            Assert.AreEqual(2, diet.TotalMacronutrients.Fat);
        }
Esempio n. 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);
        }