public void PracticeRoutineRepository_Insert_New_PracticeRoutine_Then_Update_Inserts_New_TimeSlotExercises() { Funcs.RunScript("delete-all-records.sql", Settings.AppConnectionString); using (var uow = Funcs.GetUnitOfWork()) { PracticeRoutine practiceRoutine = new PracticeRoutine("Created PracticeRoutine", new List <PracticeRoutineTimeSlot>()); uow.PracticeRoutines.Add(practiceRoutine); uow.Commit(); var exercise1 = EntityFactory.CreateExercise("Exercise 1"); var exercise2 = EntityFactory.CreateExercise("Exercise 2"); var exercise3 = EntityFactory.CreateExercise("Exercise 3"); uow.Exercises.Add(exercise1); uow.Exercises.Add(exercise2); uow.Exercises.Add(exercise3); uow.Commit(); TimeSlotExercise timeSlotExercise1 = new TimeSlotExercise(exercise1.Id, exercise1.Title, 3); TimeSlotExercise timeSlotExercise2 = new TimeSlotExercise(exercise2.Id, exercise2.Title, 3); TimeSlotExercise timeSlotExercise3 = new TimeSlotExercise(exercise3.Id, exercise3.Title, 3); List <TimeSlotExercise> timeSlotExercises1 = new List <TimeSlotExercise> { timeSlotExercise1, timeSlotExercise2 }; List <TimeSlotExercise> timeSlotExercises2 = new List <TimeSlotExercise> { timeSlotExercise3 }; PracticeRoutine existingPracticeRoutine = uow.PracticeRoutines.Get(practiceRoutine.Id); existingPracticeRoutine.Add(new PracticeRoutineTimeSlot("Time Slot 1", 5, timeSlotExercises1)); existingPracticeRoutine.Add(new PracticeRoutineTimeSlot("Time Slot 2", 5, timeSlotExercises2)); uow.PracticeRoutines.Update(existingPracticeRoutine); uow.Commit(); var updatedPracticeRoutine = uow.PracticeRoutines.Get(existingPracticeRoutine.Id); Assert.AreEqual(1, updatedPracticeRoutine.Where(t => t.Title == "Time Slot 1").Count()); Assert.AreEqual(1, updatedPracticeRoutine.Where(t => t.Title == "Time Slot 2").Count()); Assert.AreEqual(2, updatedPracticeRoutine.Where(t => t.Title == "Time Slot 1").First().Count()); Assert.AreEqual(1, updatedPracticeRoutine.Where(t => t.Title == "Time Slot 2").First().Count()); } }
private void AddTimeSlot() { PracticeRoutineTimeSlot timeSlot = new PracticeRoutineTimeSlot("New Time Slot", 300, new List <TimeSlotExercise>()); practiceRoutine.Add(timeSlot); TimeSlots.Add(new TimeSlotViewModel(timeSlot)); }