Beispiel #1
0
        public async Task <IActionResult> PostAsync([FromBody] SaveTutorResource resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }
            var tutor  = _mapper.Map <SaveTutorResource, Tutor>(resource);
            var result = await _tutorService.SaveAsync(tutor);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }
            var tutorResource = _mapper.Map <Tutor, TutorResource>(result.Resource);

            return(Ok(tutorResource));
        }
        public void GivenATutorWithNameWithoutDescriptionAndId(string name, int tutorId)
        {
            _tutor = new Tutor {
                Id = tutorId, Name = name
            };
            _career = new Career {
                Id = 1
            };
            _saveTutor = new SaveTutorResource {
                Name = name
            };

            _mapper       = GetDefaultMapperInstance();
            _tutorService = GetDefaultTutorServiceInstance();

            TutorResponse var1 = new TutorResponse(_tutor);

            _mapper.Setup(r => r.Map <SaveTutorResource, Tutor>(_saveTutor)).Returns(_tutor);
            _tutorService.Setup(r => r.GetByIdAsync(_tutor.Id)).ReturnsAsync(var1);
            _mapper.Setup(r => r.Map <Tutor, TutorResource>(var1.Resource)).Returns(new TutorResource {
                Id = _tutor.Id, CareerId = _career.Id, Name = _tutor.Name
            });
        }