public async Task TestDataTripDates() { tripFilter = new TripFilter() { Limit = 100, Pickup = "Brook", Dropoff = "Brook", StartDate = "2018-01-03", EndDate = "2018-01-03", }; // Act var resultObject = await client.GetTripDataResultsAsync(body : tripFilter); IList <DataTripResult> resultPayload = resultObject as IList <DataTripResult>; // Assert if (resultPayload != null) { Assert.IsTrue(resultPayload.Count() > 0); } else { Assert.Fail("Expected a to create resultPayload but didn't recieve one"); } }
public IList <DataTrip> GetDataTrip(TripFilter filter) { var results = _context.DataTrips .Include(d => d.PickupTaxiZone).AsNoTracking() .Include(d => d.DropOffTaxiZone).AsNoTracking() .Where(x => x.PickupTaxiZone.Zone.Contains(filter.Pickup) && x.DropOffTaxiZone.Zone.Contains(filter.Dropoff)); if (filter.validateCarType && filter.CarType != "any") { results = results.Where(x => x.CarType == filter.CarType); } if (filter.Distance > 0) { results = results.Where(x => (decimal)x.TripDistance == filter.Distance); } if (filter.passenger > 0) { results = results.Where(x => x.PassengerCount == filter.passenger); } if (filter.validateStartDate && filter.validateEndDate) { results = results.Where(x => x.StartDate >= filter.StartDateValid && x.EndDate <= filter.EndDateValid); } return(results.Take(filter.limit).ToList()); }
public async Task TestMissingPickUp() { //Arrange tripFilter = new TripFilter() { Limit = 100, Dropoff = "Astoria" }; // Act var resultObject = await client.GetDataTripWithHttpMessagesAsync(body : tripFilter); //Assert Assert.AreEqual(StatusCodes.Status400BadRequest, (int)resultObject.Response.StatusCode); }
// TODO this should be a get request - I was young and stupid public IActionResult OnPostTrips() { UserEmail = Request.Cookies["EmailCookie"]; var arrival = DateTimeHelper.ToString(DateTime.Parse(Request.Form["arrival"][0])); var pickupAddress = Request.Form["pickupAddress"][0]; var dropoffAddress = Request.Form["dropoffAddress"][0]; var filter = new TripFilter() { PickupAddress = pickupAddress, DropoffAddress = dropoffAddress, ArrivalDate = arrival }; Trips = _tripServiceProvider.GetFiltered(filter); return(OnGet()); }
public async Task TestWrongCarType() { //Arrange tripFilter = new TripFilter() { Limit = 100, Dropoff = "Astoria", Pickup = "Chinatown", CarType = "Red" }; // Act var resultObject = await client.GetDataTripWithHttpMessagesAsync(body : tripFilter); //Assert Assert.AreEqual(StatusCodes.Status400BadRequest, (int)resultObject.Response.StatusCode); }
public List <Trip> GetFiltered(TripFilter filter) { var response = ApiHelpers.DoGet(Api.Trips.GetFiltered + $"" + $"?driverEmail={filter.DriverEmail}" + $"&passengerEmail={filter.PassengerEmail}" + $"&minimumArrivalTime={filter.MinimumArrivalDate}" + $"&maximumArrivalTime={filter.MaximumArrivalDate}" + $"&pickupAddress={filter.PickupAddress}" + $"&dropoffAddress={filter.DropoffAddress}"); if (!response.IsSuccessStatusCode) { return(null); } return(JsonSerializer.Deserialize <List <Trip> >( response.Content.ReadAsStringAsync().GetAwaiter().GetResult())); }
public IList <DataTripResult> GetTripDataResult(TripFilter filter) { var results = GetDataTrip(filter); return(results.Select(x => new DataTripResult { CarType = x.CarType, PickupBorough = x.PickupTaxiZone.Zone, DropoffBorough = x.DropOffTaxiZone.Zone, PickUpTime = x.StartDate, DroppOffTime = x.EndDate, FareAmount = x.FareAmount, PassengerCount = x.PassengerCount, PayType = GetPayType(x.PayType), RateCode = GetRateCode(x.RateCodeId), TripDistance = x.TripDistance, TimeLapse = GetTimeLapse(x.StartDate, x.EndDate) }).ToList()); }
public async Task TestDataTripGreenCar() { tripFilter = new TripFilter() { Limit = 100, Pickup = "Astoria", Dropoff = "Chinatown", CarType = "green" }; // Act var resultObject = await client.GetTripDataResultsAsync(body : tripFilter); IList <DataTripResult> resultPayload = resultObject as IList <DataTripResult>; // Assert if (resultPayload != null) { Assert.IsTrue(resultPayload.Count() > 0); } else { Assert.Fail("Expected a to create resultPayload but didn't recieve one"); } }
/// <summary> /// trips search return raw db objecs /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='body'> /// payload body object /// </param> public static object GetDataTrip(this IRestClassLibraryClient operations, TripFilter body = default(TripFilter)) { return(Task.Factory.StartNew(s => ((IRestClassLibraryClient)s).GetDataTripAsync(body), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// trips search with a flat object results list /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='body'> /// payload body object /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <object> GetTripDataResultsAsync(this IRestClassLibraryClient operations, TripFilter body = default(TripFilter), CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.GetTripDataResultsWithHttpMessagesAsync(body, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// trips search with a flat object results list /// </summary> /// <param name='body'> /// payload body object /// </param> /// <param name='customHeaders'> /// Headers that will be added to request. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> /// <return> /// A response object containing the response body and response headers. /// </return> public async Task <HttpOperationResponse <object> > GetTripDataResultsWithHttpMessagesAsync(TripFilter body = default(TripFilter), Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) { if (body != null) { //body.Validate(); validate on } // Tracing bool _shouldTrace = ServiceClientTracing.IsEnabled; string _invocationId = null; if (_shouldTrace) { _invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("body", body); tracingParameters.Add("cancellationToken", cancellationToken); ServiceClientTracing.Enter(_invocationId, this, "GetTripDataResults", tracingParameters); } // Construct URL var _baseUrl = this.BaseUri.AbsoluteUri; var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "api/tripresults").ToString(); // Create HTTP transport objects HttpRequestMessage _httpRequest = new HttpRequestMessage(); HttpResponseMessage _httpResponse = null; _httpRequest.Method = new HttpMethod("POST"); _httpRequest.RequestUri = new Uri(_url); // Set Headers if (customHeaders != null) { foreach (var _header in customHeaders) { if (_httpRequest.Headers.Contains(_header.Key)) { _httpRequest.Headers.Remove(_header.Key); } _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); } } // Serialize Request string _requestContent = null; if (body != null) { _requestContent = SafeJsonConvert.SerializeObject(body, this.SerializationSettings); _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8); _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); } // Set Credentials if (this.Credentials != null) { cancellationToken.ThrowIfCancellationRequested(); await this.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); } // Send Request if (_shouldTrace) { ServiceClientTracing.SendRequest(_invocationId, _httpRequest); } cancellationToken.ThrowIfCancellationRequested(); _httpResponse = await this.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); if (_shouldTrace) { ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); } HttpStatusCode _statusCode = _httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string _responseContent = null; if ((int)_statusCode != 200 && (int)_statusCode != 400) { var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); if (_shouldTrace) { ServiceClientTracing.Error(_invocationId, ex); } _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw ex; } // Create Result var _result = new HttpOperationResponse <object>(); _result.Request = _httpRequest; _result.Response = _httpResponse; // Deserialize Response if ((int)_statusCode == 200) { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); try { _result.Body = SafeJsonConvert.DeserializeObject <IList <DataTripResult> >(_responseContent, this.DeserializationSettings); } catch (JsonException ex) { _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); } } // Deserialize Response if ((int)_statusCode == 400) { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); try { _result.Body = SafeJsonConvert.DeserializeObject <object>(_responseContent, this.DeserializationSettings); } catch (JsonException ex) { _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); } } if (_shouldTrace) { ServiceClientTracing.Exit(_invocationId, _result); } return(_result); }
public IList <DataTripResult> GetTripDataResults(TripFilter filter) { var service = new DataTripService(_context); return(service.GetTripDataResult(filter)); }
public IList <DataTrip> GetDataTrip(TripFilter filter) { var service = new DataTripService(_context); return(service.GetDataTrip(filter)); }