Esempio n. 1
0
        public async Task InsertTravelAsync_Return_Created_Result(Mock <ITravelService> userService,
                                                                  TravelResponseDto expected)
        {
            // Arrange
            var sut = new TravelController(userService.Object);

            sut.ControllerContext = new ControllerContext
            {
                HttpContext = new DefaultHttpContext()
            };
            TravelRequestDto requestDto = new TravelRequestDto();

            userService.Setup(setup => setup.InsertTravelAsync(requestDto)).Returns(Task.FromResult(expected));

            // Act
            var result = sut.InsertTravelAsync(requestDto);

            var apiResult = result.Result.Should().BeOfType <CreatedAtActionResult>().Subject;
            var model     = Assert.IsType <ApiResult>(apiResult.Value);
            TravelResponseDto response = model.Data as TravelResponseDto;

            // Assert

            Assert.IsType <CreatedAtActionResult>(result.Result);
            Assert.IsNotType <OkObjectResult>(result.Result);
            Assert.IsNotType <BadRequestObjectResult>(result.Result);
            Assert.IsNotType <AcceptedAtActionResult>(result.Result);

            Assert.NotNull(result.Result);
            Assert.NotNull(expected);
            Assert.IsAssignableFrom <TravelResponseDto>(expected);
        }
Esempio n. 2
0
        public async Task <TravelResponseDto> InsertTravelAsync([NotNull] TravelRequestDto dto)
        {
            var mapped = mapper.Map <Travel>(dto);

            return(mapper.Map <TravelResponseDto>(await travelRepository.AddAsync(mapped)));
        }
 public async Task <IActionResult> InsertTravelAsync([FromBody] TravelRequestDto model)
 {
     return(CreatedAtAction(nameof(TravelFilterAsync), Request.RouteValues, await travelService.InsertTravelAsync(model)));
 }