public void PracticeRoutineRepository_Insert_New_PracticeRoutine_Inserts_New_TimeSlotExercises() { Funcs.RunScript("delete-all-records.sql", Settings.AppConnectionString); using (var uow = Funcs.GetUnitOfWork()) { 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 }; List <PracticeRoutineTimeSlot> timeSlots = new List <PracticeRoutineTimeSlot> { new PracticeRoutineTimeSlot("Time Slot 1", 5, timeSlotExercises1), new PracticeRoutineTimeSlot("Time Slot 2", 5, timeSlotExercises2), }; PracticeRoutine practiceRoutine = new PracticeRoutine("Created PracticeRoutine", timeSlots); uow.PracticeRoutines.Add(practiceRoutine); uow.Commit(); PracticeRoutine insertedPracticeRoutine = uow.PracticeRoutines.Get(practiceRoutine.Id); Assert.AreEqual(1, insertedPracticeRoutine.Where(t => t.Title == "Time Slot 1").Count()); Assert.AreEqual(1, insertedPracticeRoutine.Where(t => t.Title == "Time Slot 2").Count()); Assert.AreEqual(2, insertedPracticeRoutine.Where(t => t.Title == "Time Slot 1").First().Count()); Assert.AreEqual(1, insertedPracticeRoutine.Where(t => t.Title == "Time Slot 2").First().Count()); } }
public void PracticeRoutineRepository_Existing_PracticeRoutine_Deletes_Children_Successfully() { Funcs.RunScript("delete-all-records.sql", Settings.AppConnectionString); using (var uow = Funcs.GetUnitOfWork()) { var exercise1 = EntityFactory.CreateExercise("Exercise 1"); var exercise2 = EntityFactory.CreateExercise("Exercise 2"); var exercise3 = EntityFactory.CreateExercise("Exercise 3"); var exercise4 = EntityFactory.CreateExercise("Exercise 4"); uow.Exercises.Add(exercise1); uow.Exercises.Add(exercise2); uow.Exercises.Add(exercise3); uow.Exercises.Add(exercise4); 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); TimeSlotExercise timeSlotExercise4 = new TimeSlotExercise(exercise4.Id, exercise4.Title, 3); List <TimeSlotExercise> timeSlotExercises1 = new List <TimeSlotExercise> { timeSlotExercise1, timeSlotExercise2 }; List <TimeSlotExercise> timeSlotExercises2 = new List <TimeSlotExercise> { timeSlotExercise3 }; List <TimeSlotExercise> timeSlotExercises3 = new List <TimeSlotExercise> { timeSlotExercise4 }; List <PracticeRoutineTimeSlot> timeSlots = new List <PracticeRoutineTimeSlot> { new PracticeRoutineTimeSlot("Time Slot 1", 300, timeSlotExercises1), new PracticeRoutineTimeSlot("Time Slot 2", 300, timeSlotExercises2), new PracticeRoutineTimeSlot("Time Slot 3", 300, timeSlotExercises3) }; PracticeRoutine practiceRoutine = new PracticeRoutine("Created PracticeRoutine", timeSlots); uow.PracticeRoutines.Add(practiceRoutine); uow.Commit(); PracticeRoutine existingPracticeRoutine = uow.PracticeRoutines.Get(practiceRoutine.Id); // --------------------- delete some ---------------------------------------------------- existingPracticeRoutine.Remove(existingPracticeRoutine.Where(ts => ts.Title == "Time Slot 3").Single()); var removeExercise = existingPracticeRoutine .Where(ts => ts.Title == "Time Slot 1").Single() .Where(ex => ex.Title == "Exercise 1").Single(); existingPracticeRoutine .Where(ts => ts.Title == "Time Slot 1").Single() .Remove(removeExercise); // --------------------- delete some ---------------------------------------------------- uow.PracticeRoutines.Update(existingPracticeRoutine); uow.Commit(); var modifiedPracticeRoutine = uow.PracticeRoutines.Get(practiceRoutine.Id); var timeSlotCount = modifiedPracticeRoutine.Count(); // should be one less after deletion of timeslot. var removedExercise = modifiedPracticeRoutine .Where(ts => ts.Title == "Time Slot 1").Single() .Where(ex => ex.Title == "Exercise 1").SingleOrDefault(); var timeSlot1ExerciseCount = modifiedPracticeRoutine .Where(ts => ts.Title == "Time Slot 1").Single() .Count; // should be one less after deletion of exercise. var timeSlot1RemainingExercise = modifiedPracticeRoutine .Where(ts => ts.Title == "Time Slot 1").Single() .Single(); // should be one less after deletion of exercise. var timeSlot2Exercise = modifiedPracticeRoutine .Where(ts => ts.Title == "Time Slot 2").Single() .Single(); // should be one less after deletion of exercise. Assert.AreEqual(2, timeSlotCount, "There should only be two time slots left (Time Slot 3 and its children have been deleted"); Assert.AreEqual(1, timeSlot1ExerciseCount); Assert.That(timeSlot1RemainingExercise.Title, Is.EqualTo("Exercise 2"), "The last remaining exercise in Time Slot 1 should be Exercise 2"); Assert.That(timeSlot2Exercise.Title, Is.EqualTo("Exercise 3"), "The exercise in Time Slot 2 should be Exercise 3"); } }
public void PracticeRoutineRepository_Update_New_PracticeRoutine_Updates_New_TimeSlotExercises() { Funcs.RunScript("delete-all-records.sql", Settings.AppConnectionString); using (var uow = Funcs.GetUnitOfWork()) { var exercise1 = EntityFactory.CreateExercise("Exercise 1"); var exercise2 = EntityFactory.CreateExercise("Exercise 2"); uow.Exercises.Add(exercise1); uow.Exercises.Add(exercise2); uow.Commit(); TimeSlotExercise timeSlotExercise1 = new TimeSlotExercise(exercise1.Id, exercise1.Title, 3); TimeSlotExercise timeSlotExercise2 = new TimeSlotExercise(exercise2.Id, exercise2.Title, 3); List <TimeSlotExercise> timeSlotExercises1 = new List <TimeSlotExercise> { timeSlotExercise1, timeSlotExercise2 }; List <PracticeRoutineTimeSlot> timeSlots = new List <PracticeRoutineTimeSlot> { new PracticeRoutineTimeSlot("Time Slot 1", 300, timeSlotExercises1) }; PracticeRoutine practiceRoutine = new PracticeRoutine("Created PracticeRoutine", timeSlots); uow.PracticeRoutines.Add(practiceRoutine); uow.Commit(); PracticeRoutine insertedPracticeRoutine = uow.PracticeRoutines.Get(practiceRoutine.Id); var modifiedTimeSlot = insertedPracticeRoutine .Where(tslot => tslot.Title == "Time Slot 1").Single(); var modifiedExercise = insertedPracticeRoutine .Where(tslot => tslot.Title == "Time Slot 1").Single() .Where(ex => ex.Title == "Exercise 1").ToList() .First(); modifiedTimeSlot.Title = "Modified Time Slot 1"; modifiedTimeSlot.AssignedSeconds = 600; modifiedExercise.FrequencyWeighting = 10; uow.PracticeRoutines.Update(insertedPracticeRoutine); uow.Commit(); var modifiedPracticeRoutine = uow.PracticeRoutines.Get(practiceRoutine.Id); var changedTimeSlot = modifiedPracticeRoutine .Where(tslot => tslot.Title == "Modified Time Slot 1").Single(); var exerciseCount = modifiedPracticeRoutine .Where(tslot => tslot.Title == "Modified Time Slot 1").Single() .Count(); var changedExercise = modifiedPracticeRoutine .Where(tslot => tslot.Title == "Modified Time Slot 1").Single() .Where(ex => ex.Title == "Exercise 1") .SingleOrDefault(); var unchangedExercise = modifiedPracticeRoutine .Where(tslot => tslot.Title == "Modified Time Slot 1").Single() .Where(ex => ex.Title == "Exercise 2") .SingleOrDefault(); Assert.That(changedTimeSlot.AssignedSeconds, Is.EqualTo(600)); Assert.That(changedExercise.FrequencyWeighting, Is.EqualTo(10)); Assert.That(unchangedExercise.FrequencyWeighting, Is.EqualTo(3)); Assert.That(exerciseCount, Is.EqualTo(2)); } }