예제 #1
0
        public async Task update_should_modify_existing_course()
        {
            var client = _factory.CreateClient();

            var request = new EditCourseRequest()
            {
                Id        = 1,
                Name      = "statistics",
                TeacherId = 1,
                SeasonId  = 1
            };

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

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

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

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

            responseEntity.Name.ShouldBe("statistics");
            responseEntity.Id.ShouldBe(1);
//            responseEntity.TeacherId.ShouldBe(1);
        }
예제 #2
0
        public async Task <CourseResponse> EditCourseAsync(EditCourseRequest request)
        {
            var existingRecord = _courseRepository.ReadOnlyGetByIdAsync(request.Id);

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

            var editedCourse = _courseMapper.Map(request);
            var result       = _courseRepository.Update(editedCourse);

            await _courseRepository.UnitOfWork.SaveChangesAsync();

            return(_courseMapper.Map(await _courseRepository.ReadOnlyGetByIdAsync(result.Id)));
        }
예제 #3
0
        public Course Map(EditCourseRequest request)
        {
            if (request == null)
            {
                return(null);
            }

            var course = new Course
            {
                Id        = request.Id,
                Name      = request.Name,
                TeacherId = request.TeacherId,
                CourseId  = request.SeasonId
            };

            return(course);
        }
예제 #4
0
        public async Task editCourse_should_correctly_edit_entity()
        {
            var sut = new CourseService(_courseRepository, _courseMapper);

            var editCourseRequest = new EditCourseRequest()
            {
                Id        = 2,
                Name      = "ASP NET Core",
                TeacherId = 3,
                SeasonId  = 1
            };

            var editedCourse =
                await sut.EditCourseAsync(editCourseRequest);

            editedCourse.ShouldNotBeNull();
            editedCourse.Id.ShouldBe(editCourseRequest.Id);
            editedCourse.Name.ShouldBe(editCourseRequest.Name);
        }
예제 #5
0
        public async Task <IActionResult> Put(EditCourseRequest schoolRequest)
        {
            var result = await _courseService.EditCourseAsync(schoolRequest);

            return(Ok(result));
        }