public void Init()
        {
            _DALcontextMock = new Mock <IDALContext>();

            // test-values that should be returned by DataAccessLayer
            _user = new User()
            {
                UserID = 1337, Birthday = new DateTime(1985, 01, 02), ActivityLevel = 1, Sex = 1
            };
            _vitalData = new VitalData()
            {
                BodyHeight = 180, BodyWeight = 90
            };
            _nutritionAggregation = new NutrientAggregation()
            {
                KiloCalories = 2000m,
                Carbohydrate = 10m,
                Protein      = 20m,
                Fat          = 30m,
                Sugar        = 0m,
                Salt         = 13.37m
            };
            _profile1 = new Profile()
            {
                ProfileID = 123,
                Name      = "TestProfileToBeDeleted",
                IsDeleted = false
            };
            _profile2 = new Profile()
            {
                ProfileID = 456,
                Name      = "TestProfile",
                Users     = new List <User>()
                {
                    _user
                },
                TV_Calories     = _nutritionAggregation.KiloCalories,
                TV_Carbohydrate = 15.5897m,
                TV_Protein      = _nutritionAggregation.Protein,
                TV_Fat          = _nutritionAggregation.Fat,
                TV_Sugar        = _nutritionAggregation.Sugar,
                TV_Salt         = _nutritionAggregation.Salt
            };
            _profileList = new List <Profile>()
            {
                _profile1, _profile2
            };

            // setup the mocked DataAccessLayer object
            _DALcontextMock.Setup(context => context.Profile.GetAll()).Returns(_profileList);
            _DALcontextMock.Setup(context => context.Profile.GetById(_profile1.ProfileID)).Returns(_profile1);
            _DALcontextMock.Setup(context => context.Profile.GetById(_profile2.ProfileID)).Returns(_profile2);

            // instantiate the BusinessLayerContext with the mocked object of the DataAccessLayer
            _BLLcontext = new BLLContext(_DALcontextMock.Object);
        }
Exemplo n.º 2
0
        public void ReturnNutritionAggregationForSpecificDate()
        {
            // arrange results for today
            decimal             quantityToday  = _nutritionLogList[0].Quantity + _nutritionLogList[1].Quantity;
            NutrientAggregation resultForToday = new NutrientAggregation()
            {
                KiloCalories = Math.Round(_food.KiloCalories / 100 * quantityToday),
                Carbohydrate = Math.Round(_food.Carbohydrate / 100 * quantityToday),
                Protein      = Math.Round(_food.Protein / 100 * quantityToday),
                Salt         = Math.Round((decimal)_food.Salt / 100 * quantityToday),
                Sugar        = Math.Round(_food.Sugar / 100 * quantityToday),
                Saturates    = Math.Round((decimal)_food.Saturates / 100 * quantityToday),
                Fat          = Math.Round(_food.Fat / 100 * quantityToday),
                Date         = DateTime.Now
            };

            // arrange results for tomorrow
            decimal             quantityTomorrow  = _nutritionLogList[1].Quantity;
            NutrientAggregation resultForTomorrow = new NutrientAggregation()
            {
                KiloCalories = Math.Round(_food.KiloCalories / 100 * quantityTomorrow),
                Carbohydrate = Math.Round(_food.Carbohydrate / 100 * quantityTomorrow),
                Protein      = Math.Round(_food.Protein / 100 * quantityTomorrow),
                Salt         = Math.Round((decimal)_food.Salt / 100 * quantityTomorrow),
                Sugar        = Math.Round(_food.Sugar / 100 * quantityTomorrow),
                Saturates    = Math.Round((decimal)_food.Saturates / 100 * quantityTomorrow),
                Fat          = Math.Round(_food.Fat / 100 * quantityTomorrow),
                Date         = DateTime.Now.AddDays(1)
            };


            // act
            var nutritionAggregationForToday    = _BLLcontext.NutritionLog.GetNutritionAggregationForSpecificDate(_nutritionLogUser.UserID, DateTime.Now);
            var nutritionAggregationForTomorrow = _BLLcontext.NutritionLog.GetNutritionAggregationForSpecificDate(_nutritionLogUser.UserID, DateTime.Now.AddDays(1));

            // assert today
            Assert.AreEqual(resultForToday.Date.ToShortDateString(), nutritionAggregationForToday.Date.ToShortDateString());

            // assert tomorrow
            Assert.AreEqual(resultForTomorrow.Date.ToShortDateString(), nutritionAggregationForTomorrow.Date.ToShortDateString());
            Assert.AreEqual(resultForTomorrow.KiloCalories, nutritionAggregationForTomorrow.KiloCalories);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Draw the chart of a specific date.
        /// </summary>
        /// <param name="selectedDate">The date for which the chart should be drawn.</param>
        private void draw_chSpecificDate(DateTime selectedDate)
        {
            NutrientAggregation nutritionAggregationOfSpecificDate = (from f in _nutritionAggregationByUser
                                                                      where f.Date.Date == selectedDate.Date
                                                                      select f).FirstOrDefault();

            // Validate if entry for the selectedDate exists
            lb_error.Text = "";
            if (nutritionAggregationOfSpecificDate == null)
            {
                lb_error.Text = "Für das ausgewählte Datum existiert kein Eintrag!";
            }

            // If an entry exists continue drawing the chart
            if (nutritionAggregationOfSpecificDate != null)
            {
                NutrientAggregation targetValuesOfSpecificDate = getTargetValuesOfSpecificDate(selectedDate);

                // Convert to double Array
                double[] parse =
                {
                    Math.Round(Convert.ToDouble(nutritionAggregationOfSpecificDate.Carbohydrate)),
                    Math.Round(Convert.ToDouble(nutritionAggregationOfSpecificDate.Protein)),
                    Math.Round(Convert.ToDouble(nutritionAggregationOfSpecificDate.Fat)),
                    Math.Round(Convert.ToDouble(nutritionAggregationOfSpecificDate.Sugar))
                };
                double[] soll =
                {
                    Math.Round((Double)targetValuesOfSpecificDate.Carbohydrate),
                    Math.Round((Double)targetValuesOfSpecificDate.Protein),
                    Math.Round((Double)targetValuesOfSpecificDate.Fat),
                    Math.Round((Double)targetValuesOfSpecificDate.Sugar)
                };

                // DataBinding
                chSpecificDate.Series[0].Points.DataBindY(parse);
                chSpecificDate.Series[1].Points.DataBindY(soll);

                // Set Title
                chSpecificDate.Titles[0].Text = "Kalorien an diesem Tag: " + (int)nutritionAggregationOfSpecificDate.KiloCalories + " Soll-Wert: " + (int)targetValuesOfSpecificDate.KiloCalories;
            }
        }
Exemplo n.º 4
0
        private NutrientAggregation getTargetValuesOfSpecificDate(DateTime date)
        {
            // TargetValues according to Profile stored in the nutrtionLog at the specified Date
            int profileId = _nutritionLogByUser.Where(n => n.Date.Date == date.Date).Select(n => n.ProfileID).FirstOrDefault();

            if (profileId == 0)
            {
                profileId = _previousId;
            }
            else
            {
                _previousId = profileId;
            }

            NutrientAggregation targeValues = _context.Profile.GetTargetValuesById(profileId);

            // Bonus KiloCaloriesgain gain tue do Activity at the specified Date
            decimal kiloCaloriesActivity = _context.ActivityLog.GetKiloCaloriesForSpecificDate(Program.CURRENT_USER.UserID, date).KiloCalories;

            // Adjust Target Values
            if (kiloCaloriesActivity > 0)
            {
                targeValues.KiloCalories += Math.Round(kiloCaloriesActivity);
                targeValues.Carbohydrate += Math.Round(kiloCaloriesActivity * (decimal)0.09);
                targeValues.Protein      += Math.Round(kiloCaloriesActivity * (decimal)0.025);
                targeValues.Fat          += Math.Round(kiloCaloriesActivity * (decimal)0.025);
                targeValues.Sugar        += Math.Round(kiloCaloriesActivity * (decimal)0.045);
            }

            return(new NutrientAggregation
            {
                KiloCalories = targeValues.KiloCalories,
                Carbohydrate = targeValues.Carbohydrate,
                Protein = targeValues.Protein,
                Fat = targeValues.Fat,
                Sugar = targeValues.Sugar,
                Salt = targeValues.Salt,
                Date = date
            });
        }
Exemplo n.º 5
0
        /// <summary>
        /// This method updates the Main View.
        /// </summary>
        /// <param name="date">The Date for which the MainView should be displayed.</param>
        private void UpdateMainView(DateTime date)
        {
            // Changes within DialogViews won't be accepted unless the BLLContext gets initiated new.
            _context      = new BLLContext();
            _nutritionLog = _context.NutritionLog.GetNutritionLogByUserIdAndDate(Program.CURRENT_USER.UserID, date).ToList();
            _nutritionLog = FilterDisplayedDaytimes(_nutritionLog).ToList();
            _activityLog  = _context.ActivityLog.GetActivityLogByUserIdAndDate(Program.CURRENT_USER.UserID, date).ToList();

            IList <ShowNutritionLog> foodToBeShown       = Tools.ConvertToShowNutritionLog(_nutritionLog);
            IList <ShowActivityLog>  activitiesToBeShown = Tools.ConvertToShowActivityLog(_activityLog);

            // DataBind/Update DataGridView
            dgv_nutritionLog.DataSource = null;
            dgv_nutritionLog.DataSource = foodToBeShown;
            dgv_activityLog.DataSource  = null;
            dgv_activityLog.DataSource  = activitiesToBeShown;

            // Set Width
            dgv_nutritionLog.RowHeadersWidth  = 102;
            dgv_nutritionLog.Columns[0].Width = 50;
            dgv_nutritionLog.Columns[1].Width = 150;
            dgv_nutritionLog.Columns[2].Width = 90;
            dgv_nutritionLog.Columns[3].Width = 90;
            dgv_nutritionLog.Columns[4].Width = 50;
            dgv_nutritionLog.Columns[5].Width = 50;
            dgv_nutritionLog.Columns[6].Width = 50;

            dgv_activityLog.RowHeadersWidth  = 50;
            dgv_activityLog.Columns[0].Width = 180;
            dgv_activityLog.Columns[1].Width = 100;
            dgv_activityLog.Columns[2].Width = 100;
            dgv_activityLog.Columns[3].Width = 200;

            // Set HeaderCells in Dgv (Breakfest, Lunch, Dinner and Snack)
            SetDaytimeHeaderCells(foodToBeShown);

            // Update Nutrient TextBoxes below the Dgv with nutrient day values and target values from the user's profile.
            try
            {
                NutrientAggregation targetValues = _context.Profile.GetTargetValuesById(_nutritionLog.Select(n => n.ProfileID).LastOrDefault());

                // Reset TextBoxes
                tb_kcal_show.Text    = ""; tb_kcal_show.BackColor = Color.White;
                tb_carb_show.Text    = ""; tb_carb_show.BackColor = Color.White;
                tb_protein_show.Text = ""; tb_protein_show.BackColor = Color.White;
                tb_fat_show.Text     = ""; tb_fat_show.BackColor = Color.White;
                tb_sugar_show.Text   = ""; tb_sugar_show.BackColor = Color.White;
                tb_salt_show.Text    = ""; tb_salt_show.BackColor = Color.White;

                // Update Nutrient TextBoxes
                tb_kcal_show.Text    = Math.Round(_nutritionLog.Select(f => (f.Food.KiloCalories) / 100 * f.Quantity).Sum()).ToString() + " / " + Math.Round(targetValues.KiloCalories);
                tb_carb_show.Text    = Math.Round(_nutritionLog.Select(f => (f.Food.Carbohydrate) / 100 * f.Quantity).Sum()).ToString() + " / " + Math.Round(targetValues.Carbohydrate);
                tb_protein_show.Text = Math.Round(_nutritionLog.Select(f => (f.Food.Protein) / 100 * f.Quantity).Sum()).ToString() + " / " + Math.Round(targetValues.Protein);
                tb_fat_show.Text     = Math.Round(_nutritionLog.Select(f => (f.Food.Fat) / 100 * f.Quantity).Sum()).ToString() + " / " + Math.Round(targetValues.Fat);
                tb_sugar_show.Text   = Math.Round(_nutritionLog.Select(f => (f.Food.Sugar) / 100 * f.Quantity).Sum()).ToString() + " / " + Math.Round(targetValues.Sugar);
                tb_salt_show.Text    = Math.Round((Decimal)_nutritionLog.Select(f => (f.Food.Salt) / 100 * f.Quantity).Sum()).ToString() + " / " + Math.Round((Decimal)targetValues.Salt);

                // Mark as red, if value extends target value in profile
                if (_nutritionLog.Select(f => (f.Food.KiloCalories) / 100 * f.Quantity).Sum() > targetValues.KiloCalories)
                {
                    tb_kcal_show.BackColor = Color.LightCoral;
                }
                if (_nutritionLog.Select(f => (f.Food.Carbohydrate) / 100 * f.Quantity).Sum() > targetValues.Carbohydrate)
                {
                    tb_carb_show.BackColor = Color.LightCoral;
                }
                if (_nutritionLog.Select(f => (f.Food.Protein) / 100 * f.Quantity).Sum() > targetValues.Protein)
                {
                    tb_protein_show.BackColor = Color.LightCoral;
                }
                if (_nutritionLog.Select(f => (f.Food.Fat) / 100 * f.Quantity).Sum() > targetValues.Fat)
                {
                    tb_fat_show.BackColor = Color.LightCoral;
                }
                if (_nutritionLog.Select(f => (f.Food.Sugar) / 100 * f.Quantity).Sum() > targetValues.Sugar)
                {
                    tb_sugar_show.BackColor = Color.LightCoral;
                }
                if (_nutritionLog.Select(f => (f.Food.Salt) / 100 * f.Quantity).Sum() > targetValues.Salt)
                {
                    tb_salt_show.BackColor = Color.LightCoral;
                }
            }
            catch
            {
                // No NutritionLog for that date
                // Reset TextBoxes
                tb_kcal_show.Text    = ""; tb_kcal_show.BackColor = Color.White;
                tb_carb_show.Text    = ""; tb_carb_show.BackColor = Color.White;
                tb_protein_show.Text = ""; tb_protein_show.BackColor = Color.White;
                tb_fat_show.Text     = ""; tb_fat_show.BackColor = Color.White;
                tb_sugar_show.Text   = ""; tb_sugar_show.BackColor = Color.White;
                tb_salt_show.Text    = ""; tb_salt_show.BackColor = Color.White;
            }

            //// Update SideStatistics
            // Reset TextBoxes
            tb_show_basic.Text    = "";
            tb_show_activity.Text = "";
            tb_show_baseNew.Text  = "";

            // Even basic requirements may change due to different vital data entries over the time
            VitalData vitalData            = _context.VitalData.GetVitalDataByUserIdAndDate(Program.CURRENT_USER.UserID, date);
            decimal   basiRequirements     = Tools.GetBasicRequirements(Program.CURRENT_USER, vitalData);
            decimal   kiloCaloriesActivity = _context.ActivityLog.GetKiloCaloriesForSpecificDate(Program.CURRENT_USER.UserID, date).KiloCalories;

            tb_show_basic.Text    = Math.Round(basiRequirements, 2).ToString();
            tb_show_activity.Text = Math.Round(kiloCaloriesActivity, 2).ToString();
            tb_show_baseNew.Text  = Math.Round((basiRequirements + kiloCaloriesActivity), 2).ToString();
        }