public async Task <SchoolResponse> AddSchoolAsync(AddSchoolRequest request) { if (request == null) { throw new ArgumentNullException($"Request is null"); } var pupil = _schoolMapper.Map(request); var result = _schoolRepository.Create(pupil); await _schoolRepository.UnitOfWork.SaveChangesAsync(); return(_schoolMapper.Map(result)); }
public School Map(AddSchoolRequest request) { if (request == null) { return(null); } var school = new School { Name = request.Name, Country = request.Country }; return(school); }
public async Task addSchool_should_add_correct_entity() { var school = new AddSchoolRequest { Name = "Angewandte", Country = "Germany", TeacherIds = null }; var addedSchool = await _sut.AddSchoolAsync(school); addedSchool.ShouldNotBeNull(); addedSchool.Name.ShouldBe(school.Name); addedSchool.Country.ShouldBe(school.Country); }
public async Task add_should_create_new_record() { var request = new AddSchoolRequest() { Name = "new school", Country = "CZE" }; var client = _factory.CreateClient(); var httpsContent = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json"); var response = await client.PostAsync($"/api/schools", httpsContent); response.EnsureSuccessStatusCode(); response.Headers.Location.ShouldNotBeNull(); }
public async Task <IActionResult> Post(AddSchoolRequest schoolRequest) { var result = await _schoolService.AddSchoolAsync(schoolRequest); return(CreatedAtAction(nameof(GetById), new { id = result.Id }, null)); }