public void StartNewCycle_Longer_ShouldUseRepetition_DoNotChangeDefinitionInDb() { definition = createCycleForRepetitions(); DateTime date = new DateTime(2012, 03, 26);//monday var cycle = new SupplementsCycleDTO(); cycle.TrainingDays = string.Format("{0}S,{1}S,{2}S", (int)DayOfWeek.Monday, (int)DayOfWeek.Wednesday, (int)DayOfWeek.Friday); cycle.Name = "Creatine"; cycle.StartDate = date; cycle.TotalWeeks = 14; cycle.SupplementsCycleDefinitionId = definition.GlobalId; var profile1 = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile1, ClientInformation); MyTrainingDTO result = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { MyTrainingOperationParam param = new MyTrainingOperationParam(); param.Operation = MyTrainingOperationType.Start; param.MyTraining = cycle; result = service.MyTrainingOperation(data.Token, param); }); var dbCycle = Session.Get <SupplementCycleDefinition>(definition.GlobalId); Assert.AreEqual(4, dbCycle.Weeks.Count); }
public void StartNewCycle_WithEmptyTrainingDays() { definition = createCreating2DT1DNTDefinition(); DateTime date = new DateTime(2012, 03, 26);//monday var cycle = new SupplementsCycleDTO(); cycle.Name = "Creatine"; cycle.StartDate = date; cycle.TrainingDays = ""; cycle.SupplementsCycleDefinitionId = definition.GlobalId; var profile1 = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile1, ClientInformation); MyTrainingDTO result = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { MyTrainingOperationParam param = new MyTrainingOperationParam(); param.Operation = MyTrainingOperationType.Start; param.MyTraining = cycle; result = service.MyTrainingOperation(data.Token, param); }); var dbCycle = Session.Get <SupplementCycle>(result.GlobalId); Assert.AreEqual(28, dbCycle.EntryObjects.Count); }
public void SimulateNewCycle_EntriesInDb() { definition = createCreating2DT1DNTDefinition(); DateTime date = new DateTime(2012, 03, 26);//monday var cycle = new SupplementsCycleDTO(); cycle.TrainingDays = string.Format("{0}S,{1}S,{2}S", (int)DayOfWeek.Monday, (int)DayOfWeek.Wednesday, (int)DayOfWeek.Friday); cycle.Name = "Creatine"; cycle.StartDate = date; cycle.SupplementsCycleDefinitionId = definition.GlobalId; var profile1 = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile1, ClientInformation); MyTrainingDTO result = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { var param = new MyTrainingOperationParam(); param.Operation = MyTrainingOperationType.Simulate; param.MyTraining = cycle; result = service.MyTrainingOperation(data.Token, param); }); Assert.AreEqual(0, Session.QueryOver <SupplementCycle>().RowCount()); Assert.AreEqual(0, Session.QueryOver <TrainingDay>().RowCount()); Assert.AreEqual(0, Session.QueryOver <SupplementCycle>().RowCount()); }
public void StartAlreadyStartedCycle() { definition = createCreating2DT1DNTDefinition(); DateTime date = new DateTime(2012, 03, 26);//monday var cycle = new SupplementsCycleDTO(); cycle.TrainingDays = string.Format("{0}S,{1}S,{2}S", (int)DayOfWeek.Monday, (int)DayOfWeek.Wednesday, (int)DayOfWeek.Friday); cycle.Name = "Creatine"; cycle.StartDate = date; cycle.SupplementsCycleDefinitionId = definition.GlobalId; var profile1 = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile1, ClientInformation); MyTrainingDTO result = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { MyTrainingOperationParam param = new MyTrainingOperationParam(); param.Operation = MyTrainingOperationType.Start; param.MyTraining = cycle; result = service.MyTrainingOperation(data.Token, param); }); RunServiceMethod(delegate(InternalBodyArchitectService service) { MyTrainingOperationParam param = new MyTrainingOperationParam(); param.Operation = MyTrainingOperationType.Start; param.MyTraining = (SupplementsCycleDTO)result; service.MyTrainingOperation(data.Token, param); }); }
public void StartNewCycle_AllowCommentsSetting_True() { profiles[0].Settings.AllowTrainingDayComments = true; insertToDatabase(profiles[0].Settings); definition = createCreating2DT1DNTDefinition(); DateTime date = new DateTime(2012, 03, 26);//monday var cycle = new SupplementsCycleDTO(); cycle.TrainingDays = string.Format("{0}S,{1}S,{2}S", (int)DayOfWeek.Monday, (int)DayOfWeek.Wednesday, (int)DayOfWeek.Friday); cycle.Name = "Creatine"; cycle.StartDate = date; cycle.SupplementsCycleDefinitionId = definition.GlobalId; var profile1 = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile1, ClientInformation); MyTrainingDTO result = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { MyTrainingOperationParam param = new MyTrainingOperationParam(); param.Operation = MyTrainingOperationType.Start; param.MyTraining = cycle; result = service.MyTrainingOperation(data.Token, param); }); //Assert.AreEqual(SuplementsEntryDTO.EntryTypeId, dbCycle.TypeId); var entries = result.EntryObjects.OrderBy(x => x.TrainingDay.TrainingDate).ToList(); foreach (var entry in entries) { Assert.IsTrue(entry.TrainingDay.AllowComments); } }
public void StartNewCycle_CustomerFromAnotherProfile() { definition = createCreating2DT1DNTDefinition(); var customer = CreateCustomer("ccc", profiles[1]); DateTime date = new DateTime(2012, 03, 26);//monday var cycle = new SupplementsCycleDTO(); cycle.TrainingDays = string.Format("{0},{1},{2}", (int)DayOfWeek.Monday, (int)DayOfWeek.Wednesday, (int)DayOfWeek.Friday); cycle.Name = "Creatine"; cycle.CustomerId = customer.GlobalId; cycle.StartDate = date; cycle.SupplementsCycleDefinitionId = definition.GlobalId; var profile1 = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile1, ClientInformation); RunServiceMethod(delegate(InternalBodyArchitectService service) { MyTrainingOperationParam param = new MyTrainingOperationParam(); param.Operation = MyTrainingOperationType.Start; param.MyTraining = cycle; service.MyTrainingOperation(data.Token, param); }); }
public void SimulateNewCycle_EntriesFromResult() { definition = createCreating2DT1DNTDefinition(); DateTime date = new DateTime(2012, 03, 26);//monday var cycle = new SupplementsCycleDTO(); cycle.TrainingDays = string.Format("{0}S,{1}S,{2}S", (int)DayOfWeek.Monday, (int)DayOfWeek.Wednesday, (int)DayOfWeek.Friday); cycle.Name = "Creatine"; cycle.StartDate = date; cycle.SupplementsCycleDefinitionId = definition.GlobalId; var profile1 = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile1, ClientInformation); MyTrainingDTO result = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { var param = new MyTrainingOperationParam(); param.Operation = MyTrainingOperationType.Simulate; param.MyTraining = cycle; result = service.MyTrainingOperation(data.Token, param); }); Assert.AreEqual(28, result.EntryObjects.Count); //Assert.AreEqual(SuplementsEntryDTO.EntryTypeId, dbCycle.TypeId); var entries = result.EntryObjects.OrderBy(x => x.TrainingDay.TrainingDate).ToList(); Assert.AreEqual(date, entries.ElementAt(0).TrainingDay.TrainingDate); Assert.AreEqual(date.AddDays(27), entries.ElementAt(27).TrainingDay.TrainingDate); foreach (var entry in entries) { Assert.AreEqual(EntryObjectStatus.Planned, entry.Status); } }
public void Test() { var cycleDef = createCycle(); DateTime date = new DateTime(2012, 03, 26);//monday var cycle = new SupplementsCycleDTO(); cycle.Name = "Sterydy"; cycle.StartDate = date; cycle.TrainingDays = string.Format("{0}S,{1}S,{2}B", (int)DayOfWeek.Monday, (int)DayOfWeek.Wednesday, (int)DayOfWeek.Friday); cycle.SupplementsCycleDefinitionId = cycleDef.GlobalId; var profile1 = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile1, ClientInformation); MyTrainingDTO result = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { MyTrainingOperationParam param = new MyTrainingOperationParam(); param.Operation = MyTrainingOperationType.Start; param.MyTraining = cycle; result = service.MyTrainingOperation(data.Token, param); }); var dbCycle = Session.Get <SupplementCycle>(result.GlobalId); Assert.AreEqual(70, dbCycle.EntryObjects.Count); }
public void StartNewCycle_Statistics() { definition = createCreating2DT1DNTDefinition(); DateTime date = new DateTime(2012, 03, 26);//monday var cycle = new SupplementsCycleDTO(); cycle.TrainingDays = string.Format("{0}S,{1}S,{2}S", (int)DayOfWeek.Monday, (int)DayOfWeek.Wednesday, (int)DayOfWeek.Friday); cycle.Name = "Creatine"; cycle.StartDate = date; cycle.SupplementsCycleDefinitionId = definition.GlobalId; var profile1 = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile1, ClientInformation); MyTrainingDTO result = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { MyTrainingOperationParam param = new MyTrainingOperationParam(); param.Operation = MyTrainingOperationType.Start; param.MyTraining = cycle; result = service.MyTrainingOperation(data.Token, param); }); var dbProfile = Session.Get <Profile>(profiles[0].GlobalId); Assert.AreEqual(28, dbProfile.Statistics.TrainingDaysCount); Assert.IsNotNull(dbProfile.Statistics.LastEntryDate); Assert.AreEqual(28, dbProfile.Statistics.SupplementEntriesCount); }
public void CreatineCycle_2DT_1DNT() { definition = createCreating2DT1DNTDefinition(); DateTime date = new DateTime(2012, 03, 26);//monday var cycle = new SupplementsCycleDTO(); cycle.TrainingDays = string.Format("{0}S,{1}S,{2}S", (int)DayOfWeek.Monday, (int)DayOfWeek.Wednesday, (int)DayOfWeek.Friday); cycle.Name = "Creatine"; cycle.StartDate = date; cycle.SupplementsCycleDefinitionId = definition.GlobalId; var profile1 = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile1, ClientInformation); MyTrainingDTO result = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { var param = new MyTrainingOperationParam(); param.Operation = MyTrainingOperationType.Start; param.MyTraining = cycle; result = service.MyTrainingOperation(data.Token, param); }); var dbCycle = Session.Get <SupplementCycle>(result.GlobalId); Assert.AreEqual(28, dbCycle.EntryObjects.Count); //Assert.AreEqual(SuplementsEntryDTO.EntryTypeId, dbCycle.TypeId); var entries = dbCycle.EntryObjects.OrderBy(x => x.TrainingDay.TrainingDate).Cast <SuplementsEntry>().ToList(); foreach (var entry in entries) { Assert.IsNotNull(entry.LoginData); Assert.IsNull(entry.Reminder); if (entry.TrainingDay.TrainingDate.DayOfWeek == DayOfWeek.Monday || entry.TrainingDay.TrainingDate.DayOfWeek == DayOfWeek.Wednesday || entry.TrainingDay.TrainingDate.DayOfWeek == DayOfWeek.Friday) { Assert.AreEqual(2, entry.Items.Count); var item = entry.Items.Where(x => x.Time.TimeType == Model.TimeType.OnEmptyStomach).Single(); Assert.AreEqual(5, item.Dosage); Assert.AreEqual(Model.DosageType.Grams, item.DosageType); Assert.AreEqual(supplement.GlobalId, item.Suplement.GlobalId); item = entry.Items.Where(x => x.Time.TimeType == Model.TimeType.AfterWorkout).Single(); Assert.AreEqual(5, item.Dosage); Assert.AreEqual(Model.DosageType.Grams, item.DosageType); Assert.AreEqual(supplement.GlobalId, item.Suplement.GlobalId); } else { Assert.AreEqual(1, entry.Items.Count); var item = entry.Items.Where(x => x.Time.TimeType == Model.TimeType.OnEmptyStomach).Single(); Assert.AreEqual(5, item.Dosage); Assert.AreEqual(Model.DosageType.Grams, item.DosageType); Assert.AreEqual(supplement.GlobalId, item.Suplement.GlobalId); } } }
public void Test() { var cycleDef = createCycle(); DateTime date = new DateTime(2012, 03, 26); //monday var cycle = new SupplementsCycleDTO(); cycle.Name = "Sterydy"; cycle.StartDate = date; cycle.SupplementsCycleDefinitionId = cycleDef.GlobalId; var profile1 = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile1, ClientInformation); MyTrainingDTO result = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { MyTrainingOperationParam param = new MyTrainingOperationParam(); param.Operation = MyTrainingOperationType.Start; param.MyTraining = cycle; result = service.MyTrainingOperation(data.Token, param); }); var dbCycle = Session.Get <SupplementCycle>(result.GlobalId); Assert.AreEqual(30, dbCycle.EntryObjects.Count); //Assert.AreEqual(SuplementsEntryDTO.EntryTypeId, dbCycle.TypeId); var entries = dbCycle.EntryObjects.OrderBy(x => x.TrainingDay.TrainingDate).ToList(); Assert.AreEqual(2, entries.OfType <SizeEntry>().Count()); Assert.AreEqual(28, entries.OfType <SuplementsEntry>().Count()); foreach (var entry in entries) { SuplementsEntry suplementEntry = entry as SuplementsEntry; if (suplementEntry == null) { continue; } Assert.IsNotNull(entry.LoginData); Assert.IsNull(entry.Reminder); Assert.AreEqual(5, suplementEntry.Items.ElementAt(0).Dosage); Assert.AreEqual(Model.DosageType.Tablets, suplementEntry.Items.ElementAt(0).DosageType); Assert.AreEqual(bcaa.GlobalId, suplementEntry.Items.ElementAt(0).Suplement.GlobalId); Assert.AreEqual(Model.TimeType.OnEmptyStomach, suplementEntry.Items.ElementAt(0).Time.TimeType); Assert.AreEqual(5, suplementEntry.Items.ElementAt(1).Dosage); Assert.AreEqual(Model.DosageType.Tablets, suplementEntry.Items.ElementAt(1).DosageType); Assert.AreEqual(bcaa.GlobalId, suplementEntry.Items.ElementAt(1).Suplement.GlobalId); Assert.AreEqual(Model.TimeType.BeforeWorkout, suplementEntry.Items.ElementAt(1).Time.TimeType); Assert.AreEqual(5, suplementEntry.Items.ElementAt(2).Dosage); Assert.AreEqual(Model.DosageType.Tablets, suplementEntry.Items.ElementAt(2).DosageType); Assert.AreEqual(bcaa.GlobalId, suplementEntry.Items.ElementAt(2).Suplement.GlobalId); Assert.AreEqual(Model.TimeType.AfterWorkout, suplementEntry.Items.ElementAt(2).Time.TimeType); } }
public void Test() { var cycleDef = createCycle(); DateTime date = new DateTime(2012, 03, 26);//monday var cycle = new SupplementsCycleDTO(); cycle.Name = "Sterydy"; cycle.StartDate = date; cycle.SupplementsCycleDefinitionId = cycleDef.GlobalId; var profile1 = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile1, ClientInformation); MyTrainingDTO result = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { MyTrainingOperationParam param = new MyTrainingOperationParam(); param.Operation = MyTrainingOperationType.Start; param.MyTraining = cycle; result = service.MyTrainingOperation(data.Token, param); }); var dbCycle = Session.Get <SupplementCycle>(result.GlobalId); Assert.AreEqual(112, dbCycle.EntryObjects.Count); //Assert.AreEqual(SuplementsEntryDTO.EntryTypeId, dbCycle.TypeId); var entries = dbCycle.EntryObjects.OrderBy(x => x.TrainingDay.TrainingDate).Cast <SuplementsEntry>().ToList(); foreach (var entry in entries) { Assert.IsNotNull(entry.LoginData); Assert.IsNull(entry.Reminder); var week = (int)((entry.TrainingDay.TrainingDate - dbCycle.StartDate).TotalDays / 7) + 1; bool isMonday = entry.TrainingDay.TrainingDate.DayOfWeek == DayOfWeek.Monday; Assert.AreEqual(isMonday?2:1, entry.Items.Count); if (isMonday) { Assert.AreEqual(week == 1 ? 600 : 300, entry.Items.Where(x => x.Suplement.GlobalId == metenolon.GlobalId).Single().Dosage); Assert.AreEqual(Model.DosageType.MiliGrams, entry.Items.Where(x => x.Suplement.GlobalId == metenolon.GlobalId).Single().DosageType); Assert.AreEqual(Model.TimeType.NotSet, entry.Items.Where(x => x.Suplement.GlobalId == metenolon.GlobalId).Single().Time.TimeType); Assert.AreEqual(50, entry.Items.Where(x => x.Suplement.GlobalId == testosteron.GlobalId).Single().Dosage); Assert.AreEqual(Model.DosageType.MiliGrams, entry.Items.Where(x => x.Suplement.GlobalId == testosteron.GlobalId).Single().DosageType); Assert.AreEqual(Model.TimeType.NotSet, entry.Items.Where(x => x.Suplement.GlobalId == testosteron.GlobalId).Single().Time.TimeType); } else { Assert.AreEqual(50, entry.Items.Where(x => x.Suplement.GlobalId == testosteron.GlobalId).Single().Dosage); Assert.AreEqual(Model.DosageType.MiliGrams, entry.Items.Where(x => x.Suplement.GlobalId == testosteron.GlobalId).Single().DosageType); Assert.AreEqual(Model.TimeType.NotSet, entry.Items.Where(x => x.Suplement.GlobalId == testosteron.GlobalId).Single().Time.TimeType); } } }
public void SaveOnceEntryAsDoneAndStopCycle_Statistics() { definition = createCreating2DT1DNTDefinition(); DateTime date = new DateTime(2012, 03, 26);//monday var cycle = new SupplementsCycleDTO(); cycle.TrainingDays = string.Format("{0}S,{1}S,{2}S", (int)DayOfWeek.Monday, (int)DayOfWeek.Wednesday, (int)DayOfWeek.Friday); cycle.Name = "Creatine"; cycle.StartDate = date; cycle.SupplementsCycleDefinitionId = definition.GlobalId; var profile1 = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile1, ClientInformation); MyTrainingDTO result = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { MyTrainingOperationParam param = new MyTrainingOperationParam(); param.Operation = MyTrainingOperationType.Start; param.MyTraining = cycle; result = service.MyTrainingOperation(data.Token, param); }); var dbTrainingDay = Session.QueryOver <TrainingDay>().Where(x => x.TrainingDate == date).Fetch(x => x.Objects).Eager.Fetch(x => x.Objects.First().MyTraining).Eager.SingleOrDefault(); var dtoTrainingDay = dbTrainingDay.Map <TrainingDayDTO>(); dtoTrainingDay.Objects[0].Status = EntryObjectStatus.Done; RunServiceMethod(delegate(InternalBodyArchitectService service) { dtoTrainingDay = service.SaveTrainingDay(data.Token, dtoTrainingDay).TrainingDay; }); RunServiceMethod(delegate(InternalBodyArchitectService service) { MyTrainingOperationParam param = new MyTrainingOperationParam(); param.Operation = MyTrainingOperationType.Stop; param.MyTraining = (SupplementsCycleDTO)result; result = service.MyTrainingOperation(data.Token, param); }); var dbProfile = Session.Get <Profile>(profiles[0].GlobalId); Assert.AreEqual(1, dbProfile.Statistics.TrainingDaysCount); Assert.IsNotNull(dbProfile.Statistics.LastEntryDate); Assert.AreEqual(1, dbProfile.Statistics.SupplementEntriesCount); }
public void MyTrainingOperation_ProblemWithResultClass() { var res = CreateSupplement("Sup"); var definition = new SupplementCycleDefinition(); definition.Language = "en"; definition.Profile = profiles[0]; definition.Name = "dfgdfg"; var week = new SupplementCycleWeek(); week.CycleWeekStart = week.CycleWeekEnd = 1; week.Definition = definition; definition.Weeks.Add(week); var dosage = new SupplementCycleDosage(); dosage.Week = week; dosage.Supplement = res; week.Dosages.Add(dosage); insertToDatabase(definition); DateTime date = new DateTime(2012, 03, 26);//monday var cycle = new SupplementsCycleDTO(); cycle.TrainingDays = string.Format("{0}S,{1}S,{2}S", (int)DayOfWeek.Monday, (int)DayOfWeek.Wednesday, (int)DayOfWeek.Friday); cycle.Name = "Creatine"; cycle.StartDate = date; cycle.SupplementsCycleDefinitionId = definition.GlobalId; var profile1 = (ProfileDTO)profiles[0].Tag; MyTrainingDTO result = null; MyTrainingOperationParam param = new MyTrainingOperationParam(); param.Operation = MyTrainingOperationType.Start; param.MyTraining = cycle; IBodyArchitectAccessService service = CreateServiceProxy(AddressHeader.CreateAddressHeader("APIKey", "", "EB17BC2A-94FD-4E65-8751-15730F69E7F5")); var sessionData = service.Login(ClientInformation, "test_user", "pwd".ToSHA1Hash()); result = service.MyTrainingOperation(sessionData.Token, param); Assert.AreEqual(7, result.EntryObjects.Count); }
public void StartNewCycle_Longer_ShouldUseRepetition() { definition = createCycleForRepetitions(); DateTime date = new DateTime(2012, 03, 26);//monday var cycle = new SupplementsCycleDTO(); cycle.TrainingDays = string.Format("{0}S,{1}S,{2}S", (int)DayOfWeek.Monday, (int)DayOfWeek.Wednesday, (int)DayOfWeek.Friday); cycle.Name = "Creatine"; cycle.StartDate = date; cycle.TotalWeeks = 14; cycle.SupplementsCycleDefinitionId = definition.GlobalId; var profile1 = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile1, ClientInformation); MyTrainingDTO result = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { MyTrainingOperationParam param = new MyTrainingOperationParam(); param.Operation = MyTrainingOperationType.Start; param.MyTraining = cycle; result = service.MyTrainingOperation(data.Token, param); }); var dbCycle = Session.Get <SupplementCycle>(result.GlobalId); var entries = dbCycle.EntryObjects.OrderBy(x => x.TrainingDay.TrainingDate).Cast <SuplementsEntry>().ToList(); Assert.AreEqual(14, entries.Count); Assert.AreEqual(400, entries[7].Items.ElementAt(0).Dosage); Assert.AreEqual(400, entries[8].Items.ElementAt(0).Dosage); Assert.AreEqual(300, entries[9].Items.ElementAt(0).Dosage); Assert.AreEqual(300, entries[10].Items.ElementAt(0).Dosage); Assert.AreEqual(400, entries[11].Items.ElementAt(0).Dosage); Assert.AreEqual(400, entries[12].Items.ElementAt(0).Dosage); Assert.AreEqual(300, entries[13].Items.ElementAt(0).Dosage); }
SupplementsCycleDTO startCycle(MyTrainingOperationType operation) { var cycle = new SupplementsCycleDTO(); cycle.RemindBefore = RemindBefore; var param = new MyTrainingOperationParam(); param.Operation = operation; param.MyTraining = cycle; if (Customer != null) { cycle.CustomerId = Customer.GlobalId; } cycle.TrainingDays = getTrainingDays(); cycle.TotalWeeks = TotalWeeks; cycle.SupplementsCycleDefinitionId = CycleDefinition.GlobalId; cycle.Name = CycleDefinition.Name;//TODO:user should allow change this name cycle.StartDate = StartDate.ToUniversalTime(); cycle.Weight = ((double?)Weight).ToSaveWeight(); return((SupplementsCycleDTO)ServiceManager.MyTrainingOperation(param)); }
public void Test() { var cycleDef = createCycle(); DateTime date = new DateTime(2012, 03, 26);//monday var cycle = new SupplementsCycleDTO(); cycle.Name = "Sterydy"; cycle.StartDate = date; cycle.SupplementsCycleDefinitionId = cycleDef.GlobalId; var profile1 = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile1, ClientInformation); MyTrainingDTO result = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { MyTrainingOperationParam param = new MyTrainingOperationParam(); param.Operation = MyTrainingOperationType.Start; param.MyTraining = cycle; result = service.MyTrainingOperation(data.Token, param); }); var dbCycle = Session.Get <SupplementCycle>(result.GlobalId); Assert.AreEqual(70, dbCycle.EntryObjects.Count); //Assert.AreEqual(SuplementsEntryDTO.EntryTypeId, dbCycle.TypeId); var entries = dbCycle.EntryObjects.OrderBy(x => x.TrainingDay.TrainingDate).Cast <SuplementsEntry>().ToList(); foreach (var entry in entries) { Assert.IsNotNull(entry.LoginData); Assert.IsNull(entry.Reminder); var item = entry.Items.ElementAt(0); Assert.AreEqual(1, entry.Items.Count); Assert.AreEqual(100, item.Dosage); Assert.AreEqual(Model.DosageType.MiliGrams, item.DosageType); Assert.AreEqual(Model.TimeType.NotSet, item.Time.TimeType); } }
public MyTrainingDTO MyTrainingOperation(MyTrainingOperationParam param) { Log.WriteWarning("MyTrainingOperation:Username={0},operation={1}", SecurityInfo.SessionData.Profile.UserName, param.Operation); using (var trans = Session.BeginSaveTransaction()) { var dbProfile = Session.Load <Profile>(SecurityInfo.SessionData.Profile.GlobalId); MyTraining dbCycle = null; if (param.Operation == MyTrainingOperationType.Start || param.Operation == MyTrainingOperationType.Simulate) { dbCycle = param.MyTraining.Map <MyTraining>(); ensureCanStartMyTraining(dbCycle, dbProfile); dbCycle.Profile = dbProfile; if (dbCycle is A6WTraining) { startA6WTraining(param, (A6WTraining)dbCycle, dbProfile); } else if (dbCycle is SupplementCycle) { SupplementsCycleDTO cycleDto = (SupplementsCycleDTO)param.MyTraining; startSupplementsCycle(param, (SupplementCycle)dbCycle, dbProfile, cycleDto.SupplementsCycleDefinitionId); } Session.Flush(); ProfileStatisticsUpdater.UpdateTrainindDay(Session, dbProfile); } else { dbCycle = StopMyTraining(param.MyTraining.GlobalId, dbProfile); } Session.SaveOrUpdate(dbCycle); if (param.Operation != MyTrainingOperationType.Simulate) {//for simulate we must reject all changes in the db trans.Commit(); } return(dbCycle.Map <MyTrainingDTO>()); } }
public void StartNewCycle_WithReminders() { definition = createCreating2DT1DNTDefinition(); DateTime date = new DateTime(2012, 03, 26);//monday var cycle = new SupplementsCycleDTO(); cycle.TrainingDays = string.Format("{0}S,{1}S,{2}S", (int)DayOfWeek.Monday, (int)DayOfWeek.Wednesday, (int)DayOfWeek.Friday); cycle.Name = "Creatine"; cycle.StartDate = date; cycle.RemindBefore = TimeSpan.FromMinutes(15); cycle.SupplementsCycleDefinitionId = definition.GlobalId; var profile1 = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile1, ClientInformation); MyTrainingDTO result = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { MyTrainingOperationParam param = new MyTrainingOperationParam(); param.Operation = MyTrainingOperationType.Start; param.MyTraining = cycle; result = service.MyTrainingOperation(data.Token, param); }); var dbCycle = Session.Get <SupplementCycle>(result.GlobalId); var entries = dbCycle.EntryObjects.OrderBy(x => x.TrainingDay.TrainingDate).Cast <SuplementsEntry>().ToList(); foreach (var entry in entries) { Assert.AreEqual(entry.TrainingDay.TrainingDate, entry.Reminder.DateTime.Date); Assert.AreEqual(TimeSpan.FromMinutes(15), entry.Reminder.RemindBefore); Assert.AreEqual("EntryObjectDTO:" + entry.GlobalId, entry.Reminder.ConnectedObject); Assert.AreEqual(ReminderRepetitions.Once, entry.Reminder.Repetitions); } }
public void StartNewCycle_Longer_PlanDoesntSupportLongerCycles() { definition = createCycleForRepetitions1(); DateTime date = new DateTime(2012, 03, 26);//monday var cycle = new SupplementsCycleDTO(); cycle.TrainingDays = string.Format("{0}S,{1}S,{2}S", (int)DayOfWeek.Monday, (int)DayOfWeek.Wednesday, (int)DayOfWeek.Friday); cycle.Name = "Creatine"; cycle.StartDate = date; cycle.TotalWeeks = 14; cycle.SupplementsCycleDefinitionId = definition.GlobalId; var profile1 = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile1, ClientInformation); RunServiceMethod(delegate(InternalBodyArchitectService service) { MyTrainingOperationParam param = new MyTrainingOperationParam(); param.Operation = MyTrainingOperationType.Start; param.MyTraining = cycle; service.MyTrainingOperation(data.Token, param); }); }
public void Test() { var cycleDef = createCycle(); DateTime date = new DateTime(2012, 03, 26);//monday var cycle = new SupplementsCycleDTO(); cycle.Name = "Sterydy"; cycle.Weight = 85; cycle.TrainingDays = string.Format("{0}C,{1}C,{2}C", (int)DayOfWeek.Monday, (int)DayOfWeek.Wednesday, (int)DayOfWeek.Friday); cycle.StartDate = date; cycle.SupplementsCycleDefinitionId = cycleDef.GlobalId; var profile1 = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile1, ClientInformation); MyTrainingDTO result = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { MyTrainingOperationParam param = new MyTrainingOperationParam(); param.Operation = MyTrainingOperationType.Start; param.MyTraining = cycle; result = service.MyTrainingOperation(data.Token, param); }); var dbCycle = Session.Get <SupplementCycle>(result.GlobalId); Assert.AreEqual(28, dbCycle.EntryObjects.Count); //Assert.AreEqual(SuplementsEntryDTO.EntryTypeId, dbCycle.TypeId); var entries = dbCycle.EntryObjects.OrderBy(x => x.TrainingDay.TrainingDate).Cast <SuplementsEntry>().ToList(); foreach (var entry in entries) { Assert.IsNotNull(entry.LoginData); Assert.IsNull(entry.Reminder); if (entry.TrainingDay.TrainingDate.DayOfWeek == DayOfWeek.Monday || entry.TrainingDay.TrainingDate.DayOfWeek == DayOfWeek.Wednesday || entry.TrainingDay.TrainingDate.DayOfWeek == DayOfWeek.Friday) { Assert.AreEqual(8.5, entry.Items.ElementAt(0).Dosage); Assert.AreEqual(Model.DosageType.Grams, entry.Items.ElementAt(0).DosageType); Assert.AreEqual(bcaa.GlobalId, entry.Items.ElementAt(0).Suplement.GlobalId); Assert.AreEqual(Model.TimeType.OnEmptyStomach, entry.Items.ElementAt(0).Time.TimeType); Assert.AreEqual(8.5, entry.Items.ElementAt(1).Dosage); Assert.AreEqual(Model.DosageType.Grams, entry.Items.ElementAt(1).DosageType); Assert.AreEqual(bcaa.GlobalId, entry.Items.ElementAt(1).Suplement.GlobalId); Assert.AreEqual(Model.TimeType.BeforeWorkout, entry.Items.ElementAt(1).Time.TimeType); Assert.AreEqual(8.5, entry.Items.ElementAt(2).Dosage); Assert.AreEqual(Model.DosageType.Grams, entry.Items.ElementAt(2).DosageType); Assert.AreEqual(bcaa.GlobalId, entry.Items.ElementAt(2).Suplement.GlobalId); Assert.AreEqual(Model.TimeType.AfterWorkout, entry.Items.ElementAt(2).Time.TimeType); } else { Assert.AreEqual(8.5, entry.Items.ElementAt(0).Dosage); Assert.AreEqual(Model.DosageType.Grams, entry.Items.ElementAt(0).DosageType); Assert.AreEqual(bcaa.GlobalId, entry.Items.ElementAt(0).Suplement.GlobalId); Assert.AreEqual(Model.TimeType.OnEmptyStomach, entry.Items.ElementAt(0).Time.TimeType); } } }