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

            // test-values that should be returned by DataAccessLayer
            _user1 = new User()
            {
                UserID = 1000, Profile = new Profile()
                {
                    ProfileID = 1
                }
            };
            _user2 = new User()
            {
                UserID = 1337, Profile = new Profile()
                {
                    ProfileID = 2
                }
            };
            _userList = new List <User>()
            {
                _user1, _user2
            };

            // setup the mocked DataAccessLayer object
            _DALcontextMock.Setup(context => context.User.GetAll()).Returns(_userList);
            _DALcontextMock.Setup(context => context.User.GetById(_user1.UserID)).Returns(_user1);
            _DALcontextMock.Setup(context => context.User.GetById(_user2.UserID)).Returns(_user2);

            // instantiate the BusinessLayerContext with the mocked object of the DataAccessLayer
            _BLLcontext = new BLLContext(_DALcontextMock.Object);
        }
        public void Init()
        {
            _DALcontextMock = new Mock <IDALContext>();

            // initialise the user for the vital data
            _vitalDataUser = new User()
            {
                UserID = 1337,
            };

            // test-values that should be returned by DataAccessLayer
            _vitalData1 = new VitalData()
            {
                Date = DateTime.Now, UserID = _vitalDataUser.UserID, VitalID = 1
            };
            _vitalData2 = new VitalData()
            {
                Date = DateTime.Now.AddDays(1), UserID = _vitalDataUser.UserID, VitalID = 2
            };
            _vitalDataList = new List <VitalData> {
                _vitalData1, _vitalData2
            };

            // setup the mocked DataAccessLayer object
            _DALcontextMock.Setup(context => context.VitalData.GetAll()).Returns(_vitalDataList);

            // instantiate the BusinessLayerContext with the mocked object of the DataAccessLayer
            _BLLcontext = new BLLContext(_DALcontextMock.Object);
        }
        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);
        }
Exemple #4
0
        public void Init()
        {
            _DALcontextMock = new Mock <IDALContext>();

            // initialise the user data for the activity logs
            _nutritionLogUser = new User()
            {
                UserID = 1337,
            };

            // test-values that should be returned by DataAccessLayer
            _food = new Food()
            {
                FoodID       = 2,
                Name         = "Food1",
                KiloCalories = 10m,
                Carbohydrate = 10m,
                Protein      = 10m,
                Fat          = 10m,
                Sugar        = 10m,
                Saturates    = 10m,
                Salt         = 10m
            };

            _nutritionLogList = new List <NutritionLog>
            {
                new NutritionLog()
                {
                    NLID     = 1,
                    FoodID   = _food.FoodID,
                    Food     = _food,
                    Quantity = 5m,
                    Date     = DateTime.Now,
                    User     = _nutritionLogUser,
                    UserID   = _nutritionLogUser.UserID
                },
                new NutritionLog()
                {
                    NLID     = 3,
                    FoodID   = _food.FoodID,
                    Food     = _food,
                    Quantity = 15m,
                    Date     = DateTime.Now.AddDays(1),
                    User     = _nutritionLogUser,
                    UserID   = _nutritionLogUser.UserID
                },
            };

            // setup the mocked DataAccessLayer object
            _DALcontextMock.Setup(context => context.NutritionLog.GetAll()).Returns(_nutritionLogList);

            // instantiate the BusinessLayerContext with the mocked object of the DataAccessLayer
            _BLLcontext = new BLLContext(_DALcontextMock.Object);
        }
Exemple #5
0
        public void Init()
        {
            _DALcontextMock          = new Mock <IDALContext>();
            _DALcontextVitalDataMock = new Mock <IDALContext>();

            // initialise the user data for the activity logs
            _activityLogUser = new User()
            {
                UserID       = 1337,
                ActivityLogs = _activityLogList,
            };
            VitalData weigth = new VitalData()
            {
                VitalID    = 1,
                UserID     = _activityLogUser.UserID,
                Date       = DateTime.Now.AddDays(-10),
                BodyHeight = 180,
                BodyWeight = 100m,
                User       = _activityLogUser
            };

            _vitalData = new List <VitalData>()
            {
                weigth
            };
            _activityLogUser.VitalDatas = _vitalData;

            // test-values that should be returned by DataAccessLayer
            activity = new Activity()
            {
                ActID = 1, Name = "Activity1", MET = 10.5m
            };
            _activityLogList = new List <ActivityLog>
            {
                new ActivityLog {
                    Activity = activity, Date = DateTime.Now, Duration = 30, User = _activityLogUser, UserID = _activityLogUser.UserID
                },
                new ActivityLog {
                    Activity = activity, Date = DateTime.Now.AddHours(1), Duration = 30, User = _activityLogUser, UserID = _activityLogUser.UserID
                },
                new ActivityLog {
                    Activity = activity, Date = DateTime.Now.AddDays(1), Duration = 30, User = _activityLogUser, UserID = _activityLogUser.UserID
                }
            };

            // setup the mocked DataAccessLayer object
            _DALcontextMock.Setup(context => context.ActivityLog.GetAll()).Returns(_activityLogList);
            _DALcontextMock.Setup(context => context.VitalData.GetAll()).Returns(_vitalData);

            // instantiate the BusinessLayerContext with the mocked object of the DataAccessLayer
            _BLLcontext = new BLLContext(_DALcontextMock.Object);
        }
        public void Init()
        {
            _DALcontextMock = new Mock <IDALContext>();

            // test-values that should be returned by DataAccessLayer
            _foodList = new List <Food>
            {
                new Food {
                    FoodID = 123, Name = "TestFoodToBeDeleted", IsDeleted = false
                },
                new Food {
                    FoodID = 456, Name = "TestFood"
                }
            };

            // setup the mocked DataAccessLayer object
            _DALcontextMock.Setup(context => context.Food.GetAll()).Returns(_foodList);

            // instantiate the BusinessLayerContext with the mocked object of the DataAccessLayer
            _BLLcontext = new BLLContext(_DALcontextMock.Object);
        }
        public void Init()
        {
            _DALcontextMock = new Mock <IDALContext>();

            // test-values that should be returned by DataAccessLayer
            _portionList = new List <Portion>
            {
                new Portion()
                {
                    PortionID = 1, Name = "portionNumerOne"
                },
                new Portion()
                {
                    PortionID = 2, Name = "portionNumberTwo"
                }
            };

            // setup the mocked DataAccessLayer object
            _DALcontextMock.Setup(context => context.Portion.GetAll()).Returns(_portionList);

            // instantiate the BusinessLayerContext with the mocked object of the DataAccessLayer
            _BLLcontext = new BLLContext(_DALcontextMock.Object);
        }
        public void Init()
        {
            _DALcontextMock = new Mock <IDALContext>();

            // test-values that should be returned by DataAccessLayer
            _activityList = new List <Activity>
            {
                new Activity()
                {
                    Name = "TestActivityToBeDeleted", IsDeleted = false
                },
                new Activity()
                {
                    Name = "TestActivity"
                }
            };

            // setup the mocked DataAccessLayer object
            _DALcontextMock.Setup(context => context.Activity.GetAll()).Returns(_activityList);

            // instantiate the BusinessLayerContext with the mocked object of the DataAccessLayer
            _BLLcontext = new BLLContext(_DALcontextMock.Object);
        }
Exemple #9
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();
        }