public void RouteTimeTablesRequest_ToString_WithEmptyRoutes_MustThrowArgumentException()
 {
     var requestEntity = new RouteTimeTablesRequest
     {
         FilterToStartEndStops = true,
         Date = DateTime.Now.AddDays(1),
         VehicleType = VehicleType.Bus,
     };
     string expected = requestEntity.ToString();
 }
 public void RouteTimeTablesRequest_ToString_WithDateNotSet_MustThrowArgumentException()
 {
     var requestEntity = new RouteTimeTablesRequest
     {
         RouteCodes = new List<string>() { "P137" },
         FilterToStartEndStops = true,
         VehicleType = VehicleType.Bus,
     };
     string expected = requestEntity.ToString();
 }
 public async Task<HttpResponseMessage> GetRouteTimeTables(RouteTimeTablesRequest request)
 {
     var result = CheckCacheForEntry<IRequest, RouteTimeTablesResponse>(request);
     if (result == null)
     {
         Logger.DebugFormat("Getting {0} from web: ", request.ToString());
         result = await new OpiaNetworkClient().GetRouteTimeTablesAsync(request);
         await StoreResultInCache<IRequest, RouteTimeTablesResponse>(request, result);
     }
     var response = Request.CreateResponse(HttpStatusCode.OK, result);
     return response;
 }
        public async Task GetRouteTimeTablesAsync_MustGetRouteTimeTables()
        {
            var requestEntity = new RouteTimeTablesRequest
            {
                Date = DateTime.Today.AddDays(1), // remember some express pre-paid routes don't run on weekends, P137 I am looking at you :)
                FilterToStartEndStops = false,
                VehicleType = VehicleType.Bus
            };
            requestEntity.RouteCodes.Add("130"); 

            var networkRequestClient = new OpiaNetworkClient();
            var result = await networkRequestClient.GetRouteTimeTablesAsync(requestEntity);
            Assert.IsTrue(result.RouteTimeTables.Any());
        }
        public void GetRouteTimeTables_MustGetRouteTimeTables()
        {
            var requestEntity = new RouteTimeTablesRequest
            {
                Date = DateTime.Today.AddDays(1), // remember some express pre-paid routes don't run on weekends, P137 I am looking at you :)
                FilterToStartEndStops = false,
                VehicleType = VehicleType.Bus
            };
            requestEntity.RouteCodes.Add("130");

            var response = _client.PostAsJsonAsync("network/getroutetimetables", requestEntity).Result;
            response.EnsureSuccessStatusCode();
            var result = response.Content.ReadAsAsync<RouteTimeTablesResponse>().Result;
            Assert.IsTrue(result.RouteTimeTables.Any());
        }
예제 #6
0
        private IEnumerable<RouteTimeTable> GetRouteTimeTablesFor(string routeNo)
        {
            var requestEntity = new RouteTimeTablesRequest
                                {
                                    RouteCodes = new List<string> { routeNo },
                                    Date = DateTime.Today.AddDays(1),
                                    // remember some express pre-paid bus routes don't run on weekends e.g. P137
                                    FilterToStartEndStops = false,
                                    VehicleType = VehicleType.Bus
                                };

            var response = _client.PostAsJsonAsync("network/getroutetimetables", requestEntity).Result;
            response.EnsureSuccessStatusCode();
            var routeTimeTables = response.Content.ReadAsAsync<RouteTimeTablesResponse>().Result.RouteTimeTables.ToList();
            return routeTimeTables;
        }
        public void RouteTimeTablesRequest_ToString_WithMandatoryValuesSet_MustReturnCorrectQueryString()
        {
            var requestEntity = new RouteTimeTablesRequest
                        {
                            RouteCodes = new List<string>(){"P137", "130"},
                            FilterToStartEndStops = true,
                            VehicleType = VehicleType.Bus,
                            Date = DateTime.Now.AddDays(1),
                        };

            // route-timetables?routeCodes=P137,130&date=2013-08-07&vehicleType=2&filterToStartEndStops=true
            string expected = string.Format("route-timetables?routeCodes=P137,130&date={0}&vehicleType=2&filterToStartEndStops=true", DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"));

            string actual = requestEntity.ToString();
            Assert.AreEqual(expected, actual);
        }