コード例 #1
0
        public async Task CreateAppointmentAsync_CreateAppointment_ReturnsCreatedAppointment()
        {
            // Arrange
            var appointment = _fixture.Create <Appointment>();
            int id          = appointment.Id;

            _repositoryWrapper
            .Setup(rw => rw.AnimalRepository.IsAnyAsync(a => a.Id == appointment.AnimalId))
            .ReturnsAsync(true);
            _repositoryWrapper
            .Setup(rw => rw.ServiceRepository.IsAnyAsync(s => s.Id == appointment.ServiceId))
            .ReturnsAsync(true);
            _repositoryWrapper
            .Setup(rw => rw.AppointmentRepository.GetFirstOrDefaultAsync(
                       a => a.Id == id,
                       It.IsAny <Func <IQueryable <Appointment>, IIncludableQueryable <Appointment, object> > >(),
                       It.IsAny <bool>()))
            .ReturnsAsync(appointment);

            // Act
            var actual = await _appointmentService.CreateAppointmentAsync(appointment);

            // Assert
            _repositoryWrapper.Verify(rw => rw.AppointmentRepository.Add(appointment), Times.Once);
            _repositoryWrapper.Verify(rw => rw.SaveAsync(), Times.Once);

            Assert.Equal(appointment, actual);
        }
コード例 #2
0
        public async Task CreateAppointment([FromBody] CreateAppointmentRequestViewModel request)
        {
            var model = Mapper.Map <CreateAppointmentRequestDto>(request);

            var currentUser = await _userService.GetUserByName(HttpContext.User.Identity.Name);

            model.UserId = currentUser.Id;

            await _appointmentService.CreateAppointmentAsync(model);
        }
コード例 #3
0
        public async Task <IActionResult> PostAsync([FromBody] CreateAppointmentDto createAppointmentDto)
        {
            var appointment = _mapper.Map <Appointment>(createAppointmentDto);

            var createdAppointment = await _appointmentService.CreateAppointmentAsync(appointment);

            var appointmentDto = _mapper.Map <AppointmentDto>(createdAppointment);

            return(CreatedAtRoute(nameof(GetAsync), new { appointmentDto.Id }, new Response <AppointmentDto>(appointmentDto)));
        }
コード例 #4
0
        public async Task <IActionResult> CreateAppointmentAsync(
            [FromBody] AddAppointmentRequestDto addAppointmentRequestDto,
            CancellationToken token = default)
        {
            try
            {
                var appointmentServiceObject = Mapper.Map <AppointmentServiceObject>(addAppointmentRequestDto);
                var serviceResult            = await _appointmentService.CreateAppointmentAsync(appointmentServiceObject, token);

                return(new CreatedResult(string.Empty, Mapper.Map <AddAppointmentResponseDto>(serviceResult)));
            }
            catch (BadRequestException e)
            {
                return(new BadRequestObjectResult(e.Error));
            }
        }
コード例 #5
0
 public async Task <IActionResult> AddAppointmentAsync([FromBody] AppointmentDto appointmentDto)
 {
     return(await appointmentService.CreateAppointmentAsync(appointmentDto, Request));
 }