コード例 #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
ファイル: UnitTest1.cs プロジェクト: tobaotic/sw-api
        public void String_Over_Max_Positive_Integer()
        {
            var resultIsPositive = SWAHellper.IsStringPositiveInteger("100000000000000000000000000000000000000000");

            Assert.AreEqual(false, resultIsPositive);
        }
コード例 #3
0
ファイル: UnitTest1.cs プロジェクト: tobaotic/sw-api
        public void String_Is_Not_Integer()
        {
            var resultIsPositive = SWAHellper.IsStringPositiveInteger("");

            Assert.AreEqual(false, resultIsPositive);
        }
コード例 #4
0
ファイル: UnitTest1.cs プロジェクト: tobaotic/sw-api
        public void String_Is_Max_Positive_Integer()
        {
            var resultIsPositive = SWAHellper.IsStringPositiveInteger("2147483647");

            Assert.AreEqual(true, resultIsPositive);
        }
コード例 #5
0
ファイル: UnitTest1.cs プロジェクト: tobaotic/sw-api
        public void Jump_Calculations_No_Go()
        {
            var resultJumps = SWAHellper.CalculateStopsForDestination("15", "unknown");

            Assert.AreEqual("Can not calculate number of stops!", resultJumps);
        }
コード例 #6
0
ファイル: UnitTest1.cs プロジェクト: tobaotic/sw-api
        public void Jump_Calculations_Below()
        {
            var resultJumps = SWAHellper.CalculateStopsForDestination("15", "22");

            Assert.AreEqual("0", resultJumps);
        }
コード例 #7
0
ファイル: UnitTest1.cs プロジェクト: tobaotic/sw-api
        public void Jump_Calculations_Over()
        {
            var resultJumps = SWAHellper.CalculateStopsForDestination("40", "15");

            Assert.AreEqual("2", resultJumps);
        }
コード例 #8
0
ファイル: UnitTest1.cs プロジェクト: tobaotic/sw-api
        public void Jump_Calculations_Exactly()
        {
            var resultJumps = SWAHellper.CalculateStopsForDestination("30", "15");

            Assert.AreEqual("1", resultJumps);
        }