Esempio n. 1
0
 public static DietIngredient CreateDietIngredient(Diet diet, Ingredient ingredient)
 {
     return new DietIngredient
                {
                    Day = "0,1",
                    Diet = diet,
                    Ingredient = ingredient,
                    IngredientId = ingredient.Id,
                    Quantity = 2,
                    Time = 900,
                    QuantityType = new QuantityType {Id = 3, Name = "Test", IsDeleted = false},
                    QuantityTypeId = 3
                };
 }
 public void TestSetup()
 {
     _diet = ModelCreator.CreateDiet();
     var ingredient1 = ModelCreator.CreateIngredient();
     var ingredient2 = ModelCreator.CreateIngredient();
     ingredient2.Kcal = 200;
     ingredient2.Fat = 24;
     ingredient2.Protein = 44;
     _ingredientRepository.Create(ingredient1);
     _ingredientRepository.Create(ingredient2);
     var meal = ModelCreator.CreateMeal();
     _mealRepository.Create(meal);
     var mealIngredients1 = ModelCreator.CreateMealIngredients(meal, ingredient1, ModelCreator.CreateQuantityType(1));
     var mealIngredients2 = ModelCreator.CreateMealIngredients(meal, ingredient2, ModelCreator.CreateQuantityType(2));
     meal.MealIngredients = new List<MealIngredient> { mealIngredients1, mealIngredients2 };
     var dietMeal = ModelCreator.CreateDietMeal(_diet, meal);
     var dietIngredient = ModelCreator.CreateDietIngredient(_diet, ingredient1);
     _diet.DietIngredients = new List<DietIngredient> { dietIngredient };
     _diet.DietMeals = new List<DietMeal> { dietMeal };
     var dietId = _dietRepository.Create(_diet).Id;
     var ingredientId = _ingredientRepository.Create(ingredient1).Id;
     _dietMealRepository.Create(dietMeal);
     _dietIngredientRepository.Create(dietIngredient);
 }
Esempio n. 3
0
 public static DietMeal CreateDietMeal(Diet diet, Meal meal)
 {
     return new DietMeal {Day = "0,1", Diet = diet, Meal = meal, Time = 540};
 }
Esempio n. 4
0
 public static Diet CreateOatMealDiet()
 {
     var diet = new Diet {Name = "SuperDiett"};
     var dietMeal = new DietMeal {Day = "0,2", Diet = diet, Meal = CreateOatMeal(), Time = 900};
     diet.DietMeals = new List<DietMeal> {dietMeal};
     return diet;
 }
Esempio n. 5
-1
        public DietCalculator(Diet diet, IIngredientQuantityRepository ingredientQuantityRepository, ITracer tracer)
        {
            _diet = diet;
            _ingredientQuantityRepository = ingredientQuantityRepository;
            _tracer = tracer;
            tracer.WriteTrace("Henter ut ingredienser og måltid");
            var ingredients = _diet.DietIngredients.ToList();
            var meals = _diet.DietMeals.ToList();
            foreach (var di in ingredients)
            {
                var quantityConversion = di.Quantity / QuantityConverter.ConvertTo100Grams(di.QuantityTypeId, _ingredientQuantityRepository.GetConvertFactor(di.IngredientId, di.QuantityTypeId)) * di.Day.ToIntArray().Count();
                _totalIngredientCarbsGrams += di.Ingredient.Carb * quantityConversion;
                _totalIngredientFatGrams += di.Ingredient.Fat * quantityConversion;
                _totalIngredientProteinGrams += di.Ingredient.Protein * quantityConversion;
                _totalIngredientKcals += di.Ingredient.Kcal * quantityConversion;
            }

            foreach (var dm in meals)
            {
                var mealDays = dm.Day.ToIntArray().Count();
                var mealCalulator = new MealCalculator(dm.Meal, _ingredientQuantityRepository);
                _totalMealCarbGrams += mealCalulator.CalculateTotalCarb() * mealDays;
                _totalMealFatGrams += mealCalulator.CalculateTotalFat() * mealDays;
                _totalMealProteinGrams += mealCalulator.CalculateTotalProtein() * mealDays;
                _totalMealKcals += mealCalulator.CalculateTotalKcal() * mealDays;
            }

            _totalGrams = _totalIngredientCarbsGrams + _totalIngredientFatGrams + _totalIngredientProteinGrams +
                          _totalMealCarbGrams + _totalMealFatGrams + _totalMealProteinGrams;
            _tracer.WriteTrace("Ferdig med constructor");
        }