public static TimeSlotExercise GetTimeSlotExercise(int id = 1, string title = "Existing Exercise", int frequencyRating = 50) { var exercise = new TimeSlotExercise(id, title, frequencyRating); return(exercise); }
public void TimeSlotExerciseViewModel_Title_Is_Populated_When_Initialized() { PracticeRoutineTimeSlot timeSlot = EntityFactory.GetSingleTimeSlot(); TimeSlotViewModel timeSlotViewModel = new TimeSlotViewModel(timeSlot); TimeSlotExercise timeSlotExercise = EntityFactory.GetTimeSlotExercise(); TimeSlotExerciseViewModel viewModel = new TimeSlotExerciseViewModel(timeSlotExercise, timeSlotViewModel); Assert.AreEqual("Existing Exercise", viewModel.Title); }
public void TimeSlotExerciseViewModel_Exposes_TimeSlotExercise() { PracticeRoutineTimeSlot timeSlot = EntityFactory.GetSingleTimeSlot(); TimeSlotViewModel timeSlotViewModel = new TimeSlotViewModel(timeSlot); TimeSlotExercise timeSlotExercise = EntityFactory.GetTimeSlotExercise(); TimeSlotExerciseViewModel viewModel = new TimeSlotExerciseViewModel(timeSlotExercise, timeSlotViewModel); Assert.IsNotNull(viewModel.TimeSlotExercise); Assert.AreEqual(timeSlot[0].Title, viewModel.TimeSlotExercise.Title); }
public void UpdateTimeSlotExercise(TimeSlotExercise exercise) { Connection.ExecuteScalar <int>(sql: "sp_UpdateTimeSlotExercise", param: new { _exerciseId = exercise.Id, _timeSlotId = exercise.TimeSlotId, _frequencyWeighting = exercise.FrequencyWeighting }, commandType: CommandType.StoredProcedure ); }
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 AddTimeSlotExercise(TimeSlotExercise timeSlotExercise) { if (SelectedItem is TimeSlotViewModel) { var timeSlotViewModel = SelectedItem as TimeSlotViewModel; TimeSlotExerciseViewModel timeSlotExerciseViewModel = new TimeSlotExerciseViewModel(timeSlotExercise, timeSlotViewModel); timeSlotViewModel.TimeSlot.Add(timeSlotExercise); timeSlotViewModel.Exercises.Add(timeSlotExerciseViewModel); } else { TimeSlotExerciseViewModel selectedExerciseViewModel = SelectedItem as TimeSlotExerciseViewModel; var timeSlotViewModel = selectedExerciseViewModel.TimeSlotViewModel; TimeSlotExerciseViewModel timeSlotExerciseViewModel = new TimeSlotExerciseViewModel(timeSlotExercise, timeSlotViewModel); timeSlotViewModel.TimeSlot.Add(timeSlotExercise); timeSlotViewModel.Exercises.Add(timeSlotExerciseViewModel); } }
public void TimeSlotExerciseViewModel_FrequencyWeighting_Set_Fires_PropertyChanged() { var fired = false; PracticeRoutineTimeSlot timeSlot = EntityFactory.GetSingleTimeSlot(); TimeSlotViewModel timeSlotViewModel = new TimeSlotViewModel(timeSlot); TimeSlotExercise timeSlotExercise = EntityFactory.GetTimeSlotExercise(); TimeSlotExerciseViewModel viewModel = new TimeSlotExerciseViewModel(timeSlotExercise, timeSlotViewModel); viewModel.PropertyChanged += (s, e) => { if (e.PropertyName == "FrequencyWeighting") { fired = true; } }; viewModel.FrequencyWeighting = 4; Assert.IsTrue(fired); }
public TimeSlotExerciseViewModel(TimeSlotExercise timeSlotExercise, TimeSlotViewModel timeSlotViewModel) { this.timeSlotExercise = timeSlotExercise ?? throw new ArgumentNullException("Time Slot Exercise must be provided."); this.timeSlotViewModel = timeSlotViewModel ?? throw new ArgumentNullException("Time Slot View Model must be provided."); }
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)); } }