public void CreaRichiestaConSoloOrigineEDestinazione() { string origine = "43.8430139000000000,10.5079940000000530"; string destinazione = "48.2081743000000000,16.3738189000000600"; Request target = new Request(origine, destinazione); string expected = "origin=43.8430139000000000,10.5079940000000530&destination=48.2081743000000000,16.3738189000000600&sensor=false"; string actual; actual = target.ToString(); Assert.AreEqual(expected, actual); }
public int CalcolaDistanzaPercorsa(Request request) { try { string requestUrl = BuildRequestUrl(request.ToString()); logger.Debug("Url interrogazione servizi di google: {0}",requestUrl); WebClient service = new WebClient(); String jsonString = service.DownloadString(requestUrl); JObject json = JObject.Parse(jsonString); var result = json.SelectToken("routes[0].legs").Select(l => trimKm((String)l.SelectToken("distance.text"))).Sum(); logger.Info("Calcolata distanza percorsa: {0} km", result); return Convert.ToInt32(result); } catch (Exception ex) { string msg = String.Format("Impossibile elaborare la richiesta di calcolo della distanza per questa request: {0}", request.ToString()); logger.ErrorException(msg, ex); throw new Exception(msg, ex); } }
public void CreaRichiestaConQualcheWaypoint() { string origine = "43.8430139000000000,10.5079940000000530"; string destinazione = "48.2081743000000000,16.3738189000000600"; var waypoints = new List<String>() { "44.4070624,8.933988900000031", "44.405,8.934", "44.407,8.938", "44.409,8.936" }; Request target = new Request(origine, destinazione); target.Waypoints = waypoints; string expected = "origin=43.8430139000000000,10.5079940000000530" + "&destination=48.2081743000000000,16.3738189000000600" + "&sensor=false" + "&waypoints=44.4070624,8.933988900000031" + "|44.405,8.934" + "|44.407,8.938" + "|44.409,8.936"; string actual; actual = target.ToString(); Assert.AreEqual(expected, actual); }