public void AddCardioTraining()
        {
            //arrange
            IUser              user              = UserFactory.GetUser();
            IUserCollection    userCollection    = UserCollectionFactory.GetUserCollection();
            IUserCollectionDAL userCollectionDAL = UserCollectionDALFactory.GetUserCollectionDAL();
            ITrainingDAL       dal         = TrainingDALFactory.GetTrainingDAL();
            ExerciseDTO        exerciseDTO = userCollection.GetExercise("Running");
            UserDTO            userDTO     = new UserDTO("TempAccountCardioTraining", Guid.NewGuid(), "TempPassword", null, null);

            userCollectionDAL.AddUser(userDTO);
            CardioTrainingDTO cardioTrainingDTO = new CardioTrainingDTO(
                exerciseDTO,
                5.44M,
                new TimeSpan(0, 28, 45),
                userDTO.UserID,
                DateTime.Now,
                TrainingTypeDTO.Cardio);

            //act
            user.AddCardioTraining(cardioTrainingDTO);

            //assert
            Guid trainingID = dal.GetUserTrainings(userDTO.UserID.ToString())[0].TrainingID;
            CardioTrainingDTO trainingFromDB = dal.GetCardioTraining(trainingID.ToString());

            Assert.AreEqual(userDTO.UserID, trainingFromDB.UserID);
            Assert.AreEqual(cardioTrainingDTO.Date.ToLongDateString(), trainingFromDB.Date.ToLongDateString());
            Assert.AreEqual(TrainingTypeDTO.Cardio, trainingFromDB.TrainingType);
        }
Exemplo n.º 2
0
        public IActionResult AddCardioTraining(TrainingViewModel trainingViewModel)
        {
            try
            {
                if (String.IsNullOrEmpty(trainingViewModel.Exercise.Name))
                {
                    ModelState.AddModelError("Exercise", "Please fill in an exercise");
                    return(View(trainingViewModel));
                }

                IUser             user              = UserFactory.GetUser();
                IUserCollection   userCollection    = UserCollectionFactory.GetUserCollection();
                ExerciseDTO       exerciseDTO       = userCollection.GetExercise(trainingViewModel.Exercise.Name);
                CardioTrainingDTO cardioTrainingDTO = new CardioTrainingDTO(exerciseDTO, trainingViewModel.Distance, new TimeSpan(0, trainingViewModel.Minutes, trainingViewModel.Seconds), Guid.Parse(User.FindFirst("Id").Value), DateTime.Now, TrainingTypeDTO.Cardio);
                user.AddCardioTraining(cardioTrainingDTO);
                TempData["JustAddedTraining"] = true;
                return(LocalRedirect("/Home/Index"));
            }

            catch
            {
                TempData["Error"] = true;
                return(LocalRedirect("/Training/AddCardioTraining"));
            }
        }
        public void Gets_two_exercises_successfully()
        {
            // Arrange
            IUser           user           = UserFactory.GetUser();
            IExerciseDAL    dal            = ExerciseDALFactory.GetExerciseDAL();
            IUserCollection userCollection = UserCollectionFactory.GetUserCollection();
            ExerciseDTO     legextension   = new ExerciseDTO(Guid.NewGuid(), "TempLegExtension", userID, ExerciseTypeDTO.Weighted);
            ExerciseDTO     pushup         = new ExerciseDTO(Guid.NewGuid(), "TempPushup", userID, ExerciseTypeDTO.Bodyweight);

            dal.AddExercise(legextension);
            dal.AddExercise(pushup);

            // Act
            ExerciseDTO legextensionDTO = userCollection.GetExercise("TempLegextension");
            ExerciseDTO pushupDTO       = userCollection.GetExercise("TempPushup");


            // Assert
            Assert.AreEqual(userID, legextensionDTO.UserID);
            Assert.AreEqual(ExerciseTypeDTO.Weighted, legextensionDTO.ExerciseType);
            Assert.AreEqual("TempLegextension", legextensionDTO.Name);
            Assert.AreEqual(legextension.ExerciseID, legextensionDTO.ExerciseID);

            Assert.AreEqual(userID, pushupDTO.UserID);
            Assert.AreEqual(ExerciseTypeDTO.Bodyweight, pushupDTO.ExerciseType);
            Assert.AreEqual("TempPushup", pushupDTO.Name);
            Assert.AreEqual(pushup.ExerciseID, pushupDTO.ExerciseID);
        }
Exemplo n.º 4
0
        public static void CleanTests()
        {
            IUserCollection userCollection = UserCollectionFactory.GetUserCollection();

            userCollection.DeleteUser("AddUserTest");
            userCollection.DeleteUser("GetUserTest");
            userCollection.DeleteUser("GetAllUsersTest");
            userCollection.DeleteUser("DoesUserExistTest");
        }
        public void AddWeightTraining()
        {
            //arrange
            IUser           user           = UserFactory.GetUser();
            IUserCollection userCollection = UserCollectionFactory.GetUserCollection();
            ITrainingDAL    dal            = TrainingDALFactory.GetTrainingDAL();
            ExerciseDTO     deadlift       = userCollection.GetExercise("Deadlift");
            ExerciseDTO     squat          = userCollection.GetExercise("Squat");
            ExerciseDTO     pullup         = userCollection.GetExercise("Pullup");
            List <SetDTO>   deadliftSets   = new List <SetDTO>
            {
                new SetDTO(80, 0),
                new SetDTO(85, 1),
                new SetDTO(90, 2)
            };

            List <SetDTO> squatSets = new List <SetDTO>
            {
                new SetDTO(50, 0),
                new SetDTO(55, 1),
                new SetDTO(60, 2)
            };

            List <SetDTO> pullupSets = new List <SetDTO>
            {
                new SetDTO(7, 0),
                new SetDTO(7, 1),
                new SetDTO(7, 2)
            };

            List <RoundDTO> rounds = new List <RoundDTO>
            {
                new RoundDTO(deadlift, deadlift.ExerciseID, deadliftSets),
                new RoundDTO(squat, squat.ExerciseID, squatSets),
                new RoundDTO(pullup, pullup.ExerciseID, pullupSets)
            };

            UserDTO            userDTO           = new UserDTO("TempAccountWeightTraining", Guid.NewGuid(), "TempPassword", null, null);
            IUserCollectionDAL userCollectionDAL = UserCollectionDALFactory.GetUserCollectionDAL();

            userCollectionDAL.AddUser(userDTO);

            WeightTrainingDTO weightTrainingDTO = new WeightTrainingDTO(rounds, userDTO.UserID, DateTime.Now, TrainingTypeDTO.Strength);

            //act
            user.AddStrengthTraining(weightTrainingDTO);

            //assert
            Guid trainingID = dal.GetUserTrainings(userDTO.UserID.ToString())[0].TrainingID;
            WeightTrainingDTO trainingFromDB = dal.GetWeightTraining(trainingID.ToString());

            Assert.AreEqual(userDTO.UserID, trainingFromDB.UserID);
            Assert.AreEqual(weightTrainingDTO.Date.ToLongDateString(), trainingFromDB.Date.ToLongDateString());
            Assert.AreEqual(TrainingTypeDTO.Strength, trainingFromDB.TrainingType);
        }
Exemplo n.º 6
0
        public void DoesUserExist()
        {
            //arrange
            IUserCollection userCollection = UserCollectionFactory.GetUserCollection();
            UserDTO         userDTO        = new UserDTO("DoesUserExistTest", "AddUserTestPassword");

            userCollection.AddUser(userDTO);

            //act
            bool exists = userCollection.DoesUserExist("DoesUserExistTest");

            //assert
            Assert.AreEqual(exists, true);
        }
Exemplo n.º 7
0
        public void AddUser()
        {
            //arrange
            IUserCollection userCollection = UserCollectionFactory.GetUserCollection();
            UserDTO         userDTO        = new UserDTO("AddUserTest", "AddUserTestPassword");

            //act
            userCollection.AddUser(userDTO);

            //assert
            UserDTO userFromDB = userCollection.GetUser(userDTO.Name);

            Assert.AreEqual(userDTO.Name, userFromDB.Name);
        }
        public static void CleanUpTests()
        {
            IUserCollection userCollection    = UserCollectionFactory.GetUserCollection();
            ExerciseDTO     tempDeadlift      = userCollection.GetExercise("TempDeadlift");
            ExerciseDTO     tempSquat         = userCollection.GetExercise("TempSquat");
            ExerciseDTO     tempPushup        = userCollection.GetExercise("TempPushup");
            ExerciseDTO     tempLegPress      = userCollection.GetExercise("TempLegpress");
            ExerciseDTO     tempLegextenstion = userCollection.GetExercise("TempLegextension");

            userCollection.DeleteExercise(tempDeadlift.ExerciseID.ToString());
            userCollection.DeleteExercise(tempSquat.ExerciseID.ToString());
            userCollection.DeleteExercise(tempPushup.ExerciseID.ToString());
            userCollection.DeleteExercise(tempLegPress.ExerciseID.ToString());
            userCollection.DeleteExercise(tempLegextenstion.ExerciseID.ToString());
        }
        public void AddExercise_Correctly()
        {
            //arrange
            IUserCollection userCollection = UserCollectionFactory.GetUserCollection();
            IUser           user           = UserFactory.GetUser();
            ExerciseDTO     legpress       = new ExerciseDTO("TempLegpress", userID, ExerciseTypeDTO.Weighted);

            //act
            user.AddExercise(legpress);

            //assert
            ExerciseDTO legpressDTO = userCollection.GetExercise("TempLegpress");

            Assert.AreEqual("TempLegpress", legpressDTO.Name);
            Assert.AreEqual(ExerciseTypeDTO.Weighted, legpressDTO.ExerciseType);
            Assert.AreEqual(userID, legpressDTO.UserID);
        }
Exemplo n.º 10
0
        public void Get_Exercise_By_Name()
        {
            //arrange
            IUserCollection userCollection = UserCollectionFactory.GetUserCollection();
            IExerciseDAL    dal            = ExerciseDALFactory.GetExerciseDAL();
            Guid            exerciseID     = Guid.NewGuid();
            ExerciseDTO     tempExercise   = new ExerciseDTO(exerciseID, "TempDeadlift", userID, ExerciseTypeDTO.Weighted);

            dal.AddExercise(tempExercise);

            //act
            ExerciseDTO TempDeadliftDTO = userCollection.GetExercise("TempDeadlift");

            //assert
            Assert.AreEqual("TempDeadlift", TempDeadliftDTO.Name);
            Assert.AreEqual(exerciseID, TempDeadliftDTO.ExerciseID);
            Assert.AreEqual(ExerciseTypeDTO.Weighted, TempDeadliftDTO.ExerciseType);
            Assert.AreEqual(userID, TempDeadliftDTO.UserID);
        }
Exemplo n.º 11
0
        public void GetAllUser()
        {
            //arrange
            IUserCollection userCollection = UserCollectionFactory.GetUserCollection();
            UserDTO         userDTO        = new UserDTO("GetAllUsersTest", "AddUserTestPassword");

            userCollection.AddUser(userDTO);

            //act
            List <UserDTO> userDTOs = userCollection.GetAllUsers();

            //assertt
            List <string> names = new List <string>();

            foreach (var user in userDTOs)
            {
                names.Add(user.Name);
            }
            bool contains = names.Contains(userDTO.Name);

            Assert.AreEqual(true, contains);
        }