public void should_have_error_when_name_is_empty() { var addPupilRequest = new AddPupilRequest { Firstname = "" }; _validator.ShouldHaveValidationErrorFor(x => x.Firstname, addPupilRequest); }
public async Task addPupil_should_add_correct_entity() { var pupil = new AddPupilRequest { Firstname = "Marek" }; var addedPupil = await _sut.AddPupilAsync(pupil); addedPupil.ShouldNotBeNull(); addedPupil.Firstname.ShouldBe("Marek"); }
public Pupil Map(AddPupilRequest request) { if (request == null) { return(null); } var pupil = new Pupil { Firstname = request.Firstname, }; return(pupil); }
public async Task <PupilResponse> AddPupilAsync(AddPupilRequest request) { if (request == null) { throw new ArgumentNullException($"Request is null"); } var pupil = _pupilMapper.Map(request); var result = _pupilRepository.Create(pupil); await _pupilRepository.UnitOfWork.SaveChangesAsync(); return(_pupilMapper.Map(result)); }
public async Task add_should_create_new_record() { var request = new AddPupilRequest { Firstname = "Miroslav", // PupilInClassIds = null, // PupilInCourseIds = null }; var client = _factory.CreateClient(); var httpsContent = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json"); var response = await client.PostAsync($"/api/pupils", httpsContent); response.EnsureSuccessStatusCode(); response.Headers.Location.ShouldNotBeNull(); }
public async Task <IActionResult> Post(AddPupilRequest pupilRequest) { var result = await _pupilService.AddPupilAsync(pupilRequest); return(CreatedAtAction(nameof(GetById), new { id = result.Id }, null)); }