public async Task GetTransitAsync_Success(string origin, string destination, string city, string cityd, int strategy, int nightflag)
        {
            var date   = DateTime.Today;
            var time   = DateTime.Now;
            var result = await _directionService.GetTransitAsync(origin, destination, city, cityd, date, time, strategy, nightflag);

            var response = JsonConvert.DeserializeObject <ServiceResponse>(result);

            Assert.True(response.Status == Success_V3);
        }
示例#2
0
        private async Task <IActionResult> GetDirections(string userId, DirectionsQueryParameters directionsQueryParameters)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            if (directionsQueryParameters.ArrivalTime.HasValue == directionsQueryParameters.DepartureTime.HasValue)
            {
                return(BadRequest("Either departureTime xor arrialTime must be specified."));
            }
            UnresolvedLocation start;

            if (null != directionsQueryParameters.StartAddress)
            {
                start = new UnresolvedLocation(directionsQueryParameters.StartAddress);
            }
            else if (directionsQueryParameters.StartLat.HasValue && directionsQueryParameters.StartLng.HasValue)
            {
                start = new UnresolvedLocation(new Coordinate()
                {
                    Lat = directionsQueryParameters.StartLat.Value,
                    Lng = directionsQueryParameters.StartLng.Value
                });
            }
            else
            {
                return(BadRequest());
            }
            var endAdress = new UnresolvedLocation(directionsQueryParameters.EndAddress);

            try
            {
                var res = await directionsService.GetTransitAsync(new DirectionsRequest()
                {
                    UserId       = userId,
                    StartAddress = start,
                    EndAddress   = endAdress,
                    DateTime     = directionsQueryParameters.DepartureTime.HasValue ?
                                   directionsQueryParameters.DepartureTime.Value :
                                   directionsQueryParameters.ArrivalTime.Value,
                    ArriveBy = directionsQueryParameters.ArrivalTime.HasValue
                });

                if (null == res)
                {
                    return(NotFound(new DirectionsNotFoundResult()
                    {
                        Reason = DirectionsNotFoundReason.RouteNotFound,
                        EndAddressFound = true,
                        StartAddressFound = true
                    }));
                }
                Response.Headers.Add("ETag", $"\"{res.CacheKey}\"");

                return(Ok(res.TransitDirections));
            }
            catch (LocationNotFoundException e)
            {
                return(NotFound(new DirectionsNotFoundResult()
                {
                    Reason = DirectionsNotFoundReason.AddressNotFound,
                    EndAddressFound = e.UnresolvedLocation == endAdress,
                    StartAddressFound = e.UnresolvedLocation != endAdress
                }));
            }
        }