Esempio n. 1
0
        public void CreateFromStream_CorrectXmlSchema_ReturnsObject()
        {
            string xml    = "<stopInfo created=\"2019-12-28T12:06:00\" stop=\"St. Stephen's Green\" stopAbv=\"STS\"><message>Green Line Service Disruption See News</message><direction name=\"Inbound\"><tram destination=\"See news for information\" dueMins=\"\" /></direction><direction name=\"Outbound\"><tram dueMins=\"6\" destination=\"Sandyford\" /></direction></stopInfo>";
            Stream stream = ConvertStringToStream(xml);

            Assert.IsType <RealTimeInfo>(RealTimeInfo.CreateFromStream(stream));
        }
Esempio n. 2
0
        public void CreateFromStream_EmptyString_ThrowsInvalidOperation()
        {
            string xml    = string.Empty;
            Stream stream = ConvertStringToStream(xml);

            Assert.Throws <InvalidOperationException>(() => RealTimeInfo.CreateFromStream(stream));
        }
Esempio n. 3
0
        public void CreateFromStream_IncorrectXmlSchema_ThrowsInvalidOperation()
        {
            string xml    = "<sample></sample>";
            Stream stream = ConvertStringToStream(xml);

            Assert.Throws <InvalidOperationException>(() => RealTimeInfo.CreateFromStream(stream));
        }
        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));
                        }
        }