public static ShoeTrackerDbContext WithWorkout(this ShoeTrackerDbContext context, 
            string name, 
            string userId, 
            DateTime? workoutDate=null, 
            decimal? distance=null, 
            DateTime? importedAt=null, 
            string externalWorkoutId=null,
            string shoeName=null)
        {
            var maxWorkoutId = 1L;
            if (context.Workouts.Any())
            {
                maxWorkoutId = context.Workouts.Max(s => s.WorkoutId);
            }

            var shoeUsed = context.Shoes.FirstOrDefault(s => s.Name == shoeName);

            var workout = new Workout
            {
                WorkoutId = maxWorkoutId,
                UserId = userId,
                Distance = distance.GetValueOrDefault(5),
                WorkoutDate = workoutDate.GetValueOrDefault(DateTime.Today),
                ShoeUsed = shoeUsed,
                CreatedAt = DateTime.Now,
                Name = name,
                ImportedAt = importedAt.GetValueOrDefault(DateTime.Now),
                ExternalWorkoutId = externalWorkoutId
            };

            context.Workouts.Attach(workout);

            if (shoeUsed != null)
            {
                shoeUsed.Workouts.Add(workout);
            }

            return context;
        }
        private Workout MapEditViewModelToWorkout(EditWorkoutViewModel workoutViewModel)
        {
            var shoeUsed = _dbContext.GetShoe(this.GetUserId(), workoutViewModel.ShoeUsedId);

            var workout = new Workout
            {
                UserId = this.GetUserId(),
                CreatedAt = DateTime.Now,
                Distance = workoutViewModel.Distance,
                Name = workoutViewModel.Name,
                ShoeUsed = shoeUsed,
                WorkoutDate = workoutViewModel.WorkoutDate,
                ImportedAt = DateTime.Now,
            };
            return workout;
        }
        private EditWorkoutViewModel MapWorkoutToEditWorkoutViewModel(Workout workout)
        {
            var shoeUsedId = workout.ShoeUsed == null ? (long?) null : workout.ShoeUsed.ShoeId;
            var availableShoes = GetAvailableShoeList();

            var viewModel = new EditWorkoutViewModel
            {
                WorkoutId = workout.WorkoutId,
                WorkoutDate = workout.WorkoutDate,
                Distance = workout.Distance,
                ShoeUsedId = shoeUsedId,
                Name = workout.Name,
                AvailableShoes = availableShoes
            };
            return viewModel;
        }
 private static void AssertWorkoutNameMatches(Workout workout, domain.fitness_providers.mapmyfitness.models.Workout matchingMmfWorkout)
 {
     Assert.That(workout.Name, Is.EqualTo(matchingMmfWorkout.name));
 }
 private static void AssertWorkoutIsForMapMyFitness(Workout workout)
 {
     Assert.That(workout.Source.Name, Is.EqualTo("MapMyFitness"));
 }
 private static void AssertWorkoutIsForCurrentUser(Workout workout)
 {
     Assert.That(workout.UserId, Is.EqualTo(_currentUserId));
 }
 private static void AssertWorkoutDateMatches(Workout workout, domain.fitness_providers.mapmyfitness.models.Workout matchingMmfWorkout)
 {
     Assert.That(workout.WorkoutDate, Is.EqualTo(DateTime.Parse(matchingMmfWorkout.start_datetime)));
 }
 private static void AssertDistanceMatches(Workout workout, domain.fitness_providers.mapmyfitness.models.Workout matchingMmfWorkout)
 {
     Assert.That(Math.Round(workout.Distance, 4),
         Is.EqualTo(Math.Round(matchingMmfWorkout.aggregates.distance_total*0.000621371, 4)));
 }