public void TwoEntries_SameType_OneIsNew() { TrainingDayDTO daySource = new TrainingDayDTO(); daySource.InstanceId = Guid.NewGuid(); daySource.GlobalId = Guid.NewGuid(); SizeEntryDTO size = new SizeEntryDTO(); size.ReservationId = Guid.NewGuid();//for testing purposes size.InstanceId = Guid.NewGuid(); size.GlobalId = Guid.NewGuid(); daySource.Objects.Add(size); size.TrainingDay = daySource; SizeEntryDTO tracker = new SizeEntryDTO(); tracker.InstanceId = Guid.NewGuid(); tracker.ReservationId = Guid.NewGuid();//for testing purposes daySource.Objects.Add(tracker); tracker.TrainingDay = daySource; var dayCopy = daySource.Copy(); dayCopy.Objects[1].GlobalId = Guid.NewGuid(); dayCopy.InstanceId = Guid.Empty; dayCopy.Objects[0].InstanceId = Guid.Empty; dayCopy.Objects[1].InstanceId = Guid.Empty; dayCopy.FillInstaneId(daySource); Assert.AreEqual(daySource.InstanceId, dayCopy.InstanceId); Assert.AreEqual(size.ReservationId, dayCopy.Objects.Where(x => x.InstanceId == size.InstanceId).SingleOrDefault().ReservationId); Assert.AreEqual(tracker.ReservationId, dayCopy.Objects.Where(x => x.InstanceId == tracker.InstanceId).SingleOrDefault().ReservationId); }
public void TestDeleteTrainingDay_Mode_OnlyWithoutMyTraining_TrainingDayShouldBeDeleted() { var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); DateTime date = DateTime.Now.AddDays(-2); TrainingDayDTO day = new TrainingDayDTO(date); day.ProfileId = profile.GlobalId; SizeEntryDTO sizeEntry = new SizeEntryDTO(); sizeEntry.Wymiary = new WymiaryDTO(); sizeEntry.Wymiary.Height = 100; day.AddEntry(sizeEntry); SaveTrainingDayResult result = null; RunServiceMethod(delegate(InternalBodyArchitectService Service) { result = Service.SaveTrainingDay(data.Token, day); day = result.TrainingDay; }); RunServiceMethod(delegate(InternalBodyArchitectService Service) { var param = new DeleteTrainingDayParam(); param.TrainingDayId = day.GlobalId; param.Mode = DeleteTrainingDayMode.OnlyWithoutMyTraining; Service.DeleteTrainingDay(data.Token, param); }); Assert.AreEqual(0, Session.QueryOver <TrainingDay>().RowCount()); Assert.AreEqual(0, Session.QueryOver <SizeEntry>().RowCount()); }
public void TwoEntries_SameType_FindingByGlobalId() { TrainingDayDTO daySource = new TrainingDayDTO(); daySource.GlobalId = Guid.NewGuid(); daySource.InstanceId = Guid.NewGuid(); SizeEntryDTO size = new SizeEntryDTO(); size.GlobalId = Guid.NewGuid(); size.InstanceId = Guid.NewGuid(); daySource.Objects.Add(size); size.TrainingDay = daySource; SizeEntryDTO tracker = new SizeEntryDTO(); tracker.InstanceId = Guid.NewGuid(); tracker.GlobalId = Guid.NewGuid(); daySource.Objects.Add(tracker); tracker.TrainingDay = daySource; var dayCopy = daySource.Copy(); dayCopy.InstanceId = Guid.Empty; dayCopy.Objects[0].InstanceId = Guid.Empty; dayCopy.Objects[1].InstanceId = Guid.Empty; dayCopy.FillInstaneId(daySource); Assert.AreEqual(daySource.InstanceId, dayCopy.InstanceId); Assert.AreEqual(size.InstanceId, dayCopy.Objects.Single(x => x.GlobalId == size.GlobalId).InstanceId); Assert.AreEqual(tracker.InstanceId, dayCopy.Objects.Single(x => x.GlobalId == tracker.GlobalId).InstanceId); }
public void TwoEntries_EachDifferentType() { TrainingDayDTO daySource = new TrainingDayDTO(); daySource.InstanceId = Guid.NewGuid(); SizeEntryDTO size = new SizeEntryDTO(); size.InstanceId = Guid.NewGuid(); daySource.Objects.Add(size); size.TrainingDay = daySource; GPSTrackerEntryDTO tracker = new GPSTrackerEntryDTO(); tracker.InstanceId = Guid.NewGuid(); daySource.Objects.Add(tracker); tracker.TrainingDay = daySource; var dayCopy = daySource.Copy(); dayCopy.GlobalId = Guid.NewGuid(); dayCopy.Objects[0].GlobalId = Guid.NewGuid(); dayCopy.Objects[1].GlobalId = Guid.NewGuid(); dayCopy.InstanceId = Guid.Empty; dayCopy.Objects[0].InstanceId = Guid.Empty; dayCopy.Objects[1].InstanceId = Guid.Empty; dayCopy.FillInstaneId(daySource); Assert.AreEqual(daySource.InstanceId, dayCopy.InstanceId); Assert.AreEqual(daySource.Objects.OfType <SizeEntryDTO>().Single().InstanceId, dayCopy.Objects.OfType <SizeEntryDTO>().Single().InstanceId); Assert.AreEqual(daySource.Objects.OfType <GPSTrackerEntryDTO>().Single().InstanceId, dayCopy.Objects.OfType <GPSTrackerEntryDTO>().Single().InstanceId); }
public void TestDeleteTrainingDay_RemoveAllTrainingDays() { var profile = (ProfileDTO)profiles[0].Tag; SessionData data = SecurityManager.CreateNewSession(profile, ClientInformation); DateTime date = DateTime.Now.AddDays(-2); TrainingDayDTO day = new TrainingDayDTO(date); day.ProfileId = profile.Id; SizeEntryDTO sizeEntry = new SizeEntryDTO(); sizeEntry.Wymiary = new WymiaryDTO(); sizeEntry.Wymiary.Height = 100; day.AddEntry(sizeEntry); RunServiceMethod(delegate(InternalBodyArchitectService Service) { day = Service.SaveTrainingDay(data.Token, day); }); RunServiceMethod(delegate(InternalBodyArchitectService Service) { Service.DeleteTrainingDay(data.Token, day); }); var dbProfile = Session.Get <Profile>(profile.Id); Assert.AreEqual(0, dbProfile.Statistics.TrainingDaysCount); Assert.AreEqual(null, dbProfile.Statistics.LastEntryDate); Assert.AreEqual(0, dbProfile.Statistics.SizeEntriesCount); }
public void DeleteTrainingDay_EntryWithReminder() { var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); DateTime date = DateTime.Now.AddDays(-2); TrainingDayDTO day = new TrainingDayDTO(date); day.ProfileId = profile.GlobalId; SizeEntryDTO sizeEntry = new SizeEntryDTO(); sizeEntry.Wymiary = new WymiaryDTO(); sizeEntry.RemindBefore = TimeSpan.FromMinutes(10); sizeEntry.Wymiary.Height = 100; day.AddEntry(sizeEntry); SaveTrainingDayResult result = null; RunServiceMethod(delegate(InternalBodyArchitectService Service) { result = Service.SaveTrainingDay(data.Token, day); day = result.TrainingDay; }); RunServiceMethod(delegate(InternalBodyArchitectService Service) { var param = new DeleteTrainingDayParam(); param.TrainingDayId = day.GlobalId; Service.DeleteTrainingDay(data.Token, param); }); var count = Session.QueryOver <ReminderItem>().RowCount(); Assert.AreEqual(0, count); }
public void Test_SaveTrainingDay_UpdateSize_TwoTimes() { var profile = (ProfileDTO)profiles[0].Tag; SessionData data = SecurityManager.CreateNewSession(profile, ClientInformation); TrainingDayDTO day = new TrainingDayDTO(DateTime.Now.AddDays(-2)); day.ProfileId = profile.Id; SizeEntryDTO entry = new SizeEntryDTO(); entry.Wymiary = new WymiaryDTO(); entry.Wymiary.Height = 100; day.AddEntry(entry); RunServiceMethod(delegate(InternalBodyArchitectService service) { service.SaveTrainingDay(data.Token, day); }); day = new TrainingDayDTO(DateTime.Now.AddDays(-1)); day.ProfileId = profile.Id; entry = new SizeEntryDTO(); entry.Wymiary = new WymiaryDTO(); entry.Wymiary.Height = 50; day.AddEntry(entry); RunServiceMethod(delegate(InternalBodyArchitectService service) { service.SaveTrainingDay(data.Token, day); }); var dbProfile = Session.Get <Profile>(profile.Id); Assert.AreEqual(50, dbProfile.Wymiary.Height); }
public void Fill(EntryObjectDTO entry) { sizeEntry = (SizeEntryDTO)entry; updateReadOnly(); this.usrWymiaryEditor1.Fill(sizeEntry.Wymiary); usrReportStatus1.Fill(entry); }
public void ForCustomer_SaveTrainingDay_UpdateSize_TwoTimes_SecondInThePast() { var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); TrainingDayDTO day = new TrainingDayDTO(DateTime.Now.AddDays(-1)); day.ProfileId = profile.GlobalId; day.CustomerId = customers[0].GlobalId; SizeEntryDTO entry = new SizeEntryDTO(); entry.Wymiary = new WymiaryDTO(); entry.Wymiary.Height = 100; day.AddEntry(entry); RunServiceMethod(delegate(InternalBodyArchitectService service) { service.SaveTrainingDay(data.Token, day); }); day = new TrainingDayDTO(DateTime.Now.AddDays(-2)); day.ProfileId = profile.GlobalId; day.CustomerId = customers[0].GlobalId; entry = new SizeEntryDTO(); entry.Wymiary = new WymiaryDTO(); entry.Wymiary.Height = 50; day.AddEntry(entry); RunServiceMethod(delegate(InternalBodyArchitectService service) { service.SaveTrainingDay(data.Token, day); }); var dbCustomer = Session.Get <Customer>(customers[0].GlobalId); Assert.AreEqual(100, dbCustomer.Wymiary.Height); }
public void DeleteTrainingDay_AnotherProfile() { var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); DateTime date = DateTime.Now.AddDays(-2); TrainingDayDTO day = new TrainingDayDTO(date); day.ProfileId = profile.GlobalId; SizeEntryDTO sizeEntry = new SizeEntryDTO(); sizeEntry.Wymiary = new WymiaryDTO(); sizeEntry.Wymiary.Height = 100; day.AddEntry(sizeEntry); SaveTrainingDayResult result = null; RunServiceMethod(delegate(InternalBodyArchitectService Service) { result = Service.SaveTrainingDay(data.Token, day); day = result.TrainingDay; }); data = CreateNewSession((ProfileDTO)profiles[1].Tag, ClientInformation); RunServiceMethod(delegate(InternalBodyArchitectService Service) { var param = new DeleteTrainingDayParam(); param.TrainingDayId = day.GlobalId; Service.DeleteTrainingDay(data.Token, param); }); }
public void TestDeleteTrainingDay_LatestNotChanged() { var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); DateTime date = DateTime.Now.AddDays(-2); TrainingDayDTO day = new TrainingDayDTO(date); day.ProfileId = profile.GlobalId; SizeEntryDTO sizeEntry = new SizeEntryDTO(); sizeEntry.Wymiary = new WymiaryDTO(); sizeEntry.Wymiary.Height = 100; day.AddEntry(sizeEntry); SaveTrainingDayResult result = null; RunServiceMethod(delegate(InternalBodyArchitectService Service) { result = Service.SaveTrainingDay(data.Token, day); day = result.TrainingDay; }); date = DateTime.Now; var day1 = new TrainingDayDTO(DateTime.Now); day1.ProfileId = profile.GlobalId; sizeEntry = new SizeEntryDTO(); sizeEntry.Wymiary = new WymiaryDTO(); sizeEntry.Wymiary.Height = 100; day1.AddEntry(sizeEntry); RunServiceMethod(delegate(InternalBodyArchitectService Service) { result = Service.SaveTrainingDay(data.Token, day1); day1 = result.TrainingDay; }); var dbProfile = Session.Get <Profile>(profile.GlobalId); Assert.AreEqual(2, dbProfile.Statistics.TrainingDaysCount); Assert.AreEqual(date.Date, dbProfile.Statistics.LastEntryDate.Value); RunServiceMethod(delegate(InternalBodyArchitectService Service) { var param = new DeleteTrainingDayParam(); param.TrainingDayId = day.GlobalId; Service.DeleteTrainingDay(data.Token, param);; }); dbProfile = Session.Get <Profile>(profile.GlobalId); Assert.AreEqual(1, dbProfile.Statistics.TrainingDaysCount); Assert.AreEqual(date.Date, dbProfile.Statistics.LastEntryDate.Value); }
TrainingDayDTO createDay(DateTime date, int version = 1) { var day = new TrainingDayDTO() { TrainingDate = date.Date }; SizeEntryDTO size = new SizeEntryDTO(); size.Version = version; day.Objects.Add(size); size.TrainingDay = day; return(day); }
async public void SyncOperation_Correct() { ApplicationState state = new ApplicationState(); ApplicationState.Current = state; state.SessionData = new SessionData(); state.SessionData.Profile = new ProfileDTO() { GlobalId = Guid.NewGuid() }; state.MyDays = new Dictionary <CacheKey, TrainingDaysHolder>(); var holder = state.GetTrainingDayHolder(null); DateTime time = ExtensionMethods.MonthDate(DateTime.UtcNow); var day = new TrainingDayDTO() { TrainingDate = time.AddDays(1) }; var size = new SizeEntryDTO(); day.Objects.Add(size); size.TrainingDay = day; holder.TrainingDays.Add(time.AddDays(1), new TrainingDayInfo(day) { IsModified = true }); bool eventCompleted = false; MockSynchronizationViewModel viewModel = new MockSynchronizationViewModel(state); viewModel.SynchronizationCompleted += delegate { eventCompleted = true; }; var items = viewModel.Items.ToArray(); await viewModel.Synchronize(); Assert.AreEqual(1, viewModel.Maximum); Assert.AreEqual(1, viewModel.SaveCount); Assert.AreEqual(MergeState.Finished, items[0].State); Assert.IsTrue(eventCompleted); Assert.IsTrue(viewModel.FirstSave); Assert.IsFalse(viewModel.Merged); Assert.IsFalse(items[0].DayInfo.IsModified); Assert.IsTrue(viewModel.IsInProgressGood); Assert.AreNotEqual(Guid.Empty, day.GlobalId); EnqueueTestComplete(); }
string getMeasurementsMessage(SizeEntryDTO size) { StringBuilder builder = new StringBuilder(); if (size.Wymiary != null) { if (size.Wymiary.RightBiceps > 0) { builder.AppendLine(ApplicationStrings.MeasurementsControl_RightBiceps + ": " + size.Wymiary.RightBiceps.ToDisplayLength().ToString("0.##")); } if (size.Wymiary.LeftBiceps > 0) { builder.AppendLine(ApplicationStrings.MeasurementsControl_LeftBiceps + ": " + size.Wymiary.LeftBiceps.ToDisplayLength().ToString("0.##")); } if (size.Wymiary.Klatka > 0) { builder.AppendLine(ApplicationStrings.MeasurementsControl_Chest + ": " + size.Wymiary.Klatka.ToDisplayLength().ToString("0.##")); } if (size.Wymiary.RightForearm > 0) { builder.AppendLine(ApplicationStrings.MeasurementsControl_RightForearm + ": " + size.Wymiary.RightForearm.ToDisplayLength().ToString("0.##")); } if (size.Wymiary.LeftForearm > 0) { builder.AppendLine(ApplicationStrings.MeasurementsControl_LeftForearm + ": " + size.Wymiary.LeftForearm.ToDisplayLength().ToString("0.##")); } if (size.Wymiary.RightUdo > 0) { builder.AppendLine(ApplicationStrings.MeasurementsControl_RightLeg + ": " + size.Wymiary.RightUdo.ToDisplayLength().ToString("0.##")); } if (size.Wymiary.LeftUdo > 0) { builder.AppendLine(ApplicationStrings.MeasurementsControl_LeftLeg + ": " + size.Wymiary.LeftUdo.ToDisplayLength().ToString("0.##")); } if (size.Wymiary.Pas > 0) { builder.AppendLine(ApplicationStrings.MeasurementsControl_Abs + ": " + size.Wymiary.Pas.ToDisplayLength().ToString("0.##")); } if (size.Wymiary.Weight > 0) { builder.AppendLine(ApplicationStrings.MeasurementsControl_Weight + ": " + size.Wymiary.Weight.ToDisplayWeight().ToString("0.##")); } } return(builder.ToString()); }
public void Test_DeleteTrainingDay_UpdateSize() { var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); TrainingDayDTO day = new TrainingDayDTO(DateTime.Now.AddDays(-2)); day.ProfileId = profile.GlobalId; SizeEntryDTO entry = new SizeEntryDTO(); entry.Wymiary = new WymiaryDTO(); entry.Wymiary.Height = 100; day.AddEntry(entry); RunServiceMethod(delegate(InternalBodyArchitectService service) { service.SaveTrainingDay(data.Token, day); }); day = new TrainingDayDTO(DateTime.Now.AddDays(-1)); day.ProfileId = profile.GlobalId; entry = new SizeEntryDTO(); entry.Wymiary = new WymiaryDTO(); entry.Wymiary.Height = 50; day.AddEntry(entry); RunServiceMethod(delegate(InternalBodyArchitectService service) { day = service.SaveTrainingDay(data.Token, day).TrainingDay; }); RunServiceMethod(delegate(InternalBodyArchitectService service) { var param = new DeleteTrainingDayParam(); param.TrainingDayId = day.GlobalId; service.DeleteTrainingDay(data.Token, param); }); var dbProfile = Session.Get <Profile>(profile.GlobalId); Assert.AreEqual(100, dbProfile.Wymiary.Height); }
public void TestDeleteTrainingDay_DataInfo_Refresh() { var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); DateTime date = DateTime.Now.AddDays(-2); TrainingDayDTO day = new TrainingDayDTO(date); day.ProfileId = profile.GlobalId; SizeEntryDTO sizeEntry = new SizeEntryDTO(); sizeEntry.Wymiary = new WymiaryDTO(); sizeEntry.Wymiary.Height = 100; day.AddEntry(sizeEntry); SaveTrainingDayResult result = null; RunServiceMethod(delegate(InternalBodyArchitectService Service) { result = Service.SaveTrainingDay(data.Token, day); day = result.TrainingDay; }); var dbProfile = Session.Get <Profile>(profile.GlobalId); var oldHash = dbProfile.DataInfo.TrainingDayHash; RunServiceMethod(delegate(InternalBodyArchitectService Service) { TimerService.UtcNow = DateTime.UtcNow.AddHours(1); var param = new DeleteTrainingDayParam(); param.TrainingDayId = day.GlobalId; Service.DeleteTrainingDay(data.Token, param); }); dbProfile = Session.Get <Profile>(profile.GlobalId); Assert.AreNotEqual(oldHash, dbProfile.DataInfo.TrainingDayHash); }
public void Test_SaveTrainingDay_AutomaticUpdateDisable() { profiles[0].Settings.AutomaticUpdateMeasurements = false; insertToDatabase(profiles[0]); var profile = (ProfileDTO)profiles[0].Tag; SessionData data = SecurityManager.CreateNewSession(profile, ClientInformation); TrainingDayDTO day = new TrainingDayDTO(DateTime.Now); day.ProfileId = profile.Id; SizeEntryDTO entry = new SizeEntryDTO(); entry.Wymiary = new WymiaryDTO(); entry.Wymiary.Height = 100; day.AddEntry(entry); RunServiceMethod(delegate(InternalBodyArchitectService service) { service.SaveTrainingDay(data.Token, day); }); var dbProfile = Session.Get <Profile>(profile.Id); Assert.IsNull(dbProfile.Wymiary); }
public void EntryObjectCreated(EntryObjectDTO entryObject) { if (reservation != null) { entryObject.ReservationId = reservation.GlobalId; } StrengthTrainingEntryDTO strength = entryObject as StrengthTrainingEntryDTO; SizeEntryDTO size = entryObject as SizeEntryDTO; if (strength != null) { strength.StartTime = scheduleEntry.StartTime.ToLocalTime(); strength.EndTime = scheduleEntry.EndTime.ToLocalTime(); if (scheduleEntry.MyPlaceId.HasValue) { var myPlacesCache = MyPlacesReposidory.GetCache(null); strength.MyPlace = myPlacesCache.GetItem(scheduleEntry.MyPlaceId.Value); } } if (size != null) { size.Wymiary.Time.DateTime = scheduleEntry.StartTime.ToLocalTime(); } }
public MeasurementsViewModel(SizeEntryDTO entry) { this.entry = entry; }
void generateProgress(SizeEntryDTO sizeEntry) { progressIndicator1.IsRunning = true; chart.SetVisible(!progressIndicator1.IsRunning); tbLicenceMsg.Text = Strings.ProgressReport_Generating; WeightRepetitionsReportBuilder reportBuilder = new WeightRepetitionsReportBuilder(); var report = reportBuilder.CreateReport(); var settings = (MeasurementsTimeReportSettings)report.SettingsControl; settings.usrDateRange1.DateFrom = DateTime.UtcNow.AddYears(-1); //create customer and user object only as a mock to put correct ProfileId and CustomerId to retrieve data method CustomerDTO customer = null; if (sizeEntry.TrainingDay.CustomerId.HasValue) { customer = new CustomerDTO(); customer.GlobalId = sizeEntry.TrainingDay.CustomerId.Value; } report.Initialize(new UserDTO() { GlobalId = sizeEntry.TrainingDay.ProfileId }, customer); var properties = typeof(WymiaryDTO).GetProperties(); foreach (var propertyInfo in properties) { if (propertyInfo.PropertyType == typeof(decimal)) { var value = (decimal)propertyInfo.GetValue(sizeEntry.Wymiary, null); if (value > 0) { var item = settings.Items.Where(x => x.Value == propertyInfo.Name).Single(); item.IsChecked = true; } } } chart.Series.Clear(); chart.ResetBarAndColumnCaches(); //StringBuilder stringBuilder = new StringBuilder(); //XmlWriterSettings xmlSettings = new XmlWriterSettings(); //xmlSettings.Indent = true; //using (XmlWriter xmlWriter = XmlWriter.Create(stringBuilder, xmlSettings)) //{ // XamlWriter.Save(chart.Template, xmlWriter); //} //Console.WriteLine(stringBuilder.ToString()); ThreadPool.QueueUserWorkItem(new WaitCallback((h) => { try { Helper.EnsureThreadLocalized(); var data = report.RetrieveReportData(null); Helper.Delay(2000); UIHelper.BeginInvoke(() => { report.GenerateReport(chart, data); progressIndicator1.IsRunning = false; chart.SetVisible(!progressIndicator1.IsRunning); tbLicenceMsg.Text = ""; }, Dispatcher); } catch (Exception) { UIHelper.BeginInvoke(() => { progressIndicator1.IsRunning = false; chart.SetVisible(!progressIndicator1.IsRunning); tbLicenceMsg.Text = Strings.ProgressReport_Error; }, Dispatcher); } })); }