public FlightSearchControllerShould()
        {
            var expected    = new FlightSearchRequestDto();
            var mockService = new Mock <IFlightSearchApplicationService>();

            mockService.Setup(s => s.SearchAsync(It.IsAny <FlightSearchRequestDto>(), It.IsAny <CancellationToken>())).ReturnsAsync(Result.Ok(new FlightSearchResponseDto(new List <ItineraryDto>(), 0, 10, 1)));

            var mockAuthorizationService = new Mock <IAuthorizationService>();

            var mockMapper = new Mock <IMapper>();

            mockMapper.Setup(x => x.Map <FlightSearchClientRequestForm, FlightSearchRequestDto>(It.IsAny <FlightSearchClientRequestForm>()))
            .Returns(expected);

            _controller = new FlightSearchController(mockService.Object, mockMapper.Object, null, null, null, mockAuthorizationService.Object);
            _controller.MockCurrentUser("1", "*****@*****.**", IdentityConstants.ApplicationScheme);
        }
        public async Task <Result <FlightSearchResponseDto> > SearchAsync(FlightSearchRequestDto request, CancellationToken cancellationToken)
        {
            if (request == null)
            {
                return(Result.ObjectValidationFail <FlightSearchResponseDto>("Invaid Request"));
            }

            if (!request.IsValid())
            {
                return(Result.ObjectValidationFail <FlightSearchResponseDto>(request.Validate()));
            }

            var flightSearchEngine = new FlightSearchEngine("skyscanner");


            var origin      = request.OriginLocation;
            var destination = request.DestinationLocation;

            cancellationToken.ThrowIfCancellationRequested();
            var result = await flightSearchEngine.SearchAsync(
                Settings.Skyscanner.APIKey,
                request.Markets,
                request.Currency,
                request.Locale,
                origin,
                destination,
                request.OutboundDate,
                request.InboundDate,
                int.Parse(request.Adults.GetEnumDescription()),
                int.Parse(request.Children.GetEnumDescription()),
                int.Parse(request.Infants.GetEnumDescription()),
                request.PriceMinFilter,
                request.PriceMaxFilter,
                request.MaxStopsFilter,
                request.FlightClass.GetEnumDescription(),
                request.SortType.GetEnumDescription(),
                request.SortOrder.GetEnumDescription(),
                request.OutboundDepartureTimeFromFilter,
                request.OutboundDepartureTimeToFilter,
                request.OutboundArrivalTimeFromFilter,
                request.OutboundArrivalTimeToFilter,
                request.InboundDepartureTimeFromFilter,
                request.InboundDepartureTimeToFilter,
                request.InboundArrivalTimeFromFilter,
                request.InboundArrivalTimeToFilter,
                cancellationToken).ConfigureAwait(false);


            var ItineraryDtos = new List <ItineraryDto>();

            foreach (Itinerary i in result.FilteredItineraries)
            {
                var itinerary = new ItineraryDto().CopyFrom(i);
                ItineraryDtos.Add(itinerary);
            }

            var response = new FlightSearchResponseDto(ItineraryDtos, request.Skip ?? 0, request.Take ?? 10, result.TotalResults);

            response.Request = request;

            return(Result.Ok(response));
        }
Exemplo n.º 3
0
 public async Task <Result <FlightSearchResponseDto> > SearchAsync(FlightSearchRequestDto request, CancellationToken cancellationToken)
 {
     return(await DomainService.SearchAsync(request, cancellationToken));
 }