public List<Athlete> CreateRandomAthletes(int numberOfAthletes) { var r = new RandomProvider(); var dateMin = new DateTime(1920, 1, 1); var dateMax = new DateTime(2020, 1, 1); var athletes = new List<Athlete>(); using (var db = new DbDataContext()) { var athleteCountBefore = db.Athletes.Count(); for (var i = 0; i < numberOfAthletes; i++) { var firstName = _randomFirstNamePrefix + i; var lastName = _randomLastNamePrefix + i; //var guid = Guid.NewGuid().ToString(); var user = new User { Password = "******", UserName = firstName, Roles = "" }; var athlete = new Athlete { FirstName = firstName, LastName = lastName, DateOfBirth = r.Next(dateMin, dateMax), User = user }; athletes.Add(athlete); db.Users.InsertOnSubmit(user); } db.SubmitChanges(); var athleteCountAfter = db.Athletes.Count(); Assert.AreEqual(numberOfAthletes, athletes.Count); Assert.AreEqual(athleteCountAfter, athleteCountBefore + numberOfAthletes); } return athletes; }
private static void InsertAthleteRuns(Athlete athlete, int numberOfRunsToInsert) { var r = new RandomProvider(); using (var db = new DbDataContext()) { var timeMin = 1000; var timeMax = 10000; var distanceMin = 5000; var distanceMax = 12000; var dateMin = new DateTime(1920, 1, 1); var dateMax = new DateTime(2020, 1, 1); var runCountBefore = db.Runs.Count(); const bool athleteModified = false; db.Athletes.Attach(athlete, athleteModified); var runs = new List<Run>(); for (var i = 0; i < numberOfRunsToInsert; i++) { var run = new Run { Athlete = athlete, Time = r.Next(timeMin, timeMax), Distance = r.Next(distanceMin, distanceMax), Start = r.Next(dateMin, dateMax) }; runs.Add(run); if (runs.Count > 5000) { db.Runs.InsertAllOnSubmit(runs); db.SubmitChanges(); runs.Clear(); } } if (runs.Count > 0) { db.Runs.InsertAllOnSubmit(runs); db.SubmitChanges(); runs.Clear(); } var afterRunsInsertedCount = db.Runs.Count(); Assert.AreEqual(runCountBefore, afterRunsInsertedCount - numberOfRunsToInsert); } }