コード例 #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);
        }
コード例 #2
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
                            );
        }