コード例 #1
0
        public void AssertInsertPlannedRuns()
        {
            var builder = new AthleteBuilder();

            var athlete = builder.Build();

            var selectedDays = WeekdaySelectionEnumeration.FifthDayOfWeek | WeekdaySelectionEnumeration.SeventhDayOfWeek;

            var trainingPlan = new TrainingPlan
                                   {
                                       Workload = 50,
                                       Goal = CreateGoal(),
                                       Athlete = athlete,
                                       Start = new DateTime(2009, 1, 1),
                                       StartDistance = 2000,
                                       PreferredWeekdays = (int)selectedDays
                                   };

            MemoryDataContext.Clear();
            Assert.IsTrue(MemoryDataContext.IsEmpty);
            MemoryDataContext.InsertOnSubmit(athlete);
            MemoryDataContext.InsertOnSubmit(trainingPlan);
            MemoryDataContext.Commit();

            var runDataAccess = new RunDataAccess();

            runDataAccess.CreateRuns(trainingPlan);

            Assert.AreEqual(47, MemoryDataContext.Queryable<Run>().Count());
        }
コード例 #2
0
ファイル: RunDataAccess.cs プロジェクト: 1pindsvin/yagni
        public void CreateRuns(TrainingPlan trainingPlan)
        {
            var existingPlan = _dataContext.GetExisting(trainingPlan);
            var existingAthlete = _dataContext.GetExisting(trainingPlan.Athlete);

            DeleteFuturePlannedRuns(existingPlan);

            var trainer = new Trainer();
            var runs = trainer.CreateRuns(existingAthlete, existingPlan);
            foreach (var run in runs)
            {
                run.Athlete = existingAthlete;
                run.TrainingPlan = existingPlan;
                run.LastChanged = DateTime.Now;
                _dataContext.InsertOnSubmit(run);
            }
            _dataContext.Commit();
        }
コード例 #3
0
ファイル: AthleteDataAccess.cs プロジェクト: 1pindsvin/yagni
        public TrainingPlan SaveTrainingPlan(TrainingPlan trainingPlan)
        {
            DataContext.RollbackAndAttach(trainingPlan.Athlete);
            trainingPlan.Goal.Athlete = trainingPlan.Athlete;
            if (trainingPlan.ID > 0)
            {
                DataContext.UpdateAndAttach(trainingPlan.Goal);
                DataContext.UpdateAndAttach(trainingPlan);
            }
            else
            {
                DataContext.InsertOnSubmit(trainingPlan);
            }
            DataContext.Commit();

            var runDataAccess = new RunDataAccess(DataContext);
            runDataAccess.CreateRuns(trainingPlan);

            return trainingPlan;
        }
コード例 #4
0
ファイル: RunDataAccess.cs プロジェクト: 1pindsvin/yagni
 public List<Run> GetPlannedRuns(TrainingPlan trainingPlan)
 {
     if (trainingPlan.ID <= 0)
     {
         throw new InvalidOperationException("trainingPlan.ID <= 0");
     }
     if (trainingPlan.Athlete == null)
     {
         throw new InvalidOperationException("trainingPlan.Athlete == null");
     }
     return GetRuns(trainingPlan.Athlete).Where(x => x.TrainingPlanID == trainingPlan.ID).ToList();
 }
コード例 #5
0
ファイル: Db.designer.cs プロジェクト: 1pindsvin/yagni
 partial void DeleteTrainingPlan(TrainingPlan instance);
コード例 #6
0
ファイル: RunDataAccess.cs プロジェクト: 1pindsvin/yagni
 private void DeleteFuturePlannedRuns(TrainingPlan trainingPlan)
 {
     var runs =
         _dataContext.Queryable<Run>().Where(
             x => x.TrainingPlan.ID == trainingPlan.ID && x.Start >= trainingPlan.Start);
     foreach (var run in runs)
     {
         _dataContext.DeleteOnSubmit(run);
     }
     _dataContext.Commit();
 }
コード例 #7
0
ファイル: Db.designer.cs プロジェクト: 1pindsvin/yagni
 partial void UpdateTrainingPlan(TrainingPlan instance);
コード例 #8
0
ファイル: Db.designer.cs プロジェクト: 1pindsvin/yagni
 partial void InsertTrainingPlan(TrainingPlan instance);
コード例 #9
0
ファイル: CreatePlannedRuns.cs プロジェクト: 1pindsvin/yagni
 private static TrainingPlan CreatePlan(Athlete athlete, WeekdaySelectionEnumeration trainingDays)
 {
     var trainingPlan = new TrainingPlan
                            {
                                Workload = 50,
                                Goal = CreateGoal(),
                                Athlete = athlete,
                                Start = new DateTime(2009, 1, 1),
                                StartDistance = 2000,
                                PreferredWeekdays = (int) trainingDays
                            };
     return trainingPlan;
 }
コード例 #10
0
 public TrainingPlan Build()
 {
     var plan = new TrainingPlan {Goal = new Goal(), ID = _ID};
     return plan;
 }
コード例 #11
0
ファイル: Trainer.cs プロジェクト: 1pindsvin/yagni
        public IEnumerable<Run> CreateRuns(Athlete athlete, TrainingPlan plan)
        {
            TrainingPlan = plan;
            Athlete = athlete;

            plan.EnsureIsValid();

            var workload = Convert.ToDouble(plan.Workload) / 100;
            WeeklyProgression *= workload;

            var goaledSequencer = BuildSequencer();
            return CreateRuns(plan.DaysAsWeekdaySelectionEnumeration(), goaledSequencer);
        }