Exemple #1
0
        public async Task ListStations_MalformedPagination()
        {
            var response = await this.stationsApi.ListStations(new ListStationsRequest()
            {
                PageSize = 1
            }, null);

            var expected = new ListStationsResponse()
            {
                Stations =
                {
                    EXPECTED_NEWARK_STATION
                }
            };

            Assert.AreEqual(expected.Stations, response.Stations);
            Assert.IsNotNull(response.NextPageToken);
            Assert.AreNotEqual(string.Empty, response.NextPageToken);

            RpcException exception = await Assert.ThrowsExceptionAsync <RpcException>(async() => await this.stationsApi.ListStations(new ListStationsRequest()
            {
                PageSize  = 1,
                PageToken = "SOMEGARBO"
            }, null));

            Assert.AreEqual(StatusCode.InvalidArgument, exception.StatusCode);
        }
Exemple #2
0
        /// <summary>
        /// Handles the ListStations request.
        /// </summary>
        public override async Task <ListStationsResponse> ListStations(ListStationsRequest request, ServerCallContext context)
        {
            int offset   = PaginationHelper.GetOffset(request.PageToken);
            int pageSize = request.PageSize == 0 ? DEFAULT_PAGE_SIZE : request.PageSize;

            ListStationsResponse response = new ListStationsResponse();
            List <StationData>   stations = new List <StationData>();

            foreach (var station in (System.Enum.GetValues(typeof(Station)) as Station[]).Where((station) => station != Station.Unspecified).Distinct())
            {
                try
                {
                    var stops = await this.pathDataRepository.GetStops(station);

                    stations.Add(this.ToStation(station, stops));
                }
                catch (Exception ex)
                {
                    Log.Logger.Here().Warning(ex, "Failed to load expected station {station}.", station);
                }
            }
            response.Stations.Add(stations.Skip(offset).Take(pageSize));
            if (stations.Count > offset + pageSize)
            {
                response.NextPageToken = PaginationHelper.GetPageToken(offset + pageSize);
            }
            return(response);
        }
Exemple #3
0
        public async Task ListStations_Pagination()
        {
            var response = await this.stationsApi.ListStations(new ListStationsRequest()
            {
                PageSize = 1
            }, null);

            var expected = new ListStationsResponse()
            {
                Stations =
                {
                    EXPECTED_NEWARK_STATION
                }
            };

            Assert.AreEqual(expected.Stations, response.Stations);
            Assert.IsNotNull(response.NextPageToken);
            Assert.AreNotEqual(string.Empty, response.NextPageToken);

            response = await this.stationsApi.ListStations(new ListStationsRequest()
            {
                PageSize  = 1,
                PageToken = response.NextPageToken
            }, null);

            expected = new ListStationsResponse()
            {
                Stations =
                {
                    EXPECTED_GROVE_STATION
                }
            };
            Assert.AreEqual(expected.Stations, response.Stations);
            Assert.AreEqual(string.Empty, response.NextPageToken);
        }