public void GetUriTest() { var request = new DirectionsRequest { Key = "abc", Origin = new Location("285 Bedford Ave, Brooklyn, NY, USA"), Destination = new Location("185 Broadway Ave, Manhattan, NY, USA") }; var uri = request.GetUri(); Assert.IsNotNull(uri); Assert.AreEqual($"/maps/api/directions/json?key={request.Key}&origin={Uri.EscapeDataString(request.Origin.ToString())}&destination={Uri.EscapeDataString(request.Destination.ToString())}&units={request.Units.ToString().ToLower()}&mode={request.TravelMode.ToString().ToLower()}&language={request.Language.ToCode()}&departure_time=now&traffic_model={request.TrafficModel.ToString().ToLower()}", uri.PathAndQuery); }
public void GetUriWhenCoordinateTest() { var request = new DirectionsRequest { Key = "abc", Origin = new Location(1, 2), Destination = new Location(1, 2) }; var uri = request.GetUri(); Assert.IsNotNull(uri); Assert.AreEqual($"/maps/api/directions/json?key={request.Key}&origin={Uri.EscapeDataString(request.Origin.ToString())}&destination={Uri.EscapeDataString(request.Destination.ToString())}&units={request.Units.ToString().ToLower()}&mode={request.TravelMode.ToString().ToLower()}&language={request.Language.ToCode()}", uri.PathAndQuery); }
public void GetUriWhenAvoidTest() { var request = new DirectionsRequest { Key = "abc", Origin = new Location("285 Bedford Ave, Brooklyn, NY, USA"), Destination = new Location("185 Broadway Ave, Manhattan, NY, USA"), Avoid = AvoidWay.Highways | AvoidWay.Indoor | AvoidWay.Ferries }; var uri = request.GetUri(); Assert.IsNotNull(uri); Assert.AreEqual($"/maps/api/directions/json?key={request.Key}&origin={Uri.EscapeDataString(request.Origin.ToString())}&destination={Uri.EscapeDataString(request.Destination.ToString())}&units={request.Units.ToString().ToLower()}&mode={request.TravelMode.ToString().ToLower()}&language={request.Language.ToCode()}&avoid={Uri.EscapeDataString(request.Avoid.ToEnumString('|'))}", uri.PathAndQuery); }
public void GetUriWhenWayPointsTest() { var request = new DirectionsRequest { Key = "abc", Origin = new Location("285 Bedford Ave, Brooklyn, NY, USA"), Destination = new Location("185 Broadway Ave, Manhattan, NY, USA"), WayPoints = new [] { new WayPoint(new Location(1, 1)) } }; var uri = request.GetUri(); var waypoints = request.WayPoints.Select(x => x.String); Assert.IsNotNull(uri); Assert.AreEqual($"/maps/api/directions/json?key={request.Key}&origin={Uri.EscapeDataString(request.Origin.ToString())}&destination={Uri.EscapeDataString(request.Destination.ToString())}&units={request.Units.ToString().ToLower()}&mode={request.TravelMode.ToString().ToLower()}&language={request.Language.ToCode()}&waypoints={Uri.EscapeDataString(string.Join("|", waypoints))}", uri.PathAndQuery); }
public void GetUriWhenTravelModeTransitAndTransitRoutingPreferenceTest() { var request = new DirectionsRequest { Key = "abc", Origin = new Location("285 Bedford Ave, Brooklyn, NY, USA"), Destination = new Location("185 Broadway Ave, Manhattan, NY, USA"), TravelMode = TravelMode.Transit, TransitMode = TransitMode.Subway | TransitMode.Bus, TransitRoutingPreference = TransitRoutingPreference.FewerTransfers | TransitRoutingPreference.LessWalking }; var uri = request.GetUri(); Assert.IsNotNull(uri); Assert.AreEqual($"/maps/api/directions/json?key={request.Key}&origin={Uri.EscapeDataString(request.Origin.ToString())}&destination={Uri.EscapeDataString(request.Destination.ToString())}&units={request.Units.ToString().ToLower()}&mode={request.TravelMode.ToString().ToLower()}&language={request.Language.ToCode()}&transit_mode={Uri.EscapeDataString(request.TransitMode.ToEnumString('|'))}&transit_routing_preference={Uri.EscapeDataString(request.TransitRoutingPreference.ToEnumString('|'))}&departure_time=now", uri.PathAndQuery); }
public void GetUriWhenTravelModeTransitAndDepatureTtimeTest() { var request = new DirectionsRequest { Key = "abc", Origin = new Location("285 Bedford Ave, Brooklyn, NY, USA"), Destination = new Location("185 Broadway Ave, Manhattan, NY, USA"), TravelMode = TravelMode.Transit, TransitMode = TransitMode.Subway | TransitMode.Bus, DepartureTime = DateTime.UtcNow }; var uri = request.GetUri(); Assert.IsNotNull(uri); Assert.AreEqual($"/maps/api/directions/json?key={request.Key}&origin={Uri.EscapeDataString(request.Origin.ToString())}&destination={Uri.EscapeDataString(request.Destination.ToString())}&units={request.Units.ToString().ToLower()}&mode={request.TravelMode.ToString().ToLower()}&language={request.Language.ToCode()}&transit_mode={Uri.EscapeDataString(request.TransitMode.ToEnumString('|'))}&departure_time={request.DepartureTime.GetValueOrDefault().DateTimeToUnixTimestamp().ToString(CultureInfo.InvariantCulture)}", uri.PathAndQuery); }