public void WeeksNumberLonger_NeedRepetit_2()
        {
            var definition = createCycleForRepetitions2();
            var repetiter = new SupplementsCycleRepetiter();
            var newDef = repetiter.Preapre(definition, 14);
            for (int i = 0; i < definition.Weeks.Count; i++)
            {
                Assert.AreEqual(newDef.Weeks.ElementAt(i).CycleWeekStart, definition.Weeks.ElementAt(i).CycleWeekStart);
                Assert.AreEqual(newDef.Weeks.ElementAt(i).CycleWeekEnd, definition.Weeks.ElementAt(i).CycleWeekEnd);
            }

            Assert.AreEqual(9,newDef.Weeks.Count);

            Assert.AreEqual(8, newDef.Weeks.ElementAt(4).CycleWeekStart);
            Assert.AreEqual(9, newDef.Weeks.ElementAt(4).CycleWeekEnd);
            Assert.AreEqual("Training week3", newDef.Weeks.ElementAt(4).Name);

            Assert.AreEqual(10, newDef.Weeks.ElementAt(5).CycleWeekStart);
            Assert.AreEqual(10, newDef.Weeks.ElementAt(5).CycleWeekEnd);
            Assert.AreEqual("Training week4", newDef.Weeks.ElementAt(5).Name);

            Assert.AreEqual(11, newDef.Weeks.ElementAt(6).CycleWeekStart);
            Assert.AreEqual(12, newDef.Weeks.ElementAt(6).CycleWeekEnd);
            Assert.AreEqual("Training week3", newDef.Weeks.ElementAt(6).Name);

            Assert.AreEqual(13, newDef.Weeks.ElementAt(7).CycleWeekStart);
            Assert.AreEqual(13, newDef.Weeks.ElementAt(7).CycleWeekEnd);
            Assert.AreEqual("Training week4", newDef.Weeks.ElementAt(7).Name);

            Assert.AreEqual(14, newDef.Weeks.ElementAt(8).CycleWeekStart);
            Assert.AreEqual(15, newDef.Weeks.ElementAt(8).CycleWeekEnd);
            Assert.AreEqual("Training week3", newDef.Weeks.ElementAt(8).Name);
        }
 public void WeeksNumberTheSameAsInDefinition_NoNeedRepetit()
 {
     var definition = createCycleForRepetitions1();
     var repetiter = new SupplementsCycleRepetiter();
     var newDef=repetiter.Preapre(definition, 7);
     for (int i = 0; i < definition.Weeks.Count; i++)
     {
         Assert.AreEqual(newDef.Weeks.ElementAt(i).CycleWeekStart, definition.Weeks.ElementAt(i).CycleWeekStart);
         Assert.AreEqual(newDef.Weeks.ElementAt(i).CycleWeekEnd, definition.Weeks.ElementAt(i).CycleWeekEnd);
     }
 }
        private void startSupplementsCycle(MyTrainingOperationParam param, SupplementCycle dbCycle, Profile dbProfile, Guid supplementsCycleDefinitionId)
        {
            dbCycle.Profile = dbProfile;

            var dbCycleDefinition = dbCycle.SupplementsCycleDefinition = Session.QueryOver <SupplementCycleDefinition>().Where(x => x.GlobalId == supplementsCycleDefinitionId).Fetch(x => x.Weeks).Eager.Fetch(x => x.Weeks.First().Dosages).Eager.SingleOrDefault();
            var definitionDTO     = dbCycleDefinition.Map <SupplementCycleDefinitionDTO>();
            SupplementsCycleRepetiter repetiter = new SupplementsCycleRepetiter();
            var preparedCycleDefinition         = repetiter.Preapre(definitionDTO, dbCycle.TotalWeeks);

            dbCycleDefinition = preparedCycleDefinition.Map <SupplementCycleDefinition>();

            for (int i = 0; i < dbCycleDefinition.GetTotalDays(dbCycle.TotalWeeks); i++)
            {
                createEntryObject(param.MyTraining, i, dbProfile, dbCycle, () =>
                {
                    List <EntryObject> entries = new List <EntryObject>();
                    var dosages = getDayDosages(dbCycleDefinition, i, dbCycle);
                    if (dosages.Count == 0)
                    {
                        return(entries);
                    }
                    if (dosages.OfType <SupplementCycleMeasurement>().Count() > 0)
                    {
                        SizeEntry sizeEntry = new SizeEntry();
                        entries.Add(sizeEntry);
                    }
                    var supplementEntries = dosages.OfType <SupplementCycleDosage>().ToList();
                    if (supplementEntries.Count == 0)
                    {
                        return(entries);
                    }
                    SuplementsEntry entry = new SuplementsEntry();
                    foreach (var dosage in supplementEntries)
                    {
                        SuplementItem item = new SuplementItem();
                        entry.AddItem(item);
                        item.Name          = dosage.Name;
                        item.Time.TimeType = (TimeType)dosage.TimeType;
                        item.Suplement     = Session.Load
                                             <Suplement>(dosage.Supplement.GlobalId);
                        item.Dosage = dosage.Dosage;
                        if (dosage.DosageUnit == BodyArchitect.Model.DosageUnit.ON10KgWight)
                        {
                            item.Dosage = (dosage.Dosage * (dbCycle.Weight / 10M)).RoundToNearestHalf();
                        }
                        item.DosageType = (DosageType)dosage.DosageType;
                    }
                    entries.Add(entry);
                    return(entries);
                });
            }
        }
        protected override void PrepareData()
        {
            SupplementsCycleRepetiter repetiter = new SupplementsCycleRepetiter();

            definition = repetiter.Preapre(originalDefinition, Weeks);
        }