public PracticeRoutineRecorder GetPracticeRoutineRecorder(int id)
        {
            try
            {
                PracticeRoutine practiceRoutine = Get(id);

                var exerciseRecorderRecords = Connection.Query <PracticeRoutineExerciseRecorderRecord>("sp_GetPracticeRoutineExerciseRecordersByRoutineId",
                                                                                                       param: new
                {
                    _practiceRoutineId = id
                }, commandType: CommandType.StoredProcedure);

                List <TimeSlotExerciseRecorder> exerciseRecorders = new List <TimeSlotExerciseRecorder>();

                foreach (var rec in exerciseRecorderRecords)
                {
                    var speedProgress  = new SpeedProgress(rec.InitialRecordedSpeed, rec.LastRecordedSpeed, rec.TargetMetronomeSpeed, rec.SpeedProgressWeighting);
                    var timeProgress   = new PracticeTimeProgress(rec.TotalPracticeTime, rec.TargetPracticeTime, rec.PracticeTimeProgressWeighting);
                    var manualProgress = new ManualProgress(rec.LastRecordedManualProgress, rec.ManualProgressWeighting);

                    exerciseRecorders.Add(new TimeSlotExerciseRecorder(new Recorder(), rec.ExerciseId, $"{rec.TimeSlotTitle} : {rec.ExerciseTitle}", speedProgress, timeProgress, manualProgress, rec.AssignedPracticeTime));
                }

                var practiceRoutineRecorder = new PracticeRoutineRecorder(practiceRoutine.Id, practiceRoutine.Title, exerciseRecorders);

                return(practiceRoutineRecorder);
            }
            catch (InvalidOperationException ex)
            {
                throw new DatabaseEntityNotFoundException($"Database entity does not exist for id: {id}", ex);
            }
        }
Exemplo n.º 2
0
        public void PracticeRoutineRecorder_When_Initialized_Reflects_Correct_State()
        {
            var exercises = new List <ITimeSlotExerciseRecorder> {
            };

            var existingRoutine = new PracticeRoutineRecorder(2, "Existing Routine", exercises);
            var newRoutine      = new PracticeRoutineRecorder("New Routine", exercises);

            Assert.AreEqual(2, existingRoutine.Id);
            Assert.AreEqual("Existing Routine", existingRoutine.Title);

            Assert.AreEqual(0, newRoutine.Id);
            Assert.AreEqual("New Routine", newRoutine.Title);
        }
        public void PracticeRoutineRecorder_Fetch_And_Create_Is_Constructed_Successfully()
        {
            Funcs.RunScript("delete-all-records.sql", Settings.AppConnectionString);
            Funcs.RunScript("test-data-practiceroutine-recorder.sql", Settings.AppConnectionString);

            using (var uow = Funcs.GetUnitOfWork())
            {
                IPracticeRoutineSearchCriteria crit = new PracticeRoutineSearchCriteria();
                crit.Title = "monday";

                var practiceRoutine = uow.PracticeRoutines.Find(crit).SingleOrDefault();
                PracticeRoutineRecorder practiceRoutineRecorder = uow.PracticeRoutines.GetPracticeRoutineRecorder(practiceRoutine.Id);

                Assert.IsNotNull(practiceRoutineRecorder);
                Assert.That(practiceRoutineRecorder.Title, Is.EqualTo("Monday Routine"));
                Assert.That(practiceRoutineRecorder.ItemCount, Is.EqualTo(6));
                Assert.That(practiceRoutineRecorder.ExerciseRecorders.Length, Is.EqualTo(6));

                Assert.AreEqual(60, practiceRoutineRecorder.ExerciseRecorders[0].CurrentTotalSeconds);
            }
        }
Exemplo n.º 4
0
        public void PracticeRoutineRecorder_Reflects_Total_Recorded_Seconds_Correctly()
        {
            var ex1 = new Mock <ITimeSlotExerciseRecorder>();

            ex1.Setup(obj => obj.RecordedSeconds).Returns(300);
            var ex2 = new Mock <ITimeSlotExerciseRecorder>();

            ex2.Setup(obj => obj.RecordedSeconds).Returns(300);
            var ex3 = new Mock <ITimeSlotExerciseRecorder>();

            ex3.Setup(obj => obj.RecordedSeconds).Returns(300);

            var exercises = new List <ITimeSlotExerciseRecorder>
            {
                ex1.Object,
                ex2.Object,
                ex3.Object
            };

            PracticeRoutineRecorder practiceRoutineRecorder = new PracticeRoutineRecorder("Recording Routine", exercises);

            Assert.That(practiceRoutineRecorder.RecordedSeconds, Is.EqualTo(900));
            Assert.That(practiceRoutineRecorder.RecordedSecondsDisplay, Is.EqualTo("00:15:00"));
        }