public void TestConstructor_PassMeasurement_ShouldSetWeightKgCorrectly(int id, int height, double weightKg, double bodyFatPercent, int chest, int shoulders, int forearm, int arm, int waist, int hips, int thighs, int calves, int neck, int wrist, int ankle) { // Arrange var date = new DateTime(1, 2, 3); var Measurement = new global::Logs.Models.Measurement(height, weightKg, bodyFatPercent, chest, shoulders, forearm, arm, waist, hips, thighs, calves, neck, wrist, ankle, null, date); Measurement.MeasurementsId = id; // Act var model = new MeasurementViewModel(Measurement, date); // Assert Assert.AreEqual(weightKg, model.WeightKg); }
public ActionResult Save(MeasurementViewModel model) { if (this.ModelState.IsValid) { var userId = this.authenticationProvider.CurrentUserId; var measurement = (Measurement)null; if (model.Id.HasValue) { measurement = this.measurementService.EditMeasurement(userId, model.Date, model.Id.Value, model.Height, model.WeightKg, model.BodyFatPercent, model.Chest, model.Shoulders, model.Forearm, model.Arm, model.Waist, model.Hips, model.Thighs, model.Calves, model.Neck, model.Wrist, model.Ankle); } else { measurement = this.measurementService.CreateMeasurement(model.Height, model.WeightKg, model.BodyFatPercent, model.Chest, model.Shoulders, model.Forearm, model.Arm, model.Waist, model.Hips, model.Thighs, model.Calves, model.Neck, model.Wrist, model.Ankle, userId, model.Date); } model = this.factory.CreateMeasurementViewModel(measurement, model.Date); model.SaveResult = Constants.SavedSuccessfully; } return(this.PartialView("Load", model)); }
public void AddMeasurement(MeasurementViewModel measurement) { if (!_channel.Writer.TryWrite(measurement)) { throw new System.Exception("Failed to write measurement to channel"); } }
public void AddTest() { var city = new City("Moscow"); City.AllCities.Add(city); var meas = new MeasurementViewModel(); var client = new Client("Ivanov", "Ivan", 9271112233, city, "Vernadskogo, 23"); var measLimit = new MeasurementLimit(8, 20, 2, city); meas.Clients.Add(client); meas.Limits.Add(measLimit); meas.SelectedClient = meas.Clients.FirstOrDefault(c => c.Id == client.Id); meas.SelectedLimit = meas.Limits.FirstOrDefault(l => l.Id == measLimit.Id); meas.Add(); bool isMeasSave = meas.MeasurementsWithoutDate.FirstOrDefault(m => m.Client.Id == client.Id) != null; ClearData(); Assert.IsTrue(isMeasSave); }
public void RemoveWithOutDateTest() { var city1 = new City("Moscow"); City.AllCities.Add(city1); var client1 = new Client("Ivanov", "Ivan", 9271112233, city1, "Vernadskogo, 23"); Client.AllClients.Add(client1); var measLimit1 = new MeasurementLimit(8, 20, 2, city1); MeasurementLimit.AllMeasurementLimits.Add(measLimit1); var meas = new MeasurementViewModel(); meas.SelectedClient = meas.Clients.FirstOrDefault(c => c.Id == client1.Id); meas.SelectedLimit = meas.Limits.FirstOrDefault(l => l.Id == measLimit1.Id); meas.Add(); meas.SelectedMeasureWithoutDate = meas.MeasurementsWithoutDate.FirstOrDefault(); meas.RemoveWithOutDate(meas.SelectedMeasureWithoutDate); bool isRemoved = !meas.MeasurementsWithoutDate.Any() && !meas.MeasurementsWithDate.Any(); ClearData(); Assert.IsTrue(isRemoved); }
public ActionResult Details(int id) { var measurementViewModel = new MeasurementViewModel { Measurement = BVSBusinessServices.Measurements.GetByID(id), SubMeasurements = new List <SubMeasurementGridViewModel>() }; var SubMeasurements = BVSBusinessServices.SubMeasurements.GetByMeasurementID(id); foreach (SubMeasurement measurement in SubMeasurements) { var u = new SubMeasurementGridViewModel() { ID = measurement.ID, CalculatedVolume = measurement.CalculatedVolume, MeasurementOn = measurement.MeasurementOn, MeasurementID = measurement.MeasurementID, IsVoided = measurement.IsVoided }; measurementViewModel.SubMeasurements.Add(u); } return(View(measurementViewModel)); }
public void TestLoad_ShouldRenderCorrectViewWithModel() { // Arrange var viewModel = new MeasurementViewModel(); var mockedFactory = new Mock <IViewModelFactory>(); mockedFactory.Setup(f => f.CreateMeasurementViewModel(It.IsAny <Measurement>(), It.IsAny <DateTime>())) .Returns(viewModel); var mockedDateTimeProvider = new Mock <IDateTimeProvider>(); var mockedMeasurementService = new Mock <IMeasurementService>(); var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>(); var date = new DateTime(2, 3, 4); var controller = new MeasurementController(mockedAuthenticationProvider.Object, mockedMeasurementService.Object, mockedFactory.Object); // Act, Assert controller .WithCallTo(c => c.Load(date)) .ShouldRenderDefaultPartialView() .WithModel <MeasurementViewModel>(m => Assert.AreSame(viewModel, m)); }
public void TestGetMeasurement_ServiceReturnsMeasurement_ShouldRenderPartialViewWithModel(int id) { // Arrange var date = new DateTime(1, 2, 3); var measurement = new Measurement { Date = date }; var model = new MeasurementViewModel(); var mockedFactory = new Mock <IViewModelFactory>(); mockedFactory.Setup(f => f.CreateMeasurementViewModel(It.IsAny <Measurement>(), It.IsAny <DateTime>())) .Returns(model); var mockedDateTimeProvider = new Mock <IDateTimeProvider>(); var mockedMeasurementService = new Mock <IMeasurementService>(); mockedMeasurementService.Setup(s => s.GetById(It.IsAny <int>())).Returns(measurement); var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>(); var controller = new MeasurementController(mockedAuthenticationProvider.Object, mockedMeasurementService.Object, mockedFactory.Object); // Act, Assert controller .WithCallTo(c => c.GetMeasurement(id)) .ShouldRenderPartialView("MeasurementDetails") .WithModel <MeasurementViewModel>(model); }
public JsonResult Post([FromBody] MeasurementViewModel vm) { try { if (ModelState.IsValid) { var newMeasurement = Mapper.Map <Measurement>(vm); _logger.LogInformation("Saving new measurement..."); _repository.AddMeasurement(User.Identity.Name, newMeasurement); if (_repository.SaveAll()) { Response.StatusCode = (int)HttpStatusCode.Created; return(Json(Mapper.Map <MeasurementViewModel>(newMeasurement))); } } } catch (Exception ex) { _logger.LogError("Failed to save new measurement to the database", ex); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json(new { Message = ex.Message })); } Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json(new { Message = "Failed", ModelState = ModelState })); }
// GET: Measurement public ActionResult Index() { var measurements = _measurementService.Get(); if (measurements.Count == 0) { return(NotFound()); } var view = new List <MeasurementViewModel>(); foreach (var measurement in measurements) { var m = new MeasurementViewModel { Time = measurement.Time, Temperature = measurement.Temperature, AirPressure = measurement.AirPressure, Humidity = measurement.Humidity }; if (measurement.LocalWeatherStation != null) { m.WeatherStationName = measurement.LocalWeatherStation.Name; } view.Add(m); } return(Json(view)); }
public void GetMeasurementsOfDevice() { mock.Setup(m => m.GetMeasurementsOfDevice("token", "user", 1)).Returns(new MeasurementViewModel()); MeasurementViewModel measurements = mock.Object.GetMeasurementsOfDevice("token", "user", 1); Assert.NotNull(measurements); }
public void IsSelectedMeasurementTest() { var city1 = new City("Moscow"); City.AllCities.Add(city1); var client1 = new Client("Ivanov", "Ivan", 9271112233, city1, "Vernadskogo, 23"); Client.AllClients.Add(client1); var measLimit1 = new MeasurementLimit(8, 20, 2, city1); MeasurementLimit.AllMeasurementLimits.Add(measLimit1); var meas = new MeasurementViewModel(); meas.SelectedClient = meas.Clients.FirstOrDefault(c => c.Id == client1.Id); meas.SelectedLimit = meas.Limits.FirstOrDefault(l => l.Id == measLimit1.Id); meas.Add(); meas.SelectedDate = DateTime.Today; meas.SelectedMeasureWithoutDate = meas.MeasurementsWithoutDate.FirstOrDefault(); meas.SetDate(); meas.SelectedMeasureWithDate = null; meas.SelectedMeasureWithDate = meas.MeasurementsWithDate.FirstOrDefault(); bool selected = meas.SelectedMeasureWithDate != null; ClearData(); Assert.IsTrue(selected); }
public static void From(this MeasurementViewModel thisViewModel, MeasurementViewModel otherViewModel) { thisViewModel.Baby = otherViewModel.Baby; thisViewModel.CreatedAt = otherViewModel.CreatedAt; thisViewModel.Id = otherViewModel.Id; thisViewModel.Length = otherViewModel.Length; thisViewModel.Weight = otherViewModel.Weight; }
private void DefaultViewModel_MeasurementCreated(MeasurementViewModel sender, string args) { Frame.BackStack.RemoveAt(0); if (!Frame.Navigate(typeof(MainPage), Constants.NAVIGATION_PARAMETER_CLEARLASTBACKENTRY)) { throw new Exception("Failed to create navigate home after creating measurement"); } }
public void TestSave_ModelStateIsNotValid_ShouldRenderCorrectPartialViewWithModel(int height, double weightKg, double bodyFatPercent, int chest, int shoulders, int forearm, int arm, int waist, int hips, int thighs, int calves, int neck, int wrist, int ankle, string userId) { // Arrange, var date = new DateTime(2, 3, 4); var model = new MeasurementViewModel { Date = date, Height = height, WeightKg = weightKg, BodyFatPercent = bodyFatPercent, Chest = chest, Shoulders = shoulders, Forearm = forearm, Arm = arm, Waist = waist, Hips = hips, Thighs = thighs, Calves = calves, Neck = neck, Wrist = wrist, Ankle = ankle }; var mockedFactory = new Mock <IViewModelFactory>(); var mockedDateTimeProvider = new Mock <IDateTimeProvider>(); var mockedMeasurementService = new Mock <IMeasurementService>(); var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>(); var controller = new MeasurementController(mockedAuthenticationProvider.Object, mockedMeasurementService.Object, mockedFactory.Object); controller.ModelState.AddModelError("", ""); // Act controller.Save(model); // Assert controller .WithCallTo(c => c.Save(model)) .ShouldRenderPartialView("Load") .WithModel <MeasurementViewModel>(m => Assert.AreSame(model, m)); }
public void TestSave_ModelStateIsValid_ShouldCallAuthenticationProviderCurrentUserId(int height, double weightKg, double bodyFatPercent, int chest, int shoulders, int forearm, int arm, int waist, int hips, int thighs, int calves, int neck, int wrist, int ankle, string userId) { // Arrange, var date = new DateTime(2, 3, 4); var model = new MeasurementViewModel { Date = date, Height = height, WeightKg = weightKg, BodyFatPercent = bodyFatPercent, Chest = chest, Shoulders = shoulders, Forearm = forearm, Arm = arm, Waist = waist, Hips = hips, Thighs = thighs, Calves = calves, Neck = neck, Wrist = wrist, Ankle = ankle }; var mockedFactory = new Mock <IViewModelFactory>(); mockedFactory.Setup(f => f.CreateMeasurementViewModel(It.IsAny <Measurement>(), It.IsAny <DateTime>())) .Returns(model); var mockedDateTimeProvider = new Mock <IDateTimeProvider>(); var mockedMeasurementService = new Mock <IMeasurementService>(); var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>(); var controller = new MeasurementController(mockedAuthenticationProvider.Object, mockedMeasurementService.Object, mockedFactory.Object); // Act controller.Save(model); // Assert mockedAuthenticationProvider.Verify(p => p.CurrentUserId, Times.Once); }
public MeasurementModel(MeasurementViewModel measurementViewModel) { this.StartTime = measurementViewModel.StartTime; this.EndTime = measurementViewModel.EndTime; this.MeasurementState = measurementViewModel.MeasurementState; this.TotalSteps = measurementViewModel.TotalSteps; this.Setting = new SettingModel(measurementViewModel.Setting); this.DataSets = new MeasurementDataSets(measurementViewModel.DataSetsViewModel); }
public void SetViewModel(MeasurementViewModel model) { Model = model; ItemView.FindViewById <TextView>(Resource.Id.measurement_title).Text = model.Type; if (model.Values.Any()) { ItemView.FindViewById <EditText>(Resource.Id.measurement_current_value).Text = $"{model.Values.Last().Value}"; } }
public static Measurement AsModel(this MeasurementViewModel viewModel) { return(new Measurement { Id = viewModel.Id, Length = viewModel.Length, Weight = viewModel.Weight, BabyId = viewModel.Baby.Id }); }
public void TestConstructor_PassMeasurementNull_ShouldSetDateCorrectly() { // Arrange var date = new DateTime(1, 2, 3); // Act var model = new MeasurementViewModel(null, date); // Assert Assert.AreEqual(date, model.Date); }
public HttpResponseMessage UpdateMeasurement([FromBody] MeasurementViewModel model) { try { var data = repo.UpdateMasurement(model); return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, result = model, message = "the record has successfully been created" })); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.OK, new { success = false, message = $"there was an error creating this record {e.Message}" })); } }
public async Task <ActionResult> AddMeasurement(MeasurementViewModel model) { var token = GetToken(); var response = await _measurementsClient.AddMeasurementAndGetHttpResponseUsingToken(model, token); if (response.IsSuccessStatusCode) { return(RedirectToAction("AllMeasurements", "Measurements")); } return(View(model)); }
public ActionResult HumidityMeasurement(int id) { var patient = this._repository.GetPatient(id); var model = new MeasurementViewModel { Id = id, Name = $"{patient.FirstName} {patient.Surname}", Age = DateTime.Now.Year - patient.DateOfBirth.Year }; return(View(model)); }
public void AddNewMeasurement(MeasurementViewModel newModel) { NewViewModel = null; ShowNew = false; ShowSettings = false; Measurements.Add(newModel); if (SelectedMeasurement == null) { SelectedMeasurement = newModel; SelectedMeasurement.IsEnabled = true; } }
public bool UpdateMasurement(MeasurementViewModel entity) { var data = (from d in context.tbl_Measurement where d.UnitOfMeasurementId == entity.unitOfMeasurementId select d).SingleOrDefault(); if (data != null) { data.UnitOfMeasurementId = entity.unitOfMeasurementId; data.UOM = entity.uom; data.IsActive = entity.isActive; } return(context.SaveChanges() > 0); }
private MeasurementViewModel MapMeasurementDTO(MeasurementDTO model) { var viewModel = new MeasurementViewModel { Id = model.Id, MeasurementDate = model.MeasurementDate, Value = model.Value, Difference = model.Difference, ApplicationUser = model.ApplicationUser }; return(viewModel); }
public void AllCitiesOnCollectionChangedTest() { var meas = new MeasurementViewModel(); bool isEmptyCitiesList = !meas.Cities.Any(); City.AllCities.Add(new City("Moscow")); bool isFullCitiesList = meas.Cities.Any(); ClearData(); Assert.IsTrue(isEmptyCitiesList && isFullCitiesList); }
public MeasurementViewModel AddMeasurement(MeasurementViewModel entity) { var data = new tbl_Measurement { UnitOfMeasurementId = entity.unitOfMeasurementId, UOM = entity.uom, IsActive = entity.isActive }; context.tbl_Measurement.Add(data); context.SaveChanges(); return(entity); }
public MainWindowViewModel() { base.DisplayName = "MainWindowViewModel"; StatusVM = new StatusViewModel(); StatusVM.Busy = 0; CameraVM = new CameraViewModel(StatusVM); SpectrometerVM = new SpectrometerViewModel(StatusVM); MeasurementVM = new MeasurementViewModel(StatusVM, CameraVM, SpectrometerVM); MainWindow mainWindow = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault(); CameraVM.setImageFilterUserControl(ref mainWindow.imageFilterUserControlInstance); }
public void AllMeasurementLimits_CollectionChangedTest() { var meas = new MeasurementViewModel(); bool isEmptyMeasLimitList = !meas.Limits.Any(); MeasurementLimit.AllMeasurementLimits.Add(new MeasurementLimit(8, 20, 10, new City("Moscow"))); bool isFullMeasLimitList = meas.Limits.Any(); ClearData(); Assert.IsTrue(isEmptyMeasLimitList && isFullMeasLimitList); }
public SettingsPage() { InitializeComponent(); _objmeasurementViewModel = new MeasurementViewModel(); dropdownWeight.ItemsSource = _objmeasurementViewModel.measurementWightEntities; dropdownHeight.ItemsSource = _objmeasurementViewModel.measurementDistance; if (Settings.DistanceId > 0 && Settings.DistanceName != null) { dropdownHeight.SelectedIndex = Settings.DistanceId - 1; } if (Settings.WeightId > 0 && Settings.WeightName != null) { dropdownWeight.SelectedIndex = Settings.WeightId - 1; } }
//############################################################################################################################################ //################################################### AppbarButton Methods ################################################################### //############################################################################################################################################ #region DelegateMethods private async void StartMeasurement(MeasurementViewModel measurementViewModel) { // Show loader _mainPage.ShowLoader(); bool isStarted = false; // first update for settings _mainPage.GlobalMeasurementModel.UpdateMeasurementInList(measurementViewModel); //start functionality isStarted = await _mainPage.StartBackgroundTask(measurementViewModel.Id); if (isStarted) { _measurementPageViewModel.MeasurementViewModel.StartMeasurement(); //second update for successfully started measurement. _mainPage.GlobalMeasurementModel.UpdateMeasurementInList(measurementViewModel); // its importent to raise the change of measurementstate to all commands RaiseCanExecuteChanged(); StartUpdateTimer(); SetOnProgressEventListnerByMeasurementState(_measurementPageViewModel.MeasurementViewModel.Id, _measurementPageViewModel.MeasurementViewModel.MeasurementState); _mainPage.ShowNotifyMessage("Messung wurde gestarted.", NotifyLevel.Info); } else { _mainPage.ShowNotifyMessage("Messung konnte nicht gestarted werden.", NotifyLevel.Error); } // Hide loader _mainPage.HideLoader(); }
private async void DeleteMeasurement(MeasurementViewModel measurementViewModel) { MessageDialog dialog = new MessageDialog("Messung löschen?"); dialog.Commands.Add(new UICommand("OK")); dialog.Commands.Add(new UICommand("Abbrechen")); var dialogResult = await dialog.ShowAsync(); if (dialogResult.Label.Equals("OK")) { bool isDeleted = false; isDeleted = await _mainPage.GlobalMeasurementModel.Delete(measurementViewModel.Id); if (isDeleted) { _measurementPageViewModel.MeasurementViewModel.DeleteMeasurement(); RaiseCanExecuteChanged(); _mainPage.ShowNotifyMessage("Messung wurde gelöscht.", NotifyLevel.Info); Frame contentFrame = MainPage.Current.FindName("ContentFrame") as Frame; if (contentFrame != null && contentFrame.CanGoBack) contentFrame.GoBack(); } else { _mainPage.ShowNotifyMessage("Messung konnte nicht gelöscht werden.", NotifyLevel.Error); } } if (dialogResult.Label.Equals("Abbrechen")) { _mainPage.ShowNotifyMessage("Messung wurden nicht gelöscht.", NotifyLevel.Info); } }
private void ShowMeasurementGraph(MeasurementViewModel measurementViewModel) { if (measurementViewModel != null) { Frame contentFrame = _mainPage.FindName("ContentFrame") as Frame; contentFrame.Navigate(typeof(GraphPage), measurementViewModel.Id); } }
private void RedoEvaluationGraph(MeasurementViewModel measurementViewModel) { if (measurementViewModel != null) { Frame contentFrame = _mainPage.FindName("ContentFrame") as Frame; contentFrame.Navigate(typeof(EvaluationPage), measurementViewModel.Id); } }
private void ExportMeasurement(MeasurementViewModel measurementViewModel) { // Show loader _mainPage.ShowLoader(); //_mainPage.ExportMeasurementData(measurementViewMdel.Id); if (measurementViewModel.Id != null && measurementViewModel.Id.Length > 0) { MeasurementModel measurement = _mainPage.GlobalMeasurementModel.GetMeasurementById(measurementViewModel.Id); if (measurement != null) { var savePicker = new Windows.Storage.Pickers.FileSavePicker(); savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary; // Dropdown of file types the user can save the file as savePicker.FileTypeChoices.Add("Binary-File", new List<string>() { ".bin" }); // Default file name if the user does not type one in or select a file to replace savePicker.SuggestedFileName = String.Format("{0}_{1:yyyy-MM-dd_HH-mm-ss}", measurement.Setting.Name, measurement.StartTime); // Open the file picker and call the method "ContinueFileSavePicker" when the user select a file. savePicker.PickSaveFileAndContinue(); } } // Hide loader _mainPage.HideLoader(); }
private void StopMeasurement(MeasurementViewModel measurementViewModel) { // Show loader _mainPage.ShowLoader(); bool isStopped = false; // stop functionality isStopped = _mainPage.StopBackgroundTask(measurementViewModel.Id); if (isStopped) { _measurementPageViewModel.MeasurementViewModel.StopMeasurement(); _mainPage.GlobalMeasurementModel.UpdateMeasurementInList(measurementViewModel); // its importent to raise the change of measurementstate to all commands RaiseCanExecuteChanged(); StopUpdateTimer(); SetOnProgressEventListnerByMeasurementState(_measurementPageViewModel.MeasurementViewModel.Id, _measurementPageViewModel.MeasurementViewModel.MeasurementState); AnalyseMeasurementDatasetsAsync(measurementViewModel.Id); _mainPage.ShowNotifyMessage("Messung wurde gestoppt.", NotifyLevel.Info); } else { _mainPage.ShowNotifyMessage("Messung konnte nicht gestoppt werden.", NotifyLevel.Error); } // Hide loader _mainPage.HideLoader(); }
public bool UpdateMeasurementInList(MeasurementViewModel updateMeasurementViewModel) { bool isUpdated = false; if (updateMeasurementViewModel != null) { MeasurementModel measurementFromList = GetMeasurementById(updateMeasurementViewModel.Id); if (measurementFromList != null) { // update relevant informations measurementFromList.StartTime = updateMeasurementViewModel.StartTime; measurementFromList.EndTime = updateMeasurementViewModel.EndTime; measurementFromList.MeasurementState = updateMeasurementViewModel.MeasurementState; measurementFromList.TotalSteps = updateMeasurementViewModel.TotalSteps; measurementFromList.Setting = new SettingModel(updateMeasurementViewModel.Setting); isUpdated = true; OnMeasurementListUpdated(EventArgs.Empty); } } return isUpdated; }