public virtual async IAsyncEnumerable <FlightView> GetFlights()
        {
            Queue <Flight> flights = _flightRepository.GetFlights();

            foreach (Flight flight in flights)
            {
                Airport originAirport;
                Airport destinationAirport;

                try
                {
                    originAirport = await _airportRepository.GetAirportByID(flight.Origin);

                    destinationAirport = await _airportRepository.GetAirportByID(flight.Destination);
                }
                catch (FlightNotFoundException)
                {
                    throw new FlightNotFoundException();
                }
                catch (Exception)
                {
                    throw new ArgumentException();
                }

                yield return(new FlightView(flight.FlightNumber.ToString(), (originAirport.City, originAirport.Iata), (destinationAirport.City, destinationAirport.Iata)));
            }
        }
Example #2
0
        public async Task GetAirportByID_Success(int airportId)
        {
            Airport airport = await _repository.GetAirportByID(airportId);

            Assert.IsNotNull(airport);

            Airport dbAirport = _context.Airports.First(a => a.AirportId == airportId);

            Assert.AreEqual(dbAirport.AirportId, airport.AirportId);
            Assert.AreEqual(dbAirport.City, airport.City);
            Assert.AreEqual(dbAirport.Iata, airport.Iata);
        }
Example #3
0
 public AirportDto FindAirport(AirportDto airportDto)
 {
     return(AirportMapper.toDto(AirportRepository.GetAirportByID(airportDto.AirportId)));
 }