public async Task TestGetWorkoutsSuccessfully()
        {
            using (var context = new FitTracContext(options))
            {
                ExercisesController exercisesController       = new ExercisesController(context);
                WorkoutsController  workoutsController        = new WorkoutsController(context, exercisesController);
                ActionResult <IEnumerable <Workouts> > result = await workoutsController.GetWorkouts();

                // check if get method acutally returns something
                Assert.IsNotNull(result);

                // convert everything into an array for easier access
                var resultArray   = result.Value.ToArray();
                var workoutsArray = workouts.ToArray();

                // compare first object of array
                Assert.AreEqual(resultArray[0].WorkoutName, workoutsArray[0].WorkoutName);
                Assert.AreEqual(resultArray[0].WorkoutDescription, workoutsArray[0].WorkoutDescription);
                Assert.AreEqual(resultArray[0].WorkoutId, workoutsArray[0].WorkoutId);

                // compare second object of array
                Assert.AreEqual(resultArray[1].WorkoutName, workoutsArray[1].WorkoutName);
                Assert.AreEqual(resultArray[1].WorkoutDescription, workoutsArray[1].WorkoutDescription);
                Assert.AreEqual(resultArray[1].WorkoutId, workoutsArray[1].WorkoutId);
            }
        }
Exemple #2
0
        public async Task TestGetExercisesSuccessfully()
        {
            using (var context = new FitTracContext(options))
            {
                ExercisesController exercisesController        = new ExercisesController(context);
                ActionResult <IEnumerable <Exercises> > result = await exercisesController.GetExercises();

                Assert.IsNotNull(result);

                // convert everything into an array for easier access
                var resultArray    = result.Value.ToArray();
                var exercisesArray = exercises.ToArray();

                // compare first object of array
                Assert.AreEqual(resultArray[0].ExerciseName, exercisesArray[0].ExerciseName);
                Assert.AreEqual(resultArray[0].ExerciseReps, exercisesArray[0].ExerciseReps);
                Assert.AreEqual(resultArray[0].ExerciseSets, exercisesArray[0].ExerciseSets);
                Assert.AreEqual(resultArray[0].ExerciseId, exercisesArray[0].ExerciseId);
                Assert.AreEqual(resultArray[0].WorkoutId, exercisesArray[0].WorkoutId);

                // compare second object of array
                Assert.AreEqual(resultArray[1].ExerciseName, exercisesArray[1].ExerciseName);
                Assert.AreEqual(resultArray[1].ExerciseReps, exercisesArray[1].ExerciseReps);
                Assert.AreEqual(resultArray[1].ExerciseSets, exercisesArray[1].ExerciseSets);
                Assert.AreEqual(resultArray[1].ExerciseId, exercisesArray[1].ExerciseId);
                Assert.AreEqual(resultArray[1].WorkoutId, exercisesArray[1].WorkoutId);
            }
        }
        public async Task TestEditWorkoutSuccessfully()
        {
            using (var context = new FitTracContext(options))
            {
                string   updateWorkoutName = "Update name of workout";
                Workouts workouts1         = context.Workouts.Where(x => x.WorkoutName == workouts[0].WorkoutName).Single();
                workouts1.WorkoutName = updateWorkoutName;

                string updateExerciseName             = "Update name of exercise";
                ICollection <Exercises> tempExercises = new List <Exercises>
                {
                    new Exercises()
                    {
                        ExerciseId   = 1,
                        ExerciseName = updateExerciseName,
                        ExerciseReps = 5,
                        ExerciseSets = 5,
                    }
                };

                workouts1.Exercises = tempExercises;

                ExercisesController exercisesController = new ExercisesController(context);
                WorkoutsController  workoutsController  = new WorkoutsController(context, exercisesController);
                IActionResult       result = await workoutsController.EditWorkouts(workouts1.WorkoutId, workouts1) as IActionResult;

                Assert.IsNotNull(result);
                Assert.IsInstanceOfType(result, typeof(NoContentResult));
            }
        }
 public void ClearDb()
 {
     using (var context = new FitTracContext(options))
     {
         // clear the db
         context.Workouts.RemoveRange(context.Workouts);
         context.SaveChanges();
     };
 }
 public void SetupDb()
 {
     using (var context = new FitTracContext(options))
     {
         // populate the db
         context.Workouts.Add(workouts[0]);
         context.Workouts.Add(workouts[1]);
         context.SaveChanges();
     }
 }
Exemple #6
0
 public void SetupDb()
 {
     using (var context = new FitTracContext(options))
     {
         // populate the db
         context.Exercises.Add(exercises[0]);
         context.Exercises.Add(exercises[1]);
         context.SaveChanges();
     }
 }
Exemple #7
0
        public async Task TestGetFilteredExerciseExercisesSuccessfully()
        {
            using (var context = new FitTracContext(options))
            {
                ExercisesController      exercisesController = new ExercisesController(context);
                ActionResult <Exercises> result = await exercisesController.GetFilteredExercises(1);

                // temp = result.Result.ExecuteResult();
                //// var wId = result.Value.ExerciseId;
                //// var workoutId = result.Value.WorkoutId;
                //var workoutId = context.Exercises.Where(x => x.ExerciseId == exercises[0].ExerciseId).Single().ExerciseId;

                Assert.IsNotNull(result);
            }
        }
        public async Task TestPutWorkoutSuccessfully()
        {
            using (var context = new FitTracContext(options))
            {
                string   updateWorkoutName = "Update name of workout";
                Workouts workouts1         = context.Workouts.Where(x => x.WorkoutName == workouts[0].WorkoutName).Single();
                workouts1.WorkoutName = updateWorkoutName;

                ExercisesController exercisesController = new ExercisesController(context);
                WorkoutsController  workoutsController  = new WorkoutsController(context, exercisesController);
                IActionResult       result = await workoutsController.PutWorkouts(workouts1.WorkoutId, workouts1) as IActionResult;

                Assert.IsNotNull(result);
                Assert.IsInstanceOfType(result, typeof(NoContentResult));
            }
        }
Exemple #9
0
        public async Task TestPutExercisesSuccessfully()
        {
            using (var context = new FitTracContext(options))
            {
                string    updateExerciseName = "Update name of exercise";
                Exercises exercise1          = context.Exercises.Where(x => x.ExerciseId == exercises[0].ExerciseId).Single();
                exercise1.ExerciseName = updateExerciseName;

                ExercisesController exercisesController = new ExercisesController(context);
                IActionResult       result = await exercisesController.PutExercises(exercise1.ExerciseId, exercise1) as IActionResult;

                // checking if successfully edit exercise
                Assert.IsNotNull(result);
                Assert.IsInstanceOfType(result, typeof(NoContentResult));

                // checking if correct name has been updated
                string updatedExerciseName = context.Exercises.Where(x => x.ExerciseId == exercises[0].ExerciseId).Single().ExerciseName;
                Assert.AreEqual(updateExerciseName, updatedExerciseName);
            }
        }
Exemple #10
0
 public ExercisesController(FitTracContext context)
 {
     _context = context;
 }