public void CheckThatTheGoogleDirectionsHandlesTheGoogleCredentialsConstructorParameterCorrectly() { var key = Guid.NewGuid().ToString("N"); const string clientId = "FixedId"; const string secretKey = "vNIXE0xscrmjlyV-12Nj_BvUPaw="; const string signture = "CRxVumPbEloBzaOnLNuYNWMbzNA="; var directionsRequest = new GoogleDirectionsRequest(new GoogleCredentials(key)) { RootPath = "http://test.com" }; Assert.That(directionsRequest.Path, Is.StringContaining($"key={key}")); Assert.That(directionsRequest.Path, Is.Not.StringContaining("client=")); Assert.That(directionsRequest.Path, Is.Not.StringContaining("signature=")); directionsRequest = new GoogleDirectionsRequest(new GoogleCredentials(clientId, secretKey)); Assert.That(directionsRequest.Path, Is.Not.StringContaining($"key={key}")); Assert.That(directionsRequest.Path, Is.StringContaining($"client={clientId}")); Assert.That(directionsRequest.Path, Is.StringContaining($"signature={signture}")); Assert.Throws <ArgumentException>( () => { var request = new GoogleDirectionsRequest((GoogleCredentials)null); var path = request.Path; }); }
public void CheckThatTheApiClientCorrectlySerialisesAGoogleDirectionsResponse() { var key = Guid.NewGuid().ToString(); var request = new GoogleDirectionsRequest(key) { Origin = "Bristol", Destination = "Bath" }; var apiResponse = GetResponse(new ApiClient(), request, GetDirectionsResult()).Result; Assert.That(request.Path, Is.StringContaining($"key={key}")); Assert.That(apiResponse, Is.Not.Null); Assert.That(apiResponse.Routes.Length, Is.EqualTo(1)); Assert.That(apiResponse.Routes[0].PolyLine.Points, Is.Not.Empty); Assert.That(apiResponse.Routes[0].PolyLine.StepLocations.Count(), Is.EqualTo(1)); Assert.That(apiResponse.Routes[0].PolyLine.StepLocations.ElementAt(0).Latitude, Is.EqualTo(40.74288)); Assert.That(apiResponse.Routes[0].PolyLine.StepLocations.ElementAt(0).Longitude, Is.EqualTo(-74.00585)); Assert.That(apiResponse.Routes[0].Bounds.NorthEast.Latitude, Is.EqualTo(40.8171321)); Assert.That(apiResponse.Routes[0].Bounds.NorthEast.Longitude, Is.EqualTo(-73.99449150000001)); Assert.That(apiResponse.Routes[0].Bounds.SouthWest.Latitude, Is.EqualTo(40.7416627)); Assert.That(apiResponse.Routes[0].Bounds.SouthWest.Longitude, Is.EqualTo(-74.0728354)); Assert.That(apiResponse.Routes[0].Legs.Length, Is.EqualTo(1)); Assert.That(apiResponse.Routes[0].Legs[0].Distance.Text, Is.EqualTo("9.7 mi")); Assert.That(apiResponse.Routes[0].Legs[0].Distance.Value, Is.EqualTo(15653)); Assert.That(apiResponse.Routes[0].Legs[0].Duration.Text, Is.EqualTo("25 mins")); Assert.That(apiResponse.Routes[0].Legs[0].Duration.Value, Is.EqualTo(1480)); Assert.That(apiResponse.Routes[0].Legs[0].StartAddress, Is.EqualTo("75 Ninth Ave, New York, NY 10011, USA")); Assert.That(apiResponse.Routes[0].Legs[0].Start.Latitude, Is.EqualTo(40.7428759)); Assert.That(apiResponse.Routes[0].Legs[0].Start.Longitude, Is.EqualTo(-74.00584719999999)); Assert.That(apiResponse.Routes[0].Legs[0].EndAddress, Is.EqualTo("1 MetLife Stadium Dr, East Rutherford, NJ 07073, USA")); Assert.That(apiResponse.Routes[0].Legs[0].End.Latitude, Is.EqualTo(40.814505)); Assert.That(apiResponse.Routes[0].Legs[0].End.Longitude, Is.EqualTo(-74.07272910000002)); Assert.That(apiResponse.Routes[0].Legs[0].Steps.Length, Is.EqualTo(22)); Assert.That(apiResponse.Routes[0].Legs[0].Steps[0].Distance.Text, Is.EqualTo("440 ft")); Assert.That(apiResponse.Routes[0].Legs[0].Steps[0].Distance.Value, Is.EqualTo(134)); Assert.That(apiResponse.Routes[0].Legs[0].Steps[0].Duration.Text, Is.EqualTo("1 min")); Assert.That(apiResponse.Routes[0].Legs[0].Steps[0].Duration.Value, Is.EqualTo(34)); Assert.That(apiResponse.Routes[0].Legs[0].Steps[0].End.Latitude, Is.EqualTo(40.7422925)); Assert.That(apiResponse.Routes[0].Legs[0].Steps[0].End.Longitude, Is.EqualTo(-74.004457)); Assert.That(apiResponse.Routes[0].Legs[0].Steps[0].Start.Latitude, Is.EqualTo(40.7428759)); Assert.That(apiResponse.Routes[0].Legs[0].Steps[0].Start.Longitude, Is.EqualTo(-74.00584719999999)); Assert.That(apiResponse.Routes[0].Legs[0].Steps[0].PolyLine.Points, Is.EqualTo("_rtwFpgubMtBuG")); Assert.That(apiResponse.Routes[0].Legs[0].Steps[0].TravelMode, Is.EqualTo("DRIVING")); Assert.That(apiResponse.Waypoints.Length, Is.EqualTo(2)); Assert.That(apiResponse.Waypoints[1].PlaceId, Is.EqualTo("ChIJ8YWMWnz4wokRCOVf1CcJCbY")); Assert.That(apiResponse.Waypoints[1].Types, Contains.Item("street_address")); Assert.That(apiResponse.Waypoints[1].PartialMatch, Is.True); }
public void CheckThatTheDirectionApiRequestHasAcorrectlyFormattedUrl() { var key = Guid.NewGuid().ToString("N"); var origin = Guid.NewGuid().ToString("N"); var destination = Guid.NewGuid().ToString("N"); var request = new GoogleDirectionsRequest(key) { Origin = origin, Destination = destination }; Assert.That(request.Path, Is.EqualTo($"https://maps.googleapis.com/maps/api/directions/json?destination={destination}&origin={origin}&key={key}")); }
public void CheckThatTheGoogleDirectionsRequestReturnsValidResults() { var client = Substitute.For <IApiClient>(); var provider = new MappingDataProvider(client); var request = new GoogleDirectionsRequest { Origin = "Bristol", Destination = "Bath" }; var response = new GoogleDirectionsResponse(); client.GetAsync(request).Returns(info => response); var apiResponse = provider.GetAsync(request).Result; Assert.That(response, Is.SameAs(apiResponse)); }