public async Task update_should_modify_existing_school()
        {
            var client = _factory.CreateClient();

            var request = new EditSchoolRequest()
            {
                Id      = 1,
                Name    = "JKU",
                Country = "Germany"
            };

            var httpsContent = new StringContent(JsonConvert.SerializeObject(request),
                                                 Encoding.UTF8, "application/json");
            var response = await client.PutAsync("/api/schools", httpsContent);

            response.ShouldNotBeNull();
            response.EnsureSuccessStatusCode();

            var responseContent = await response.Content.ReadAsStringAsync();

            var responseEntity = JsonConvert.DeserializeObject <School>(responseContent);

            responseEntity.Name.ShouldBe("JKU");
            responseEntity.Id.ShouldBe(1);
            responseEntity.Country.ShouldBe("Germany");
        }
Esempio n. 2
0
        public School Map(EditSchoolRequest request)
        {
            if (request == null)
            {
                return(null);
            }

            var school = new School
            {
                Id      = request.Id,
                Name    = request.Name,
                Country = request.Country,
            };

            return(school);
        }
        public async Task <SchoolResponse> EditSchoolAsync(EditSchoolRequest request)
        {
            var existingRecord = _schoolRepository.ReadOnlyGetByIdAsync(request.Id);

            if (existingRecord == null)
            {
                throw new ArgumentException($"School with {request.Id} does not exist in the database");
            }

            var entity = _schoolMapper.Map(request);
            var result = _schoolRepository.Update(entity);

            await _schoolRepository.UnitOfWork.SaveChangesAsync();

            return(_schoolMapper.Map(await _schoolRepository.ReadOnlyGetByIdAsync(result.Id)));
        }
        public async Task editSchool_should_correctly_edit_entity()
        {
            var school = new EditSchoolRequest()
            {
                Id         = 3,
                Name       = "JKU",
                Country    = "Austria",
                TeacherIds = null
            };

            var editedSchool =
                await _sut.EditSchoolAsync(school);

            editedSchool.ShouldNotBeNull();
            editedSchool.Id.ShouldBe(school.Id);
            editedSchool.Name.ShouldBe(school.Name);
            editedSchool.Country.ShouldBe(school.Country);
        }
Esempio n. 5
0
        public async Task <IActionResult> Put(EditSchoolRequest schoolRequest)
        {
            var result = await _schoolService.EditSchoolAsync(schoolRequest);

            return(Ok(result));
        }