public void CreateStationForecastFromRealTimeInfo_()
        {
            UnitTestStationInformationLoader loader = new UnitTestStationInformationLoader();

            loader.AddStations(new Station()
            {
                Abbreviation = "STS", Name = "St. Stephen's Green", IsInUse = true
            });
            loader.AddStations(new Station()
            {
                Abbreviation = "PAR", Name = "Parnell", IsInUse = true
            });
            loader.AddStations(new Station()
            {
                Abbreviation = "SAN", Name = "Sandyford", IsInUse = true
            });

            Stations stations = new Stations(loader);

            RealTimeInfo realTimeInfo = CreateRealTimeInfoFromXml("<stopInfo created=\"2019-12-31T12:00:00\" stop=\"St. Stephen's Green\" stopAbv=\"STS\"><message>Green Line services operating normally</message><direction name=\"Inbound\"><tram destination=\"Parnell\" dueMins=\"1\" /></direction><direction name=\"Outbound\"><tram dueMins=\"6\" destination=\"Sandyford\" /></direction></stopInfo>");

            StationForecast forecast = StationForecast.CreateStationForecastFromRealTimeInfo(realTimeInfo, stations);

            Assert.Equal(realTimeInfo.Stop, forecast.Station.Name);
            Assert.Single(forecast.InboundTrams);
            Assert.Single(forecast.OutboundTrams);
        }
        public void CreateStationForecastFromRealTimeInfo_StationsIsNull_ThrowsArgumentException()
        {
            RealTimeInfo realTimeInfoXml = new RealTimeInfo();
            Stations     stations        = null;

            Assert.Throws <ArgumentException>(() => StationForecast.CreateStationForecastFromRealTimeInfo(realTimeInfoXml, stations));
        }
        public void CreateStationForecastFromRealTimeInfo_RealTimeInfoIsNull_ThrowsArgumentException()
        {
            RealTimeInfo realTimeInfoXml = null;
            Stations     stations        = new Stations(new UnitTestStationInformationLoader());

            Assert.Throws <ArgumentException>(() => StationForecast.CreateStationForecastFromRealTimeInfo(realTimeInfoXml, stations));
        }
Ejemplo n.º 4
0
        public async Task <StationForecast> GetForecastAsync(string stationAbbreviation)
        {
            IForecastClient client   = new LuasForecastApiClient(stations);
            StationForecast forecast = await client.GetRealTimeInfoAsync(stationAbbreviation).ConfigureAwait(false);

            return(forecast);
        }
Ejemplo n.º 5
0
        public long ForecastAsync(string station)
        {
            Stopwatch.Restart();

            StationForecast sfAsync = Api.GetForecastAsync(station).Result;

            Stopwatch.Stop();
            Console.WriteLine($"{station}: {sfAsync.InboundTrams[0].Minutes} ({Stopwatch.ElapsedMilliseconds})");

            return(Stopwatch.ElapsedMilliseconds);
        }
        public async Task <StationForecast> GetRealTimeInfoAsync(string stationAbbreviation)
        {
            if (string.IsNullOrEmpty(stationAbbreviation))
            {
                throw new ArgumentException("Can't get the forecast of a station that does not exist.", nameof(stationAbbreviation));
            }

            Uri uri = new Uri(string.Format(CultureInfo.InvariantCulture, LuasApiUrl, stationAbbreviation));

            using (HttpClient client = new HttpClient())
                using (HttpResponseMessage response = await client.GetAsync(uri).ConfigureAwait(false))
                    using (HttpContent content = response.Content)
                        using (Stream stream = await content.ReadAsStreamAsync().ConfigureAwait(false))
                        {
                            return(StationForecast.CreateStationForecastFromRealTimeInfo(RealTimeInfo.CreateFromStream(stream), stations));
                        }
        }