public async Task update_should_modify_existing_course() { var client = _factory.CreateClient(); var request = new EditCourseRequest() { Id = 1, Name = "statistics", TeacherId = 1, SeasonId = 1 }; var httpsContent = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json"); var response = await client.PutAsync("/api/courses", httpsContent); response.ShouldNotBeNull(); response.EnsureSuccessStatusCode(); var responseContent = await response.Content.ReadAsStringAsync(); var responseEntity = JsonConvert.DeserializeObject <Course>(responseContent); responseEntity.Name.ShouldBe("statistics"); responseEntity.Id.ShouldBe(1); // responseEntity.TeacherId.ShouldBe(1); }
public async Task <CourseResponse> EditCourseAsync(EditCourseRequest request) { var existingRecord = _courseRepository.ReadOnlyGetByIdAsync(request.Id); if (existingRecord == null) { throw new ArgumentException($"Course with ID {request.Id} does not exist in the database"); } var editedCourse = _courseMapper.Map(request); var result = _courseRepository.Update(editedCourse); await _courseRepository.UnitOfWork.SaveChangesAsync(); return(_courseMapper.Map(await _courseRepository.ReadOnlyGetByIdAsync(result.Id))); }
public Course Map(EditCourseRequest request) { if (request == null) { return(null); } var course = new Course { Id = request.Id, Name = request.Name, TeacherId = request.TeacherId, CourseId = request.SeasonId }; return(course); }
public async Task editCourse_should_correctly_edit_entity() { var sut = new CourseService(_courseRepository, _courseMapper); var editCourseRequest = new EditCourseRequest() { Id = 2, Name = "ASP NET Core", TeacherId = 3, SeasonId = 1 }; var editedCourse = await sut.EditCourseAsync(editCourseRequest); editedCourse.ShouldNotBeNull(); editedCourse.Id.ShouldBe(editCourseRequest.Id); editedCourse.Name.ShouldBe(editCourseRequest.Name); }
public async Task <IActionResult> Put(EditCourseRequest schoolRequest) { var result = await _courseService.EditCourseAsync(schoolRequest); return(Ok(result)); }