public void StartA6WTraining()
        {
            DateTime date  = new DateTime(2012, 03, 26);//monday
            var      cycle = new A6WTrainingDTO();

            cycle.Name      = "My A6W";
            cycle.StartDate = date;
            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 <MyTraining>(result.GlobalId);

            Assert.AreEqual(42, dbCycle.EntryObjects.Count);
            //Assert.AreEqual(SuplementsEntryDTO.EntryTypeId, dbCycle.TypeId);
            var entries = dbCycle.EntryObjects.OrderBy(x => x.TrainingDay.TrainingDate).Cast <A6WEntry>().ToList();

            Assert.AreEqual(date, entries.ElementAt(0).TrainingDay.TrainingDate);
            Assert.AreEqual(date.AddDays(41), entries.ElementAt(41).TrainingDay.TrainingDate);
            foreach (var entry in entries)
            {
                Assert.AreEqual(Model.EntryObjectStatus.Planned, entry.Status);
            }
        }
        public void StartA6WTraining_TrainingDayStatistics()
        {
            DateTime date  = new DateTime(2012, 03, 26);//monday
            var      cycle = new A6WTrainingDTO();

            cycle.Name      = "My A6W";
            cycle.StartDate = date;
            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 dbProfile = Session.Get <Profile>(profiles[0].GlobalId);

            Assert.AreEqual(42, dbProfile.Statistics.TrainingDaysCount);
            Assert.IsNotNull(dbProfile.Statistics.LastEntryDate);
            Assert.AreEqual(0, dbProfile.Statistics.A6WFullCyclesCount);
            Assert.AreEqual(42, dbProfile.Statistics.A6WEntriesCount);
        }
        public void StartA6WTraining_ResultEntries()
        {
            DateTime date  = new DateTime(2012, 03, 26);//monday
            var      cycle = new A6WTrainingDTO();

            cycle.Name      = "My A6W";
            cycle.StartDate = date;
            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 entries = result.EntryObjects.OrderBy(x => x.TrainingDay.TrainingDate).ToList();

            for (int index = 0; index < entries.Count; index++)
            {
                var entry = (A6WEntryDTO)entries[index];
                Assert.AreEqual(index + 1, entry.Day.DayNumber);
                Assert.IsNull(entry.RemindBefore);
                Assert.AreEqual(EntryObjectStatus.Planned, entry.Status);
            }
        }
        public void StartAlreadyStartedA6WTraining()
        {
            DateTime date  = new DateTime(2012, 03, 26);//monday
            var      cycle = new A6WTrainingDTO();

            cycle.Name      = "My A6W";
            cycle.StartDate = date;
            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);
            });

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                var param        = new MyTrainingOperationParam();
                param.Operation  = MyTrainingOperationType.Start;
                param.MyTraining = result;
                service.MyTrainingOperation(data.Token, param);
            });
        }
        public void StartA6WTraining_ForCustomer_EntriesBelongsToCustomer()
        {
            var      cust  = CreateCustomer("test", profiles[0]);
            DateTime date  = new DateTime(2012, 03, 26);//monday
            var      cycle = new A6WTrainingDTO();

            cycle.Name       = "My A6W";
            cycle.StartDate  = date;
            cycle.CustomerId = cust.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 a6w = Session.Get <A6WTraining>(result.GlobalId);

            foreach (var entryObject in a6w.EntryObjects)
            {
                Assert.AreEqual(cust.GlobalId, entryObject.TrainingDay.Customer.GlobalId);
                Assert.AreEqual(profiles[0].GlobalId, entryObject.TrainingDay.Profile.GlobalId);
            }
        }
        public void FinishTraining_BySaveTrainingDay()
        {
            DateTime date  = new DateTime(2012, 03, 26);//monday
            var      cycle = new A6WTrainingDTO();

            cycle.Name      = "My A6W";
            cycle.StartDate = date;
            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 dbTrainingDay = Session.QueryOver <TrainingDay>().Fetch(x => x.Objects).Eager.Fetch(x => x.Objects.First().MyTraining).Eager.List();

            for (int i = 0; i < 41; i++)
            {
                dbTrainingDay[i].Objects.ElementAt(0).Status = Model.EntryObjectStatus.Done;
                insertToDatabase(dbTrainingDay[i].Objects.ElementAt(0));
            }
            //mark last entry as Done
            var dtoTrainingDay = dbTrainingDay[41].Map <TrainingDayDTO>();

            dtoTrainingDay.Objects[0].Status = Service.V2.Model.EntryObjectStatus.Done;
            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                TimerService.UtcNow = DateTime.UtcNow.AddDays(3).Date;
                var res             = service.SaveTrainingDay(data.Token, dtoTrainingDay);
                dtoTrainingDay      = res.TrainingDay;
            });
            Assert.AreEqual(DateTime.UtcNow.AddDays(3).Date, dtoTrainingDay.Objects[0].MyTraining.EndDate);
            Assert.AreEqual(100, dtoTrainingDay.Objects[0].MyTraining.PercentageCompleted);
            Assert.AreEqual(Service.V2.Model.TrainingEnd.Complete, dtoTrainingDay.Objects[0].MyTraining.TrainingEnd);

            var dbCycle = Session.Get <MyTraining>(result.GlobalId);

            Assert.AreEqual(DateTime.UtcNow.AddDays(3).Date, dbCycle.EndDate);
            Assert.AreEqual(100, dbCycle.PercentageCompleted);
            Assert.AreEqual(Model.TrainingEnd.Complete, dbCycle.TrainingEnd);
        }
Example #7
0
        A6WTrainingDTO startCycle(MyTrainingOperationType operation)
        {
            var cycle = new A6WTrainingDTO();

            cycle.RemindBefore = RemindBefore;
            var param = new MyTrainingOperationParam();

            param.Operation  = operation;
            param.MyTraining = cycle;
            cycle.Name       = Name;
            if (Customer != null)
            {
                cycle.CustomerId = Customer.GlobalId;
            }
            cycle.StartDate = StartDate.ToUniversalTime();
            return((A6WTrainingDTO)ServiceManager.MyTrainingOperation(param));
        }
        public void SaveOnceEntryAsDoneAndStopTraining_TrainingDayStatistics()
        {
            DateTime date  = new DateTime(2012, 03, 26);//monday
            var      cycle = new A6WTrainingDTO();

            cycle.Name      = "My A6W";
            cycle.StartDate = date;
            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 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 = Service.V2.Model.EntryObjectStatus.Done;
            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                dtoTrainingDay = service.SaveTrainingDay(data.Token, dtoTrainingDay).TrainingDay;
            });

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                var param        = new MyTrainingOperationParam();
                param.Operation  = MyTrainingOperationType.Stop;
                param.MyTraining = 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(0, dbProfile.Statistics.A6WFullCyclesCount);
            Assert.AreEqual(1, dbProfile.Statistics.A6WEntriesCount);
        }
        public void FinishA6WTraining_Statistics_PartiallyCompleted()
        {
            DateTime date  = new DateTime(2012, 03, 26);//monday
            var      cycle = new A6WTrainingDTO();

            cycle.Name      = "My A6W";
            cycle.StartDate = date;
            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);
            });
            Run(s =>
            {
                for (int index = 0; index < 12; index++)
                {
                    var entryObjectDto = result.EntryObjects[index];
                    var entry          = s.Get <EntryObject>(entryObjectDto.GlobalId);
                    entry.Status       = Model.EntryObjectStatus.Done;
                    s.Update(entry);
                }
            });

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                var param        = new MyTrainingOperationParam();
                param.Operation  = MyTrainingOperationType.Stop;
                param.MyTraining = result;
                result           = service.MyTrainingOperation(data.Token, param);
            });
            var dbProfile = Session.Get <Profile>(profiles[0].GlobalId);

            Assert.AreEqual(12, dbProfile.Statistics.TrainingDaysCount);
            Assert.AreEqual(0, dbProfile.Statistics.A6WFullCyclesCount);
            Assert.AreEqual(12, dbProfile.Statistics.A6WEntriesCount);
        }
        public void StartA6WTraining_WithReminders_ForCustomer()
        {
            var      cust  = CreateCustomer("cust", profiles[0]);
            DateTime date  = new DateTime(2012, 03, 26);//monday
            var      cycle = new A6WTrainingDTO();

            cycle.Name         = "My A6W";
            cycle.StartDate    = date;
            cycle.RemindBefore = TimeSpan.FromMinutes(15);
            cycle.CustomerId   = cust.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 <MyTraining>(result.GlobalId);
            var entries = dbCycle.EntryObjects.OrderBy(x => x.TrainingDay.TrainingDate).Cast <A6WEntry>().ToList();

            Assert.AreEqual(cust.GlobalId, dbCycle.Customer.GlobalId);
            foreach (var entry in entries)
            {
                Assert.AreEqual(entry.TrainingDay.TrainingDate, entry.Reminder.DateTime.Date);
                Assert.AreEqual(cust.GlobalId, entry.TrainingDay.Customer.GlobalId);
                Assert.AreEqual(TimeSpan.FromMinutes(15), entry.Reminder.RemindBefore);
                Assert.AreEqual("EntryObjectDTO:" + entry.GlobalId, entry.Reminder.ConnectedObject);
                Assert.AreEqual(ReminderRepetitions.Once, entry.Reminder.Repetitions);
            }
            //if we start training for customers then profile statistic shouldn't be changed
            var dbProfile = Session.Get <Profile>(profiles[0].GlobalId);

            Assert.AreEqual(0, dbProfile.Statistics.TrainingDaysCount);
            Assert.IsNull(dbProfile.Statistics.LastEntryDate);
            Assert.AreEqual(0, dbProfile.Statistics.A6WFullCyclesCount);
            Assert.AreEqual(0, dbProfile.Statistics.A6WEntriesCount);
        }
        public void StartA6WTraining_ForCustomerFromAnotherProfile()
        {
            var      cust  = CreateCustomer("test", profiles[1]);
            DateTime date  = new DateTime(2012, 03, 26);//monday
            var      cycle = new A6WTrainingDTO();

            cycle.Name       = "My A6W";
            cycle.StartDate  = date;
            cycle.CustomerId = cust.GlobalId;
            var         profile1 = (ProfileDTO)profiles[0].Tag;
            SessionData data     = CreateNewSession(profile1, ClientInformation);

            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                var param        = new MyTrainingOperationParam();
                param.Operation  = MyTrainingOperationType.Start;
                param.MyTraining = cycle;
                service.MyTrainingOperation(data.Token, param);
            });
        }
        public void DeleteTrainingDayWithTrainingEntry()
        {
            DateTime date  = new DateTime(2012, 03, 26);//monday
            var      cycle = new A6WTrainingDTO();

            cycle.Name      = "My A6W";
            cycle.StartDate = date;
            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 dbTrainingDay = Session.QueryOver <TrainingDay>().Fetch(x => x.Objects).Eager.Fetch(x => x.Objects.First().MyTraining).Eager.List();

            for (int i = 0; i < 41; i++)
            {
                dbTrainingDay[i].Objects.ElementAt(0).Status = Model.EntryObjectStatus.Done;
                insertToDatabase(dbTrainingDay[i].Objects.ElementAt(0));
            }
            var dtoTrainingDay = dbTrainingDay[40].Map <TrainingDayDTO>();

            dtoTrainingDay.Objects.RemoveAt(0);
            RunServiceMethod(delegate(InternalBodyArchitectService service)
            {
                DeleteTrainingDayParam param = new DeleteTrainingDayParam();
                param.TrainingDayId          = dtoTrainingDay.GlobalId;
                param.Mode          = DeleteTrainingDayMode.All;
                TimerService.UtcNow = DateTime.UtcNow.AddDays(3).Date;
                service.DeleteTrainingDay(data.Token, param);
            });
        }
        public void SimulateA6WTraining_EntriesInDb()
        {
            DateTime date  = new DateTime(2012, 03, 26);//monday
            var      cycle = new A6WTrainingDTO();

            cycle.Name      = "My A6W";
            cycle.StartDate = date;
            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 <A6WEntry>().RowCount());
            Assert.AreEqual(0, Session.QueryOver <TrainingDay>().RowCount());
            Assert.AreEqual(0, Session.QueryOver <SupplementCycle>().RowCount());
        }