public async Task update_should_modify_exisitng_pupil() { var client = _factory.CreateClient(); var request = new EditPupilRequest { Id = 2, Firstname = "Jirka", // PupilInClassIds = null, // PupilInCourseIds = null }; var httpsContent = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json"); var response = await client.PutAsync("/api/pupils", httpsContent); response.ShouldNotBeNull(); response.EnsureSuccessStatusCode(); var responseContent = await response.Content.ReadAsStringAsync(); var responseEntity = JsonConvert.DeserializeObject <Pupil>(responseContent); responseEntity.Firstname.ShouldBe("Jirka"); }
public Pupil Map(EditPupilRequest request) { if (request == null) { return(null); } var pupil = new Pupil { Id = request.Id, Firstname = request.Firstname }; return(pupil); }
public async Task <PupilResponse> EditPupilAsync(EditPupilRequest request) { var existingRecord = _pupilRepository.ReadOnlyGetByIdAsync(request.Id); if (existingRecord == null) { throw new ArgumentException($"Pupil with ID {request.Id} does not exist in the database"); } var entity = _pupilMapper.Map(request); var result = _pupilRepository.Update(entity); await _pupilRepository.UnitOfWork.SaveChangesAsync(); return(_pupilMapper.Map(await _pupilRepository.ReadOnlyGetByIdAsync(result.Id))); }
public async Task editPupil_should_correctly_edit_entity() { var sut = new PupilService(_pupilRepository, _pupilMapper); var editPupil = new EditPupilRequest { Id = 3, Firstname = "Jan" }; var editedPupil = await sut.EditPupilAsync(editPupil); editedPupil.ShouldNotBeNull(); editedPupil.Id.ShouldBe(editPupil.Id); editedPupil.Firstname.ShouldBe(editedPupil.Firstname); }
public async Task <IActionResult> Put(EditPupilRequest pupilRequest) { var result = await _pupilService.EditPupilAsync(pupilRequest); return(Ok(result)); }