public void TestValidCountries() { using (var dataProvider = new OpenFlightsDataCountryProvider(Path.GetTempFileName())) { try { var countries = dataProvider.GetAllCountries(); int totalCount = 0; int missingName = 0; int missingAlpha2 = 0; foreach (Country country in countries) { totalCount++; Assert.IsNotNull(country); if (String.IsNullOrEmpty(country.Name)) { missingName++; } if (String.IsNullOrEmpty(country.Alpha2)) { missingAlpha2++; } } Console.WriteLine( $"{totalCount} countries correctly read. {dataProvider.BadDataRowCount} rows skipped due to bad data."); Console.WriteLine( $"Missing data: name - {missingName}, alpha2 - {missingAlpha2}"); } finally { dataProvider.ClearCache(); } } }
public void TestListInvalidAirports() { var countries = new Dictionary <string, Country>(); using (var countryProvider = new OpenFlightsDataCountryProvider(Path.GetTempFileName())) { try { foreach (var country in countryProvider.GetAllCountries()) { if (!string.IsNullOrEmpty(country.Name) && !countries.ContainsKey(country.Name)) { countries.Add(country.Name, country); } //throw new InvalidDataException($"Invalid country with name {country.Name} received"); } } finally { countryProvider.ClearCache(); } } using (var airportProvider = new OpenFlightsDataAirportProvider(Path.GetTempFileName())) { try { IEnumerable <Airport> airports = airportProvider.GetAllAirports(); int validAirports = 0; int invalidAirports = 0; int missingCountryName = 0; int missingCountryMapping = 0; int missingTimezoneName = 0; foreach (Airport airport in airports.Where(x => !String.IsNullOrEmpty(x.IataCode))) { bool allValid = true; if (String.IsNullOrEmpty(airport.CountryName)) { Console.WriteLine($"Airport '{airport.Name}' ({airport.IataCode}) is missing Country name"); missingCountryName++; allValid = false; } else { countries.TryGetValue(airport.CountryName, out Country country); if (country == null) { Console.WriteLine($"Airport '{airport.Name}' ({airport.IataCode}) has a country '{airport.CountryName}' that cannot be mapped to Alpha 2"); missingCountryMapping++; allValid = false; } } if (String.IsNullOrEmpty(airport.TimeZoneName) && airport.TimeZoneUtcOffset == 0F) { Console.WriteLine($"Airport '{airport.Name}' ({airport.IataCode}) is missing Timezone information"); missingTimezoneName++; allValid = false; } if (allValid) { validAirports++; } else { invalidAirports++; } } Console.WriteLine($"Read {validAirports} valid airports. and {invalidAirports} invalid airports"); Console.WriteLine($"Missing info: {missingCountryName} country names, {missingCountryMapping} country mappings, {missingTimezoneName} time zones"); } finally { airportProvider.ClearCache(); } } }