private void AddTimeSlot()
        {
            PracticeRoutineTimeSlot timeSlot = new PracticeRoutineTimeSlot("New Time Slot", 300, new List <TimeSlotExercise>());

            practiceRoutine.Add(timeSlot);
            TimeSlots.Add(new TimeSlotViewModel(timeSlot));
        }
        public void TimeSlotExerciseViewModel_Initialized_With_No_TimeSlotExercise_Throws_Exception()
        {
            PracticeRoutineTimeSlot timeSlot          = EntityFactory.GetSingleTimeSlot();
            TimeSlotViewModel       timeSlotViewModel = new TimeSlotViewModel(timeSlot);

            TestDelegate proc = () => new TimeSlotExerciseViewModel(null, timeSlotViewModel);

            Assert.That(proc, Throws.TypeOf <ArgumentNullException>());
        }
        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);
        }
Example #5
0
        public void PracticeRoutineTimeSlot_Initialize_As_Existing_Has_CorrectState()
        {
            PracticeRoutineTimeSlot timeSlot = new PracticeRoutineTimeSlot(1, "Title", 120, EntityFactory.CreateSingleTimeSlotExerciseList());

            Assert.AreEqual("Title", timeSlot.Title);
            Assert.AreEqual(120, timeSlot.AssignedSeconds);
            Assert.AreEqual(1, timeSlot.Count());
            Assert.AreEqual(1, timeSlot.Id);
            Assert.IsNull(timeSlot.DateCreated);
            Assert.IsNull(timeSlot.DateModified);
        }
        public TimeSlotViewModel(PracticeRoutineTimeSlot timeSlot)
        {
            this.TimeSlot           = timeSlot ?? throw new ArgumentNullException("Time Slot must be provided.");
            IncrementMinutesCommand = new RelayCommand(() => IncrementMinutesPracticed(), () => true);
            DecrementMinutesCommand = new RelayCommand(() => DecrementMinutesPracticed(), () => true);

            foreach (var exercise in timeSlot)
            {
                Exercises.Add(new TimeSlotExerciseViewModel(exercise, this));
            }
        }
 public void UpdateTimeSlot(PracticeRoutineTimeSlot timeSlot)
 {
     Connection.ExecuteScalar <int>(sql: "sp_UpdateTimeSlot",
                                    param: new
     {
         _id    = timeSlot.Id,
         _title = timeSlot.Title,
         _assignedPracticeTime = timeSlot.AssignedSeconds
     },
                                    commandType: CommandType.StoredProcedure
                                    );
 }
        public PracticeRoutine Get(int id)
        {
            try
            {
                var practiceRoutineRecord = Connection.QuerySingle <PracticeRoutineRecord>("sp_GetPracticeRoutineById",
                                                                                           param: new { _id = id }, commandType: CommandType.StoredProcedure);


                var timeSlotRecords = Connection.Query <TimeSlotRecord>("sp_GetTimeSlotsByPracticeRoutineId",
                                                                        param: new
                {
                    _id = id
                }, commandType: CommandType.StoredProcedure);

                var timeSlotExerciseRecords = GetTimeSlotExercisesByTimeSlotIds(GetCommaDelimitedIds(timeSlotRecords));

                var timeSlots = new List <PracticeRoutineTimeSlot>();

                foreach (var timeSlotRecord in timeSlotRecords)
                {
                    var timeSlotExerciseRecs = timeSlotExerciseRecords
                                               .Where(recs => recs.TimeSlotId == timeSlotRecord.Id)
                                               .Select(rec => new TimeSlotExercise(rec.Id, rec.TimeSlotId, rec.Title, rec.FrequencyWeighting)
                    {
                        TimeSlotId = rec.TimeSlotId
                    }).ToList();

                    var timeSlot = new PracticeRoutineTimeSlot(timeSlotRecord.Id, timeSlotRecord.Title, timeSlotRecord.AssignedPracticeTime,
                                                               timeSlotExerciseRecs);

                    timeSlots.Add(timeSlot);
                }

                var practiceRoutine = new PracticeRoutine(practiceRoutineRecord.Id, practiceRoutineRecord.Title, timeSlots);

                practiceRoutine.DateCreated  = practiceRoutineRecord.DateCreated;
                practiceRoutine.DateModified = practiceRoutineRecord.DateModified;

                return(practiceRoutine);
            }
            catch (InvalidOperationException ex)
            {
                throw new DatabaseEntityNotFoundException($"Database entity does not exist for id: {id}", ex);
            }
        }
        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);
        }