public void ChargeingStations_GetByEmptyState() { ChargingStationsGet service = new ChargingStationsGet(); StationCounts result = service.GetStationCounts("Detroit", ""); Assert.That(result.Stations, Is.Not.Null); }
public void ChargeingStations_GetByEmptyCity() { ChargingStationsGet service = new ChargingStationsGet(); StationCounts result = service.GetStationCounts("", "Michigan"); Assert.That(result.Stations, Is.Not.Null); }
public StationCounts GetStationCounts(string city, string state) { StationCounts counts = null; GeoLocation location = new GeoLocation() { City = city, State = state }; try { counts = _nrelClient.GetStationCountsByGeoLocation(location); } catch (Exception ex) { if (ex.Message.Contains("Cannot perform runtime binding on a null reference")) { throw new ValidationException("City/state combination not found."); } else { throw new ValidationException(ex.Message); } } return(counts); }
public HttpResponseMessage GetStationCounts(string city, string state) { try { ChargingStationsGet get = new ChargingStationsGet(); StationCounts retrievedCounts = get.GetStationCounts(city, state); return(ResponseHelper.CreateResponse(Request, HttpStatusCode.OK, retrievedCounts, PublicApiCommonErrorCode.SUCCESS)); } catch (Exception e) { return(ResponseHelper.CreateResponse(Request, HttpStatusCode.NotFound, e.Message, PublicApiCommonErrorCode.NOT_FOUND)); } }
public void ChargeingStations_GetByNonExistingCityAndState() { ChargingStationsGet service = new ChargingStationsGet(); try { StationCounts result = service.GetStationCounts("abc", "def"); } catch (Exception e) { Assert.That(e.Message, Is.EqualTo("City/state combination not found.")); } }
public void GetStationCounts_EmptyState() { NrelClient client = new NrelClient(); GeoLocation location = new GeoLocation() { City = "Detroit", State = "" }; StationCounts counts = client.GetStationCountsByGeoLocation(location); Assert.That(counts, Is.Not.Null); }
public void GetStationCounts() { NrelClient client = new NrelClient(); GeoLocation location = new GeoLocation() { City = "Detroit", State = "Michigan" }; StationCounts counts = client.GetStationCountsByGeoLocation(location); Assert.That(counts.Ports, Is.Not.Empty); Assert.That(counts.Stations, Is.Not.Empty); }
public StationCounts GetStationCountsByGeoLocation(GeoLocation location) { StationCounts result = new StationCounts(); string url = String.Format(_getStationCountsUrlFormat, _config.Nrel.Url, _config.Nrel.FuelType, _config.Nrel.Radius, _config.Nrel.ApiKey, location.City, location.State); using (HttpClient client = new HttpClient()) { var response = client.GetAsync(url); string resultString = response.Result.Content.ReadAsStringAsync().Result; var json = JsonConvert.DeserializeObject <dynamic>(resultString); result.Stations = json.station_counts.fuels.ELEC.stations.total; result.Ports = json.station_counts.fuels.ELEC.total; } return(result); }
public void GetStationCounts_NonExistingCityAndState() { NrelClient client = new NrelClient(); GeoLocation location = new GeoLocation() { City = "abc", State = "def" }; try { StationCounts counts = client.GetStationCountsByGeoLocation(location); Assert.That(false); } catch (Exception e) { Assert.That(e.Message, Is.EqualTo("Cannot perform runtime binding on a null reference")); } }