public async Task Put_ShouldReturnOk_WhenUserIsAdminAndDataIsValid() { await AuthenticateAdminAsync(); var addExercise = new AddExercise { Name = "testExercise", PartOfBody = PartOfBodyId.Chest.ToString() }; var createdExercise = await _client.CreatePostAsync("api/exercises", addExercise); var updateExercise = new UpdateExercise { ExerciseId = createdExercise.Id, Name = createdExercise.Name + "Updated", PartOfBody = createdExercise.PartOfBody }; var response = await _client.PutAsJsonAsync("api/exercises", updateExercise); response.EnsureSuccessStatusCode(); response.StatusCode.ShouldBe(HttpStatusCode.OK); var exerciseResponse = await _client.GetAsync($"api/exercises/{updateExercise.ExerciseId}"); var updatedExercise = await exerciseResponse.Content.ReadAsAsync <ExerciseDto>(); updatedExercise.Name.ShouldBe(updateExercise.Name); }
public async Task GetAll_ShouldReturnIEnumerableExerciseDto(string query) { await AuthenticateAdminAsync(); var addExercise1 = new AddExercise { Name = "testExercise", PartOfBody = PartOfBodyId.Chest.ToString() }; var addExercise2 = new AddExercise { Name = "testExercise2", PartOfBody = PartOfBodyId.Chest.ToString() }; var createdExercise1 = await _client.CreatePostAsync("api/exercises", addExercise1); var createdExercise2 = await _client.CreatePostAsync("api/exercises", addExercise2); var response = await _client.GetAsync(query); response.EnsureSuccessStatusCode(); response.StatusCode.ShouldBe(HttpStatusCode.OK); var exercisesDto = await response.Content.ReadAsAsync <PageResultDto <ExerciseDto> >(); exercisesDto.ShouldNotBeNull(); exercisesDto.Items.Count().ShouldBe(2); }
public async Task <ActionResult> Post([FromBody] AddExercise command) { await DispatchAsync(command); _logger.LogInfo($"Exercise with name: {command.Name} added."); return(CreatedAtAction(nameof(Get), new { id = command.Id }, command)); }
public async Task Post_ShouldReturnUnauthorized_WhenUserIsNotAuthorized() { var addExercise = new AddExercise { Name = "testExercise", PartOfBody = PartOfBodyId.Chest.ToString() }; var response = await _client.PostAsJsonAsync("api/exercises", addExercise); response.StatusCode.ShouldBe(HttpStatusCode.Unauthorized); }
public async Task Post_ShouldReturnBadRequest_WhenUserIsAdminAndDataIsNotValid() { await AuthenticateAdminAsync(); var addExercise = new AddExercise { PartOfBody = PartOfBodyId.Chest.ToString() }; var response = await _client.PostAsJsonAsync("api/exercises", addExercise); response.StatusCode.ShouldBe(HttpStatusCode.BadRequest); }
public async Task Delete_ShouldReturnNoContent_WhenUserIsAdminAndExerciseExists() { await AuthenticateAdminAsync(); var addExercise = new AddExercise { Name = "testExercise", PartOfBody = PartOfBodyId.Chest.ToString() }; var createdExercise = await _client.CreatePostAsync("api/exercises", addExercise); var response = await _client.DeleteAsJsonAsync("api/exercises", new DeleteExercise { ExerciseId = createdExercise.Id }); response.EnsureSuccessStatusCode(); response.StatusCode.ShouldBe(HttpStatusCode.NoContent); }
public async Task Post_ShouldReturnCrated_WhenUserIsAdminAndDataIsValid() { await AuthenticateAdminAsync(); var addExercise = new AddExercise { Name = "testExercise", PartOfBody = PartOfBodyId.Chest.ToString() }; var response = await _client.PostAsJsonAsync("api/exercises", addExercise); response.EnsureSuccessStatusCode(); response.StatusCode.ShouldBe(HttpStatusCode.Created); var createdExercise = await response.Content.ReadAsAsync <AddExercise>(); createdExercise.Name.ShouldBe(addExercise.Name); createdExercise.PartOfBody.ShouldBe(addExercise.PartOfBody); }
public async Task GetByName_ShouldReturnOk_WhenExerciseExists() { await AuthenticateAdminAsync(); var addExercise = new AddExercise { Name = "testExercise", PartOfBody = PartOfBodyId.Chest.ToString() }; await _client.PostAsJsonAsync($"api/exercises", addExercise); var response = await _client.GetAsync($"api/exercises/{addExercise.Name}"); response.EnsureSuccessStatusCode(); response.StatusCode.ShouldBe(HttpStatusCode.OK); var exercise = await response.Content.ReadAsAsync <ExerciseDto>(); exercise.Name.ShouldBe(addExercise.Name); exercise.PartOfBody.ShouldBe(addExercise.PartOfBody); }
public static void PopulateExercise(IWorkoutDAL db) { db.AddExerciseTypeDB("Strength"); db.AddExerciseTypeDB("Endurance"); db.AddExerciseTypeDB("Bodyweight"); AddExercise newExercise = new AddExercise(); //Add Exercises for Strength newExercise.Name = "Bench Press"; newExercise.TypeId = 1; newExercise.Description = "https://cdn2.coachmag.co.uk/sites/coachmag/files/styles/insert_main_wide_image/public/2016/07/1-1-bench-press.jpg?itok=bJYGPFGO"; newExercise.VideoLink = "https://www.youtube.com/watch?v=TPqdrWcffdk"; db.AddExerciseDB(newExercise); newExercise.Name = "Biceps curl"; newExercise.TypeId = 1; newExercise.Description = "http://www.getfit-studio.com/wp-content/uploads/2016/07/bicep-curls-350x321.jpg"; newExercise.VideoLink = "https://www.youtube.com/watch?v=ktFMqoa4R5A"; db.AddExerciseDB(newExercise); newExercise.Name = "Squat"; newExercise.TypeId = 1; newExercise.Description = "http://seannal.com/wp-content/uploads/2013/04/squat-form.jpg"; newExercise.VideoLink = "https://www.youtube.com/watch?v=nEQQle9-0NA"; db.AddExerciseDB(newExercise); newExercise.Name = "Deadlift"; newExercise.TypeId = 1; newExercise.Description = "http://ispgym.ie/wp-content/uploads/2017/04/deadlift_1.jpg"; newExercise.VideoLink = "https://www.youtube.com/watch?v=ytGaGIn3SjE"; db.AddExerciseDB(newExercise); newExercise.Name = "Overhead Press"; newExercise.TypeId = 1; newExercise.Description = "https://www.oxygenmag.com/.image/t_share/MTQ1MzQ3MzE1MTU2NjU3NzE5/standing-barbell-strict-press.jpg"; newExercise.VideoLink = "https://www.youtube.com/watch?v=ECWxumBMLVQ"; db.AddExerciseDB(newExercise); //Add Endurance Exercises newExercise.Name = "Jog"; newExercise.TypeId = 2; newExercise.Description = "https://media.tenor.com/images/f85efb3960ed019939c7d4b936f927a5/tenor.png"; newExercise.VideoLink = "https://www.youtube.com/watch?v=fQ7ewHFw_I8"; db.AddExerciseDB(newExercise); newExercise.Name = "Cycling Bike"; newExercise.TypeId = 2; newExercise.Description = "https://images-na.ssl-images-amazon.com/images/I/81qWOUKaDDL._SX425_.jpg"; newExercise.VideoLink = "https://www.youtube.com/watch?v=MOIhG2GbZ3c"; db.AddExerciseDB(newExercise); newExercise.Name = "Rowing"; newExercise.TypeId = 2; newExercise.Description = "https://cdn.powerhouse-fitness.co.uk/media/catalog/product/cache/10f519365b01716ddb90abc57de5a837/i/m/imgpsh_fullsize_3.jpg"; newExercise.VideoLink = "https://www.youtube.com/watch?v=H0r_ZPXJLtg"; db.AddExerciseDB(newExercise); newExercise.Name = "Stairmaster"; newExercise.TypeId = 2; newExercise.Description = "https://www.kingsofcardio.com/media/catalog/product/cache/1/image/800x800/9df78eab33525d08d6e5fb8d27136e95/s/m/sm5_lady_1.jpg"; newExercise.VideoLink = "https://www.youtube.com/watch?v=vUqHqBQ-wK0"; db.AddExerciseDB(newExercise); //Add Bodyweight Exercises newExercise.Name = "Pushups"; newExercise.TypeId = 3; newExercise.Description = "https://qph.fs.quoracdn.net/main-qimg-18bb2ae51bff1f3bd0c673d3594bd765-c"; newExercise.VideoLink = "https://www.youtube.com/watch?v=IODxDxX7oi4"; db.AddExerciseDB(newExercise); newExercise.Name = "Lunge"; newExercise.TypeId = 3; newExercise.Description = "https://www.popworkouts.com/wp-content/uploads/2012/07/walking-lunge.jpg"; newExercise.VideoLink = "https://www.youtube.com/watch?v=QOVaHwm-Q6U"; db.AddExerciseDB(newExercise); newExercise.Name = "Pullups"; newExercise.TypeId = 3; newExercise.Description = "https://1h6wllf3f4qfut1832zlo21e-wpengine.netdna-ssl.com/wp-content/uploads/rookie-mistakes-the-pullup-main-594x442.jpg"; newExercise.VideoLink = "https://www.youtube.com/watch?v=eGo4IYlbE5g"; db.AddExerciseDB(newExercise); newExercise.Name = "Burpee"; newExercise.TypeId = 3; newExercise.Description = "https://media1.popsugar-assets.com/files/thumbor/D1XViPexj8W8d7OUJEHi0IznS_I/fit-in/1024x1024/filters:format_auto-!!-:strip_icc-!!-/2015/11/19/900/n/1922729/9cdb44dde915ed97_Burpees/i/Burpees.jpg"; newExercise.VideoLink = "https://www.youtube.com/watch?v=dZgVxmf6jkA"; db.AddExerciseDB(newExercise); newExercise.Name = "Jumping Jacks"; newExercise.TypeId = 3; newExercise.Description = "https://i2.wp.com/www.bodybuildingestore.com/wp-content/uploads/2016/09/Jumping-Jacks-1.jpg"; newExercise.VideoLink = "https://www.youtube.com/watch?v=UpH7rm0cYbM"; db.AddExerciseDB(newExercise); }