public void MetricToImperialWeightTests()
        {
            Assert.AreEqual(14.5, MeasurementConverter.ConvertWeight(6.577, MeasurementSystem.Metric, MeasurementSystem.Imperial), .01);

            Assert.AreEqual(18, MeasurementConverter.ConvertWeight(8.164, MeasurementSystem.Metric, MeasurementSystem.Imperial), .01);

            Assert.AreEqual(98.6, MeasurementConverter.ConvertWeight(44.724, MeasurementSystem.Metric, MeasurementSystem.Imperial), .01);
        }
        public void ImperialToMetricWeightTests()
        {
            Assert.AreEqual(6.577, MeasurementConverter.ConvertWeight(14.5, MeasurementSystem.Imperial, MeasurementSystem.Metric), .01);

            Assert.AreEqual(8.164, MeasurementConverter.ConvertWeight(18, MeasurementSystem.Imperial, MeasurementSystem.Metric), .01);

            Assert.AreEqual(44.724, MeasurementConverter.ConvertWeight(98.6, MeasurementSystem.Imperial, MeasurementSystem.Metric), .01);
        }
        public void ConversionBetweenSameSourceAndDestinationTests()
        {
            Assert.AreEqual(18, MeasurementConverter.ConvertWeight(18, MeasurementSystem.Imperial, MeasurementSystem.Imperial), .01);

            Assert.AreEqual(6.577, MeasurementConverter.ConvertWeight(6.577, MeasurementSystem.Metric, MeasurementSystem.Metric), .01);

            Assert.AreEqual(14, MeasurementConverter.ConvertLength(14, MeasurementSystem.Imperial, MeasurementSystem.Imperial), .001);

            Assert.AreEqual(10.16, MeasurementConverter.ConvertLength(10.16, MeasurementSystem.Metric, MeasurementSystem.Metric), .001);
        }
Exemple #4
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();
        }