Пример #1
0
        static void Main(string[] args)
        {
            //Class :: get JSON response for given URL
            SWARequest CSWARequest = new SWARequest();
            //Class :: parse JSON response
            SWAJson CSWAJson = new SWAJson();

            //result data for display
            List <SWAModel.Ship> ships = new List <SWAModel.Ship>();

            string pathURL = "https://swapi.co/api/starships/";

            //Show message for user input
            Console.WriteLine(string_all.InputEnterNumber);
            //wait for it ...
            string distance = Console.ReadLine();

            //check if input is valid integer greater then zero
            if (SWAHellper.IsStringPositiveInteger(distance))
            {
                //only ten rows per call
                while (pathURL != string.Empty)
                {
                    try
                    {
                        //get JSON response for API call
                        string jsonResponse = CSWARequest.GetJsonResponse(pathURL);
                        //parse response into ships
                        ships.AddRange(CSWAJson.GetShipsAndDistances(jsonResponse, distance));

                        //check if there is another page to call
                        pathURL = CSWAJson.NextPageURL;
                    }
                    catch (Exception ex)
                    {
                        //something is wrong
                        Console.WriteLine(ex.Message);
                        pathURL = string.Empty;
                    }
                }

                //results are here
                foreach (SWAModel.Ship ship in ships)
                {
                    Console.WriteLine(string.Format("{0}: {1}", ship.name, ship.jumps));
                }
            }
            else
            {
                //input is not integer
                Console.WriteLine(string_all.WarningEnterNumber);
            }

            Console.ReadLine();
        }
Пример #2
0
        public void String_Over_Max_Positive_Integer()
        {
            var resultIsPositive = SWAHellper.IsStringPositiveInteger("100000000000000000000000000000000000000000");

            Assert.AreEqual(false, resultIsPositive);
        }
Пример #3
0
        public void String_Is_Not_Integer()
        {
            var resultIsPositive = SWAHellper.IsStringPositiveInteger("");

            Assert.AreEqual(false, resultIsPositive);
        }
Пример #4
0
        public void String_Is_Max_Positive_Integer()
        {
            var resultIsPositive = SWAHellper.IsStringPositiveInteger("2147483647");

            Assert.AreEqual(true, resultIsPositive);
        }