public void WhenGoalIsNewShouldAddInstance() { var dataAccess = new AthleteDataAccess(); var athlete = new Athlete { ID = 1 }; MemoryDataContext.Clear(); MemoryDataContext.InsertOnSubmit(athlete); MemoryDataContext.Commit(); Assert.AreEqual(0, MemoryDataContext.Queryable<Goal>().Count()); var goal = new Goal {Athlete = athlete}; dataAccess.SaveGoal(goal); Assert.AreEqual(1, MemoryDataContext.Queryable<Goal>().Count()); }
public void WhenGoalExistShouldUpdateExistingGoal() { var dataAccess = new AthleteDataAccess(); var athlete = new Athlete { ID = 1 }; MemoryDataContext.Clear(); MemoryDataContext.InsertOnSubmit(athlete); MemoryDataContext.Commit(); var goal = new Goal { Athlete = athlete }; dataAccess.SaveGoal(goal); goal.ID = 1; Assert.AreEqual(1, MemoryDataContext.Queryable<Goal>().Count()); dataAccess.SaveGoal(goal); Assert.AreEqual(1, MemoryDataContext.Queryable<Goal>().Count()); }
Goal CreateGoal() { var goal = new Goal { Distance = 10000 }; return goal; }
public void SaveGoal(Goal goal) { DataContext.RollbackAndAttach(goal.Athlete); if (goal.ID > 0) { DataContext.UpdateAndAttach(goal); } else { DataContext.InsertOnSubmit(goal); } DataContext.Commit(); }
partial void DeleteGoal(Goal instance);
partial void UpdateGoal(Goal instance);
partial void InsertGoal(Goal instance);
private double ResolveLastTrainingDistance(Goal goal) { var fractionOfGoalForlastTraining = Convert.ToDouble(PercentageOfGoalForLastTraining) / 100; var lastTrainingDistance = Convert.ToInt32(goal.Distance * fractionOfGoalForlastTraining); return lastTrainingDistance; }
private double ResolveLastRestituteDistance(Goal goal) { var fractionOfGoalForlastRestitution = Convert.ToDouble(PercentageOfGoalForLastRestitution) / 100; var lastRestituteDistance = Convert.ToInt32(goal.Distance * fractionOfGoalForlastRestitution); return lastRestituteDistance; }