예제 #1
0
        public async Task ExerciseServicesCRUD()
        {
            var exerciseService = new ExerciseService(Fixture.DbSettings);

            // Create, need to test unique name constraint

            var name = "Squat";
            var type = Enums.ResistanceType.Dynamic;
            var unit = 20;

            var exercise = exerciseService.Create(new Exercise(name, type, unit));

            Assert.True(exercise is Exercise);
            Assert.True(exercise.Name == name);
            Assert.True(exercise.ResistanceType == type);
            Assert.True(exercise.ResistanceUnit == unit);

            // Read

            var exercises = exerciseService.Get();

            Assert.True(exercises.Any());
            Assert.True(exercises.All(e => e is Exercise));

            exercise = exerciseService.Get(exercise.Id);

            Assert.True(exercise is Exercise);

            // Update

            var newName = "Deadlift";

            exercise.Name = newName;

            exerciseService.Update(exercise.Id, exercise);

            exercise = exerciseService.Get(exercise.Id);

            Assert.True(exercise is Exercise);
            Assert.True(exercise.Name == newName);

            // Delete

            exerciseService.Remove(exercise.Id);

            exercise = exerciseService.Get(exercise.Id);

            Assert.True(exercise is null);
        }
예제 #2
0
        public async Task Get_Exercise_With_A_Valid_Question(Mock <IAuthorizationService> authorizationService, IStateService stateService, Exercise exercise, Exercise invalidExercise, User user)
        {
            authorizationService.Setup(x => x.HasWriteAccess(user, It.IsAny <Exercise>(), It.IsAny <CancellationToken>())).ReturnsAsync(false);

            invalidExercise.Questions.First().Answers.ForEach(x => x.Valid = false);

            var context     = TestSetup.SetupContext();
            var httpContext = TestSetup.SetupHttpContext().SetupSession(user);

            await context.Exercises.AddAsync(exercise);

            await context.Exercises.AddAsync(invalidExercise);

            await context.SaveChangesAsync();

            var service = new ExerciseService(context, httpContext, authorizationService.Object, stateService);
            var result  = await service.Get(exercise.Id);

            var invalidResult = await service.Get(invalidExercise.Id);

            result.Should().NotBeNull().And.BeEquivalentTo(exercise);
            invalidResult.Should().BeNull();
        }
예제 #3
0
        public void GetById()
        {
            //Arrange
            var searchId = 2;

            _mock.Setup(s => s.Get(It.IsAny <int>())).Returns <int>(id =>
            {
                return(_exercises.Find(ex => ex.Id == id));
            });

            //Act
            var result = _exerciseService.Get(searchId);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(result.Id, searchId);
            Assert.IsInstanceOfType(result, typeof(ExerciseDTO));
        }
예제 #4
0
 public ActionResult <List <Exercise> > Get() =>
 _exerciseService.Get();
예제 #5
0
        public void GetBody()
        {
            var result = ExerciseService.Get(2);

            Assert.That(result.Id, Is.EqualTo(2));
        }
예제 #6
0
        public void EquipmentLoaded()
        {
            var result = ExerciseService.Get(2);

            Assert.That(result.Equipments.Count(), Is.GreaterThan(0));
        }
예제 #7
0
        public void MusclesLoaded()
        {
            var result = ExerciseService.Get(2);

            Assert.That(result.Muscles.Count(), Is.GreaterThan(0));
        }
예제 #8
0
        public void Get_NotNull()
        {
            Exercise exercise = service.Get(1);

            Assert.That(exercise, Is.Not.Null);
        }
예제 #9
0
 public Exercise Get(Int32 Id)
 {
     return(exerciseService.Get(Id));
 }