// This program asks for number of passengers as input // and returns all ships and all pilots of said ships // that both exist in the Star Wars API (swapi.co) and // can carry that number of passengers static void Main(string[] args) { Console.Write("Enter number of passengers: "); var input = Console.ReadLine(); if (int.TryParse(input, out int passengers)) { var swApiClient = new SWAPIClient(); var ships = swApiClient.GetAllStarshipsAsync().Result; foreach (var ship in ships) { if (long.TryParse(ship.passengers, out long shipPassengers)) { if (passengers <= shipPassengers) { var pilots = ship.GetPilotsAsync(swApiClient).Result; if (pilots.Count() == 0) { Console.WriteLine($"{ship.name} - No pilots listed"); continue; } foreach (var pilot in pilots) { Console.WriteLine($"{ship.name} - {pilot.name}"); } } } } } }
public async Task WillReturnCollectionWith37Items() { var client = new SWAPIClient(provider.GetService <IHttpClientFactory>()); var result = await client.GetStarshipData(); Assert.NotNull(result); Assert.True(result.Count == 37); }
public async Task WillReturnConsumablesAsDays() { var client = new SWAPIClient (provider.GetService <IHttpClientFactory>()); var handler = new StoppingHandler(); var result = await client.GetStarshipData(); Assert.NotNull(result); Assert.Equal(2190, handler.PeriodToDays(result.ToList()[0].Consumables)); }
/// <summary> /// Loads the data from the api and converts to a collection of Starship. /// </summary> /// <returns></returns> public async Task LoadShips() { var loadedData = await SWAPIClient.DownloadStarshipsData(); if (loadedData != null) { Ships = loadedData.Select(x => new Starship() { Name = x.Name, MGLT = x.MGLT.ConvertToLongOrNull(), AvailableConsumablesInHours = x.Consumables.ComputeConsumablesDuration() }).ToList(); } }
public async Task WillGetNumberOfStops() { var client = new SWAPIClient(provider.GetService <IHttpClientFactory>()); var handler = new StoppingHandler(); var result = await client.GetStarshipData(); //Millennium Falcon: 9 //Index in collection: 3 var milleniumFalcon = result.ToList()[3]; var convertedConsumables = handler.PeriodToDays(milleniumFalcon.Consumables); var milleniumFalconStops = handler.NumberOfStops(1000000, Convert.ToInt32(milleniumFalcon.MGLT), convertedConsumables); Assert.NotNull(result); Assert.Equal(9, milleniumFalconStops); }
public static async Task <IEnumerable <People> > GetPeopleAsync(this Species species, SWAPIClient apiClient) { return(await apiClient.GetListAsync <People>(species.people)); }
public static async Task <IEnumerable <Film> > GetFilmsAsync(this Starship starship, SWAPIClient apiClient) { return(await apiClient.GetListAsync <Film>(starship.films)); }
public static async Task <IEnumerable <Film> > GetFilmsAsync(this Vehicle vehicle, SWAPIClient apiClient) { return(await apiClient.GetListAsync <Film>(vehicle.films)); }
public static async Task <IEnumerable <Film> > GetFilmsAsync(this Planet planet, SWAPIClient apiClient) { return(await apiClient.GetListAsync <Film>(planet.films)); }
public static async Task <IEnumerable <Starship> > GetStarshipsAsync(this Film film, SWAPIClient apiClient) { return(await apiClient.GetListAsync <Starship>(film.starships)); }
public static async Task <IEnumerable <Species> > GetSpeciesAsync(this People person, SWAPIClient apiClient) { return(await apiClient.GetListAsync <Species>(person.species)); }
public static async Task <IEnumerable <Film> > GetFilmsAsync(this People person, SWAPIClient apiClient) { return(await apiClient.GetListAsync <Film>(person.films)); }
public static async Task <IEnumerable <Vehicle> > GetVehiclesAsync(this People person, SWAPIClient apiClient) { return(await apiClient.GetListAsync <Vehicle>(person.vehicles)); }
public static async Task <IEnumerable <Starship> > GetStarshipsAsync(this People person, SWAPIClient apiClient) { return(await apiClient.GetListAsync <Starship>(person.starships)); }
public static async Task <EntryList <T> > GetNext <T>(this EntryList <T> entryList, SWAPIClient apiClient) { return(await apiClient.GetAsync <EntryList <T> >(entryList.next)); }
public static async Task <EntryList <T> > GetPrevious <T>(this EntryList <T> entryList, SWAPIClient apiClient) { return(await apiClient.GetAsync <EntryList <T> >(entryList.previous)); }
public static async Task <IEnumerable <Vehicle> > GetVehiclesAsync(this Film film, SWAPIClient apiClient) { return(await apiClient.GetListAsync <Vehicle>(film.vehicles)); }
public static async Task <IEnumerable <People> > GetResidentsAsync(this Planet planet, SWAPIClient apiClient) { return(await apiClient.GetListAsync <People>(planet.residents)); }
public static async Task <IEnumerable <People> > GetCharactersAsync(this Film film, SWAPIClient apiClient) { return(await apiClient.GetListAsync <People>(film.characters)); }
public StarWars(SWAPIClient swapiClient) { _swapiClient = swapiClient; }
public static async Task <IEnumerable <Planet> > GetPlanetAsync(this Film film, SWAPIClient apiClient) { return(await apiClient.GetListAsync <Planet>(film.planets)); }
public static async Task <IEnumerable <People> > GetPilotsAsync(this Vehicle vehicle, SWAPIClient apiClient) { return(await apiClient.GetListAsync <People>(vehicle.pilots)); }
public static async Task <IEnumerable <Species> > GetSpeciesAsync(this Film film, SWAPIClient apiClient) { return(await apiClient.GetListAsync <Species>(film.species)); }
public static async Task <IEnumerable <People> > GetPilotsAsync(this Starship starship, SWAPIClient apiClient) { return(await apiClient.GetListAsync <People>(starship.pilots)); }
public static async Task <IEnumerable <Film> > GetFilmsAsync(this Species species, SWAPIClient apiClient) { return(await apiClient.GetListAsync <Film>(species.films)); }