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));
        }
Esempio n. 2
0
        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();
        }
Esempio n. 5
0
        public async Task <IActionResult> Post(AddSchoolRequest schoolRequest)
        {
            var result = await _schoolService.AddSchoolAsync(schoolRequest);

            return(CreatedAtAction(nameof(GetById), new { id = result.Id }, null));
        }