コード例 #1
0
        public void GetStationFromName_StationNotFound_ThrowsException()
        {
            UnitTestStationInformationLoader loader = new UnitTestStationInformationLoader();

            Stations stations = new Stations(loader);

            Assert.Throws <StationNotFoundException>(() => stations.GetStationFromName("St. Stephen's Green"));
        }
コード例 #2
0
        public void GetStationFromName_NullAbbreviation_ThrowsArgumentException()
        {
            UnitTestStationInformationLoader loader = new UnitTestStationInformationLoader();

            Stations stations = new Stations(loader);

            Assert.Throws <ArgumentException>(() => stations.GetStationFromName(null));
        }
コード例 #3
0
        public void GetStationFromName_WhiteSpaceAbbreviation_ThrowsArgumentException()
        {
            UnitTestStationInformationLoader loader = new UnitTestStationInformationLoader();

            Stations stations = new Stations(loader);

            Assert.Throws <ArgumentException>(() => stations.GetStationFromName(string.Empty));
        }
コード例 #4
0
        public void GetStationFromName_LowercaseQueryStationExists_ReturnsStation()
        {
            UnitTestStationInformationLoader loader = new UnitTestStationInformationLoader();

            Station station = new Station {
                Name = "St. Stephen's Green", Abbreviation = "STS"
            };

            loader.AddStations(station);

            Stations stations = new Stations(loader);

            Assert.Equal(station, stations.GetStationFromName(station.Name.ToLowerInvariant()));
        }
コード例 #5
0
        public void GetStationFromName_MoreThanOneStationAvailable_ReturnsCorrectStation()
        {
            UnitTestStationInformationLoader loader = new UnitTestStationInformationLoader();

            Station alternativeStation = new Station {
                Name = "Harcourt", Abbreviation = "HAR"
            };
            Station stationToQuery = new Station {
                Name = "St. Stephen's Green", Abbreviation = "STS"
            };

            loader.AddStations(alternativeStation, stationToQuery);

            Stations stations = new Stations(loader);

            Assert.Equal(stationToQuery, stations.GetStationFromName(stationToQuery.Name));
        }
コード例 #6
0
        public static TramForecast CreateTramForecastFromTramXml(TramXml tramXml, Stations stations)
        {
            if (tramXml?.Destination == "No trams forecast" && string.IsNullOrEmpty(tramXml.Destination))
            {
                return(null);
            }

            if (stations == null)
            {
                throw new ArgumentNullException(nameof(stations));
            }

            if (!int.TryParse(tramXml.DueMins, out int dueMinutes))
            {
                dueMinutes = 0;
            }

            try
            {
                Station destinationStation = stations.GetStationFromName(tramXml.Destination);

                TramForecast tramForecast = new TramForecast
                {
                    DestinationStation = destinationStation,
                    Minutes            = dueMinutes,
                    IsDue = dueMinutes == 0
                };

                return(tramForecast);
            }
            catch (StationNotFoundException ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(null);
        }