예제 #1
0
        // 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}");
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        public async Task WillReturnCollectionWith37Items()
        {
            var client = new SWAPIClient(provider.GetService <IHttpClientFactory>());

            var result = await client.GetStarshipData();

            Assert.NotNull(result);
            Assert.True(result.Count == 37);
        }
예제 #3
0
        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));
        }
예제 #4
0
        /// <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();
            }
        }
예제 #5
0
        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);
        }
예제 #6
0
 public static async Task <IEnumerable <People> > GetPeopleAsync(this Species species, SWAPIClient apiClient)
 {
     return(await apiClient.GetListAsync <People>(species.people));
 }
예제 #7
0
 public static async Task <IEnumerable <Film> > GetFilmsAsync(this Starship starship, SWAPIClient apiClient)
 {
     return(await apiClient.GetListAsync <Film>(starship.films));
 }
예제 #8
0
 public static async Task <IEnumerable <Film> > GetFilmsAsync(this Vehicle vehicle, SWAPIClient apiClient)
 {
     return(await apiClient.GetListAsync <Film>(vehicle.films));
 }
예제 #9
0
 public static async Task <IEnumerable <Film> > GetFilmsAsync(this Planet planet, SWAPIClient apiClient)
 {
     return(await apiClient.GetListAsync <Film>(planet.films));
 }
예제 #10
0
 public static async Task <IEnumerable <Starship> > GetStarshipsAsync(this Film film, SWAPIClient apiClient)
 {
     return(await apiClient.GetListAsync <Starship>(film.starships));
 }
예제 #11
0
 public static async Task <IEnumerable <Species> > GetSpeciesAsync(this People person, SWAPIClient apiClient)
 {
     return(await apiClient.GetListAsync <Species>(person.species));
 }
예제 #12
0
 public static async Task <IEnumerable <Film> > GetFilmsAsync(this People person, SWAPIClient apiClient)
 {
     return(await apiClient.GetListAsync <Film>(person.films));
 }
예제 #13
0
 public static async Task <IEnumerable <Vehicle> > GetVehiclesAsync(this People person, SWAPIClient apiClient)
 {
     return(await apiClient.GetListAsync <Vehicle>(person.vehicles));
 }
예제 #14
0
 public static async Task <IEnumerable <Starship> > GetStarshipsAsync(this People person, SWAPIClient apiClient)
 {
     return(await apiClient.GetListAsync <Starship>(person.starships));
 }
예제 #15
0
 public static async Task <EntryList <T> > GetNext <T>(this EntryList <T> entryList, SWAPIClient apiClient)
 {
     return(await apiClient.GetAsync <EntryList <T> >(entryList.next));
 }
예제 #16
0
 public static async Task <EntryList <T> > GetPrevious <T>(this EntryList <T> entryList, SWAPIClient apiClient)
 {
     return(await apiClient.GetAsync <EntryList <T> >(entryList.previous));
 }
예제 #17
0
 public static async Task <IEnumerable <Vehicle> > GetVehiclesAsync(this Film film, SWAPIClient apiClient)
 {
     return(await apiClient.GetListAsync <Vehicle>(film.vehicles));
 }
예제 #18
0
 public static async Task <IEnumerable <People> > GetResidentsAsync(this Planet planet, SWAPIClient apiClient)
 {
     return(await apiClient.GetListAsync <People>(planet.residents));
 }
예제 #19
0
 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;
 }
예제 #21
0
 public static async Task <IEnumerable <Planet> > GetPlanetAsync(this Film film, SWAPIClient apiClient)
 {
     return(await apiClient.GetListAsync <Planet>(film.planets));
 }
예제 #22
0
 public static async Task <IEnumerable <People> > GetPilotsAsync(this Vehicle vehicle, SWAPIClient apiClient)
 {
     return(await apiClient.GetListAsync <People>(vehicle.pilots));
 }
예제 #23
0
 public static async Task <IEnumerable <Species> > GetSpeciesAsync(this Film film, SWAPIClient apiClient)
 {
     return(await apiClient.GetListAsync <Species>(film.species));
 }
예제 #24
0
 public static async Task <IEnumerable <People> > GetPilotsAsync(this Starship starship, SWAPIClient apiClient)
 {
     return(await apiClient.GetListAsync <People>(starship.pilots));
 }
예제 #25
0
 public static async Task <IEnumerable <Film> > GetFilmsAsync(this Species species, SWAPIClient apiClient)
 {
     return(await apiClient.GetListAsync <Film>(species.films));
 }