Пример #1
0
        public void FatPercentageForFemaleBasedOffMeasurementsShouldBeAbout25Percent()
        {
            AppUser         appUser         = new AppUser("", "", "", 60, GenderType.Female, MeasurementSystem.Imperial);
            BodyMeasurement bodyMeasurement = new BodyMeasurement(appUser, 10, 30, 30, 60, 60, DateTime.Today, MeasurementSystem.Imperial);
            double          actual          = BodyFatPercentageCalculator.CalculateBodyFatPercentage(bodyMeasurement);

            Assert.AreEqual(25.19, actual, .01);
        }
Пример #2
0
        private void TryEditingMeasurement(CreateOrEditBodyMeasurementRequest request)
        {
            int currentUserId = _userAccessor.GetCurrentUserId();
            Dictionary <string, string> errors = new Dictionary <string, string>();
            AppUser appUser = _bodyFitTrackerContext.AppUsers.Where(x => x.AppUserId == currentUserId).First();

            BodyMeasurement bodyMeasurementToEdit = appUser.BodyMeasurements.Where(x => x.BodyMeasurementId ==
                                                                                   request.IdOfBodyMeasurementToEdit).FirstOrDefault();

            if (bodyMeasurementToEdit == null)
            {
                errors.Add("", $"The bodymeasurement with id {request.IdOfBodyMeasurementToEdit} was not found");
                throw new RestException(HttpStatusCode.NotFound, errors);
            }

            // all measurements in the database should be in imperial units

            MeasurementSystem sourceUnits      = appUser.MeasurementSystemPreference;
            MeasurementSystem destinationUnits = MeasurementSystem.Imperial;

            bodyMeasurementToEdit.NeckCircumference =
                MeasurementConverter.ConvertLength(request.NeckCircumference, sourceUnits, destinationUnits);

            bodyMeasurementToEdit.WaistCircumference =
                MeasurementConverter.ConvertLength(request.WaistCircumference,
                                                   sourceUnits, destinationUnits);

            if (request.HipCircumference.HasValue)
            {
                bodyMeasurementToEdit.HipCircumference =
                    MeasurementConverter.ConvertLength((double)request.HipCircumference, sourceUnits, destinationUnits);
            }
            bodyMeasurementToEdit.Height =
                MeasurementConverter.ConvertLength(request.Height, sourceUnits, destinationUnits);

            bodyMeasurementToEdit.Weight =
                MeasurementConverter.ConvertWeight(request.Weight, sourceUnits, destinationUnits);

            bodyMeasurementToEdit.DateAdded = request.DateAdded;

            bodyMeasurementToEdit.BodyFatPercentage = BodyFatPercentageCalculator.CalculateBodyFatPercentage(bodyMeasurementToEdit);

            _bodyFitTrackerContext.SaveChanges();
        }
Пример #3
0
        /// <summary>
        /// All units are expected to be in the the units parameter
        /// </summary>
        public BodyMeasurement(AppUser appUser, double neckCircumference, double waistCircumference, double?hipCircumference, double height, double weight, DateTime dateAdded, MeasurementSystem units)
        {
            if (appUser == null)
            {
                throw new ArgumentNullException(nameof(appUser));
            }

            if (appUser.Gender == GenderType.Female && hipCircumference == null)
            {
                throw new ArgumentNullException($"{nameof(hipCircumference)} can't be null for {nameof(GenderType.Female)}");
            }

            AppUser            = appUser;
            NeckCircumference  = neckCircumference;
            WaistCircumference = waistCircumference;
            AppUserId          = appUser.AppUserId;
            Weight             = weight;
            DateAdded          = dateAdded;
            HipCircumference   = appUser.Gender == GenderType.Female ? hipCircumference : null;
            Height             = height;
            Units             = units;
            BodyFatPercentage = BodyFatPercentageCalculator.CalculateBodyFatPercentage(this);
        }