Exemple #1
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Inform the distance in mega lights:");
            string distance   = Console.ReadLine();
            int    countPages = 1;

            string url             = "http://swapi.dev/api/starships/";
            var    starShipFacade  = new StarShipFacade();
            var    starShipService = new StarShipService(starShipFacade);

            try
            {
                do
                {
                    StarShipDTO starShipDTO = starShipService.GetStopsRequired(distance, url);
                    BuildHeader(countPages);
                    ShowStarShips(starShipDTO);
                    url = starShipDTO.NextPage;
                    countPages++;
                } while (!string.IsNullOrEmpty(url));
            }
            catch (DistanceInvalidException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (StarShipsNullException ex)
            {
                Console.WriteLine(ex.Message);
            }

            ReadKeyToExit();
        }
Exemple #2
0
        public static async Task ShowOneShip(int shipId)
        {
            var ship = await StarShipService.GetShip(shipId);

            if (ship == null)
            {
                Console.WriteLine($"Sorry, couldn't find ship with id: {shipId}");
            }
            else
            {
                ObjectExtensions.PrintObject(ship);
            }
        }
Exemple #3
0
        private async static Task GetAllShips(Action <IEnumerable <StarShipModel> > afterFinished)
        {
            int  page     = 0;
            bool hasItems = false;

            do
            {
                page++;
                await StarShipService.GetAllShipsPaged(page)
                .ContinueWith(task =>
                {
                    hasItems = task.Result != null && task.Result.Any();
                    afterFinished(task.Result);
                });
            } while (hasItems);
        }
Exemple #4
0
        public static void Start()
        {
            Configuration = new ConfigurationBuilder()
                            .SetBasePath(Directory.GetCurrentDirectory())
                            .AddJsonFile("appsettings.json")
                            .Build();

            Console.BufferHeight = 500;

            while (!StarShipService.CheckConnection())
            {
                Console.Clear();
                Console.WriteLine("The empire have cut off our connection to the server!");
                Console.WriteLine("Trying again in 3 second.");
                Thread.Sleep(3000);
            }
        }
Exemple #5
0
        public async static Task DownloadAllShips()
        {
            var success = false;

            Console.WriteLine("Downloading...");
            var ships = await StarShipService.GetAllShips();

            string folder = AppManager.DefaultDownloadFolder;

            while (!success && !Directory.Exists(folder))
            {
                Console.WriteLine("Please, specify the folder where we can download the ships:");
                folder = Console.ReadLine();

                try
                {
                    var fullPath = $@"{folder}\starships.csv";
                    Console.WriteLine("Writing to: " + fullPath);

                    await File.WriteAllTextAsync(fullPath, ships.ToCsv());

                    success = true;
                }
                catch (UnauthorizedAccessException)
                {
                    success = false;
                    Console.WriteLine("The application does not have acces to create a file in the selected path.");
                }
                catch (DirectoryNotFoundException)
                {
                    success = false;
                    Console.WriteLine("The application couldn't find the path inputed.");
                }
            }

            Console.WriteLine("Done!");
        }
Exemple #6
0
        private async static Task <StarShipModel> GetShip()
        {
            Console.WriteLine("Please, specify the ship id: ");
            var idInput = Console.ReadLine();

            if (int.TryParse(idInput, out int id))
            {
                Console.WriteLine("Searching...");
                var ship = await StarShipService.GetShip(id);

                if (ship != null)
                {
                    return(ship);
                }

                Console.WriteLine("Couldn't find ship by id: " + id);
                return(await GetShip());
            }
            else
            {
                Console.WriteLine("Please inform a valid MGLT number");
                return(await GetShip());
            }
        }
Exemple #7
0
 public WhenRequestingNumberOfStopsForAllStarShips()
 {
     this.deserializer = new ApiResponseDeserializer();
     this.mapper       = new StarShipMap();
     this.service      = new StarShipService(this.ApiClient, deserializer, mapper);
 }
 public void TearDown()
 {
     _starWarsRepository = null;
     starShipService     = null;
 }
 public void Setup()
 {
     _starWarsRepository = new Mock <IStarWarsRepository>();
     starShipService     = new StarShipService(_starWarsRepository.Object);
 }
Exemple #10
0
        public StarShipServiceTest()
        {
            IStarShip starShipMock = CriarMockStarShip();

            this.starShipService = new StarShipService(starShipMock);
        }