private void Delete() { if (SelectedItem is TimeSlotViewModel) { if (dialogService.YesNoPrompt("Delete Timeslot", "Sure you want to delete this time slot and all of its contents?")) { practiceRoutine.Remove((SelectedItem as TimeSlotViewModel).TimeSlot); TimeSlots.Remove(SelectedItem as TimeSlotViewModel); } } else { if (dialogService.YesNoPrompt("Remove Exercise", "Sure you want to remove this exercise from the timeslot?")) { var exerciseViewModel = SelectedItem as TimeSlotExerciseViewModel; var timeSlotViewModel = exerciseViewModel.TimeSlotViewModel; timeSlotViewModel.TimeSlot.Remove(exerciseViewModel.TimeSlotExercise); timeSlotViewModel.Remove(exerciseViewModel); } } }
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"); } }