Example #1
0
        public async Task CanDelete()
        {
            using var context = new DataContext(ContextOptions);
            var user = await GetUser(context);

            var trainingRepo = new TrainingRepository(context);
            var training     = await CreateTraining(context, user);

            trainingRepo.Add(training);
            var saved = await trainingRepo.SaveAll();

            Assert.IsTrue(saved);

            var trainingsReturned = await trainingRepo.GetAllByUserId(user.Id);

            Assert.AreEqual(1, trainingsReturned.Count());

            trainingRepo.Delete(trainingsReturned.ElementAt(0));
            await trainingRepo.SaveAll();

            var trainingsReturnedAfterDelete = await trainingRepo.GetAllByUserId(user.Id);

            Assert.IsEmpty(trainingsReturnedAfterDelete);

            var trainingExercisesAfterDelete = await context.TrainingExercises.ToListAsync();

            Assert.IsEmpty(trainingExercisesAfterDelete);

            var trainingExerciseSetsAfterDelete = await context.TrainingExerciseSets.ToListAsync();

            Assert.IsEmpty(trainingExerciseSetsAfterDelete);
        }
Example #2
0
        public Training CreateTraining(int trainingTypeId, int ratePerHour)
        {
            ITrainingRepository trainingRepo = new TrainingRepository(db);
            var training = new Training {
                TrainingTypeId = trainingTypeId, RatePerHour = ratePerHour
            };

            trainingRepo.Add(training);
            return(training);
        }
Example #3
0
        public async Task CanAdd()
        {
            using var context = new DataContext(ContextOptions);
            var user = await GetUser(context);

            var trainingRepo = new TrainingRepository(context);


            trainingRepo.Add(await CreateTraining(context, user));
            await trainingRepo.SaveAll();

            var trainingsReturned = await trainingRepo.GetAllByUserId(user.Id);

            var training0 = trainingsReturned.ElementAt(0);

            Assert.AreEqual(1, trainingsReturned.Count());
            Assert.AreEqual(1, training0.Id);
            Assert.AreEqual(1, training0.Exercises.Count());
            Assert.AreEqual("Training 1", training0.Name);
            Assert.AreEqual("User", training0.User.Username);

            var training0Exercise0 = training0.Exercises.ElementAt(0);

            Assert.AreEqual(1, training0Exercise0.Id);
            Assert.AreEqual("Exercise 1", training0Exercise0.Exercise.Name);
            Assert.NotNull(training0Exercise0.Sets);

            var trainig0Exercise0Set0 = training0Exercise0.Sets.ElementAt(0);

            Assert.AreEqual(1, trainig0Exercise0Set0.Id);
            Assert.AreEqual(10, trainig0Exercise0Set0.Reps);
            Assert.AreEqual(80, trainig0Exercise0Set0.Weight);
            Assert.AreEqual("kg", trainig0Exercise0Set0.Unit.Code
                            );

            var trainig0Exercise0Set1 = training0Exercise0.Sets.ElementAt(1);

            Assert.AreEqual(2, trainig0Exercise0Set1.Id);
            Assert.AreEqual(10, trainig0Exercise0Set1.Reps);
            Assert.AreEqual(85, trainig0Exercise0Set1.Weight);
            Assert.AreEqual("kg", trainig0Exercise0Set1.Unit.Code
                            );
        }
        public void CanReadTraining()
        {
            // Arange
            var dbFactory          = new DatabaseFactory();
            var trainingRepository = new TrainingRepository(dbFactory);
            var unitOfWork         = new UnitOfWork(dbFactory);

            trainingRepository.Add(new TRAINING
            {
                TRAINING_INTERNAL_ID = "1",
                DURATION             = 3,
                NOTES         = "something",
                TRAININGTHEME = "something",
                TRAININGTYPE  = "something",
                STARTDATE     = System.DateTime.Now,
                COACH         = new COACH {
                    COACH_INTERNAL_ID = "1",
                    PAYMENTRATE       = 120.2M,
                    PAYOFFRATE        = 100.2M,
                    PERSON            = new PERSON
                    {
                        FIRSTNAME = "Milan",
                        LASTNAME  = "Milanovic",
                        EMAIL     = "*****@*****.**",
                        TELEPHONE = "0644325665"
                    }
                }
            });

            unitOfWork.Commit();

            // Act
            var training = trainingRepository.Get(t => t.TRAINING_INTERNAL_ID == "1");

            // Assert
            Assert.IsNotNull(training, "training doesn't exist");
        }
Example #5
0
        public void AddTraining()
        {
            int tryint;

            Console.Write("Enter Swimmer Id:");
            string swimmertrainingId = Console.ReadLine();

            while (!int.TryParse(swimmertrainingId, out tryint))
            {
                Console.WriteLine("Incorrect Id! Try again ");
                swimmertrainingId = Console.ReadLine();
            }

            Console.Write("Enter Swim Style Id:");
            string swimStyleId = Console.ReadLine();

            while (!int.TryParse(swimStyleId, out tryint))
            {
                Console.WriteLine("Incorrect Id! Try again ");
                swimStyleId = Console.ReadLine();
            }

            string   trainingDate = Console.ReadLine();
            DateTime temp;

            while (!DateTime.TryParse(trainingDate, out temp))
            {
                Console.WriteLine("Incorrect Date! Try again ");
                trainingDate = Console.ReadLine();
            }

            string distance = Console.ReadLine();

            while (!int.TryParse(distance, out tryint))
            {
                Console.WriteLine("Incorrect Distance! Try again ");
                distance = Console.ReadLine();
            }

            try
            {
                Training training = new Training
                {
                    SwimmerId    = Convert.ToInt32(swimmertrainingId),
                    SwimStyleId  = Convert.ToInt32(swimStyleId),
                    TrainingDate = Convert.ToDateTime(trainingDate),
                    Distance     = Convert.ToInt32(distance)
                };

                using (swimmingContext swimdb = new swimmingContext())
                {
                    ITrainingManager <Training> trainingManager = new TrainingRepository(swimdb);
                    trainingManager.Add(training);
                    Console.WriteLine("Training is added");
                }
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
 public IActionResult Post([FromBody] Training item)
 {
     _repository.Add(item);
     return(Ok());
 }