Пример #1
0
        public async Task <ActionResult <Course> > Post(Course model, CancellationToken cancellationToken)
        {
            // add model validation
            var result = await service.AddCourseAsync(model, cancellationToken);

            return(CreatedAtRoute(new { controller = "courses", id = result.Id }, result));
        }
Пример #2
0
        public async Task <IActionResult> AddCourse([FromBody] CourseForAddDTO courseForAddDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var result = await _service.AddCourseAsync(courseForAddDTO);

            return(Ok(result));
        }
Пример #3
0
        public async Task <IHttpActionResult> CreateCourseAsync
            ([FromBody, CustomizeValidator] CourseAdd_DTO course)
        {
            if (course is null || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await _courseBase.AddCourseAsync(course);

            return(result.IsError ? BadRequest(result.Message) : (IHttpActionResult)Ok(result.Data));
        }
Пример #4
0
        public async Task AddCourseAsync_Test()
        {
            var    add_DTO   = _listCourseAdd_DTO.FirstOrDefault();
            var    forAdd    = _mapper.Map <CourseDB>(add_DTO);
            Course whasAdded = null;

            _mockUnitRepo.Setup(_ => _.Courses.Add(forAdd));

            _mockUnitRepo.Setup(_ => _.SaveAsync())
            .Callback(() => { whasAdded = _mapper.Map <Course>(forAdd); });

            var result = await _service.AddCourseAsync(add_DTO);

            result.IsError.Should().BeFalse();
            result.Data.Name.Should().BeEquivalentTo(whasAdded.Name);//becouse result and whasAdded are from different mapping add_DTO
        }