public void GetUrl_UrlReturned_Test() { // Arrange var testStartingAddress = new Address { StreetAddress = "Central Station", AddressLocality = "Brisbane City", AddressRegion = "Qld", PostalCode = "4000" }; var testDestinationAddress = new Address { StreetAddress = "139 Sumners Rd", AddressLocality = "Jamboree Heights", AddressRegion = "Qld", PostalCode = "4074" }; //var expectedUrl = "https://www.google.com.au/maps/dir/Central+Station,+Brisbane+City+QLD+4000/139+Sumners+Rd,+Jamboree+Heights+QLD+4074/"; var expectedUrl = "https://maps.googleapis.com/maps/api/distancematrix/xml?origins=Central+Station,+Brisbane+City+QLD+4000&destinations=139+Sumners+Rd,+Jamboree+Heights+QLD+4074"; // Act var actualUrl = testDistanceFinder.GetUrl(testStartingAddress, testDestinationAddress); // Assert Assert.AreEqual(expectedUrl, actualUrl); }
public float GetDistanceFromCity(Address destinationAddress) { var distanceFromCity = 0.0f; var distanceFinder = new DistanceFinder(); var url = string.Empty; try { url = distanceFinder.GetUrl(startingAddress, destinationAddress); } catch (ArgumentNullException) { // part of the address was not supplied distanceFromCity = 0.0f; } catch (Exception) { throw; } if (!string.IsNullOrEmpty(url)) { var response = distanceFinder.GetWebResponse(url); distanceFromCity = distanceFinder.GetDistance(response); } return(distanceFromCity); }