Beispiel #1
0
        /// <summary>
        /// Gets the addresses for all the stops, and their geographical co-ordinates,
        /// and tries to format it a little more neatly.
        /// </summary>
        /// <param name="stopIds"></param>
        /// <returns></returns>
        private IEnumerable<string> GetInformationForStops(IEnumerable<string> stopIds)
        {
            var requestEntity = new StopsRequest
            {
                StopIds = stopIds.ToList()
            };

            var response = _client.PostAsJsonAsync("location/getstopsbyids", requestEntity).Result;
            response.EnsureSuccessStatusCode();
            StopsResponse result = response.Content.ReadAsAsync<StopsResponse>().Result;

            var stopInfo = result.Stops.Select(
                                                s =>
                                                    new
                                                    {
                                                        Zone = s.Zone,
                                                        StopId = s.StopId,
                                                        Street = s.Street,
                                                        Suburb = s.Suburb,
                                                        Latitude = s.Position.Lat,
                                                        Longitude = s.Position.Lng
                                                    });

            var stopDetails = new List<string>()
                              {
                                  string.Format("{0}     :\t{1}\t\t\t\t{2}\t\t\t\t{3}", "StopId", "Street", "Suburb", "Position")
                              };
            Array.ForEach(stopInfo.ToArray(), s => stopDetails.Add(string.Format("{0} (Z{1}):\t{2}\t{3}\t\t\t({4},{5}))", s.StopId, s.Zone, s.Street, s.Suburb, s.Latitude, s.Longitude)));
            return stopDetails;
        }
        public void GetStopsByIds_MustGetStopsByIds()
        {
            var requestEntity = new StopsRequest
            {
                StopIds = new List<string>() { "000026", "005468" }
            };

            var response = _client.PostAsJsonAsync("location/getstopsbyids", requestEntity).Result;
            response.EnsureSuccessStatusCode();
            var result = response.Content.ReadAsAsync<StopsResponse>().Result;
            Assert.IsTrue(result.Stops.Any());
        }
 public void StopsRequest_WithNoStopIds_MustThrowArgumentException()
 {
     var requestEntity = new StopsRequest();
     string expected = requestEntity.ToString();
 }
        public void StopsRequest_ToString_WithMandatoryValuesSet_MustReturnCorrectQueryString()
        {
            var requestEntity = new StopsRequest
            {
                StopIds = new List<string>() { "000026", "005468" }
            };

            string expected = string.Format("stops?ids=000026,005468");
            string actual = requestEntity.ToString();
            Assert.AreEqual(expected, actual);
        }
 public async Task<HttpResponseMessage> GetStopsByIds(StopsRequest request)
 {
     var result = CheckCacheForEntry<IRequest, StopsResponse>(request);
     if (result == null)
     {
         Logger.DebugFormat("Getting {0} from web: ", request.ToString());
         result = await new OpiaLocationClient().GetStopsByIdsAsync(request);
         await StoreResultInCache<IRequest, StopsResponse>(request, result);
     }
     var response = Request.CreateResponse(HttpStatusCode.OK, result);
     return response;
 }
        public async Task GetStopsByIdsAsync_MustGetStopsByIdsAsync()
        {
            var requestEntity = new StopsRequest
            {
                StopIds = new List<string>() { "000026", "005468" }
            };

            var locationClient = new OpiaLocationClient();
            var result = await locationClient.GetStopsByIdsAsync(requestEntity);
            Assert.IsTrue(result.Stops.Any());
        }
        public void GetStopsByIds_MustGetStopsByIds()
        {
            var requestEntity = new StopsRequest
            {
                StopIds = new List<string>() { "000026", "005468" }
            };

            var locationClient = new OpiaLocationClient();
            var result = locationClient.GetStopsByIds(requestEntity);
            Assert.IsTrue(result.Stops.Any());
        }