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); }
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(); }
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)); }
public ActionResult <List <Exercise> > Get() => _exerciseService.Get();
public void GetBody() { var result = ExerciseService.Get(2); Assert.That(result.Id, Is.EqualTo(2)); }
public void EquipmentLoaded() { var result = ExerciseService.Get(2); Assert.That(result.Equipments.Count(), Is.GreaterThan(0)); }
public void MusclesLoaded() { var result = ExerciseService.Get(2); Assert.That(result.Muscles.Count(), Is.GreaterThan(0)); }
public void Get_NotNull() { Exercise exercise = service.Get(1); Assert.That(exercise, Is.Not.Null); }
public Exercise Get(Int32 Id) { return(exerciseService.Get(Id)); }