Exemplo n.º 1
0
        private static void Main(string[] args)
        {
            WriteHeader();
            var input = Console.ReadLine();

            while (input != "q")
            {
                Console.Clear();
                ulong distance = ulong.TryParse(input, out distance) ? distance : 1000000;

                Console.WriteLine("------------------------------------------------");
                Console.WriteLine($"Calculating Starships stops to: {distance} MGLT");
                Console.WriteLine("------------------------------------------------");
                List <StarshipModel> calculatedStops = StarshipBusiness.GetStarshipStops(distance);
                Console.Clear();

                Console.WriteLine("------------------------------------------------");
                Console.WriteLine($"Calculated Starships stops to: {distance} MGLT");
                Console.WriteLine("------------------------------------------------");
                calculatedStops.Where(x => x.stops > 0).ToList().ForEach(x => Console.WriteLine($"{x.name}: {x.stops}"));

                Console.WriteLine("-----------------------------------------------------------------");
                Console.WriteLine("\nThe Starships below do not have enough information to calculate:");
                Console.WriteLine("-----------------------------------------------------------------");
                calculatedStops.Where(x => x.stops == 0).ToList().ForEach(x => Console.WriteLine($"{x.name}: {x.stops}"));

                WriteHeader();
                input = Console.ReadLine();
            }

            Console.Clear();
            Console.WriteLine("------------------------------------------");
            Console.WriteLine("Thank you, I hope you enjoyed!");
            Console.WriteLine("------------------------------------------");
        }
Exemplo n.º 2
0
        public void Should_GetStarshipStops_Bring_Results()
        {
            System.Collections.Generic.List <Models.StarshipModel> returnValue = StarshipBusiness.GetStarshipStops(200);

            Assert.IsNotNull(returnValue);
            Assert.Pass("OK for GetStarshipStops Should Bring Results test");
        }
Exemplo n.º 3
0
        public void Should_CalculateStarshipStops_Not_Throw_Exception_If_Input_Is_Null_Or_Zero()
        {
            List <StarshipModel> list = null;

            StarshipBusiness.CalculateStarshipStops(ref list, 0);
            Assert.Pass("OK for CalculateStarshipStops Null And Zero Values test");
        }
Exemplo n.º 4
0
        public void Should_CalculateStarshipStops_Greather_Than_Zero_If_Input_Is_Valid2()
        {
            StarshipBusiness.CalculateStarshipStops(ref _starshipValidList, 1000000);

            _starshipValidList.ForEach(x => Assert.IsTrue(x.stops > 0));

            Assert.Pass("OK for CalculateStarshipStops valid Starshiplist test");
        }
Exemplo n.º 5
0
        public void Should_CalculateStarshipStops_Not_Throw_Exception_If_Input_Is_Invalid()
        {
            StarshipBusiness.CalculateStarshipStops(ref _starshipInvalidList, 0);

            _starshipInvalidList.ForEach(x => Assert.AreEqual(x.stops, 0));

            Assert.Pass("OK for CalculateStarshipStops Invalid Starshiplist test");
        }
Exemplo n.º 6
0
 public void Should_GetSpentPerHour_Return_Default_Value_If_Consumables_Has_Zero_Values()
 {
     Assert.AreEqual(StarshipBusiness.GetSpentPerHour("0 days"), 0);
     Assert.AreEqual(StarshipBusiness.GetSpentPerHour("0 weeks"), 0);
     Assert.AreEqual(StarshipBusiness.GetSpentPerHour("0 months"), 0);
     Assert.AreEqual(StarshipBusiness.GetSpentPerHour("0 years"), 0);
     Assert.Pass("OK for Zero Values test");
 }
Exemplo n.º 7
0
 public void Should_GetSpentPerHour_Return_Value_If_Consumables_Is_Pascal_Case_And_Singular()
 {
     Assert.IsTrue(StarshipBusiness.GetSpentPerHour("1 Hour") > 0);
     Assert.IsTrue(StarshipBusiness.GetSpentPerHour("1 Day") > 0);
     Assert.IsTrue(StarshipBusiness.GetSpentPerHour("1 Week") > 0);
     Assert.IsTrue(StarshipBusiness.GetSpentPerHour("1 Month") > 0);
     Assert.IsTrue(StarshipBusiness.GetSpentPerHour("1 Year") > 0);
     Assert.Pass("OK for PascalCase and Singular test");
 }
Exemplo n.º 8
0
 public void Should_GetSpentPerHour_Return_Value_If_Consumables_Per_Year_IsPuzzledCase_and_Plural()
 {
     Assert.IsTrue(StarshipBusiness.GetSpentPerHour("2 hoUrs") > 0);
     Assert.IsTrue(StarshipBusiness.GetSpentPerHour("2 DayS") > 0);
     Assert.IsTrue(StarshipBusiness.GetSpentPerHour("2 weeKs") > 0);
     Assert.IsTrue(StarshipBusiness.GetSpentPerHour("5 mOnths") > 0);
     Assert.IsTrue(StarshipBusiness.GetSpentPerHour("8 YeArs") > 0);
     Assert.Pass("OK GetSpentPerHour for PascalCase and Plural test");
 }
Exemplo n.º 9
0
        public void Should_GetSpentPerHour_Return_Same_Value_For_Different_Time_Unit()
        {
            var hours = StarshipBusiness.GetSpentPerHour("8760 hours");
            var day   = StarshipBusiness.GetSpentPerHour("365 days");
            var year  = StarshipBusiness.GetSpentPerHour("1 year");

            Assert.IsTrue(hours == day && hours == year && day == year);

            Assert.Pass("OK GetSpentPerHour for return same value for different time unit test");
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            InitConfiguration();
            Console.WriteLine("Insert the distance: ");
            var distance         = Convert.ToInt64(Console.ReadLine());
            var apiUrl           = Starship.Configuration["ApiUrl"];
            var starshipBusiness = new StarshipBusiness();

            starshipBusiness.CalculateStarshipsStops(apiUrl, distance);
            Console.ReadLine();
        }
Exemplo n.º 11
0
        public void Should_GetStarshipStops_Ywing_Stops_74_Times()
        {
            System.Collections.Generic.List <Models.StarshipModel> returnValue = StarshipBusiness.GetStarshipStops(1000000);
            Assert.IsNotNull(returnValue);

            Models.StarshipModel ywing = returnValue.FirstOrDefault(x => x.name.ToLower() == "y-wing");

            Assert.IsNotNull(ywing);
            Assert.AreEqual(ywing.stops, 74);
            Assert.Pass("OK for GetStarshipStops Y-wing stops 74 times test");
        }
Exemplo n.º 12
0
        public void Should_GetStarshipStop_Rebel_Transport_Stops_11_Times()
        {
            System.Collections.Generic.List <Models.StarshipModel> returnValue = StarshipBusiness.GetStarshipStops(1000000);
            Assert.IsNotNull(returnValue);

            Models.StarshipModel ywing = returnValue.FirstOrDefault(x => x.name.ToLower() == "rebel transport");

            Assert.IsNotNull(ywing);
            Assert.AreEqual(ywing.stops, 11);
            Assert.Pass("OK for GetStarshipStops Rebel Transport stops 11 times test");
        }
Exemplo n.º 13
0
        public void Should_GetStarshipStops_Millennium_Falcon_Stops_9_Times()
        {
            System.Collections.Generic.List <Models.StarshipModel> returnValue = StarshipBusiness.GetStarshipStops(1000000);
            Assert.IsNotNull(returnValue);

            Models.StarshipModel ywing = returnValue.FirstOrDefault(x => x.name.ToLower() == "millennium falcon");

            Assert.IsNotNull(ywing);
            Assert.AreEqual(ywing.stops, 9);
            Assert.Pass("OK for GetStarshipStops Millennium Falcon stops 9 times test");
        }
Exemplo n.º 14
0
        public void Should_GetSpentPerHour_Return_Default_Value_If_Consumables_Is_Negative()
        {
            Assert.AreEqual(StarshipBusiness.GetSpentPerHour("-1 hours"), 0);
            Assert.AreEqual(StarshipBusiness.GetSpentPerHour("-1 days"), 0);
            Assert.AreEqual(StarshipBusiness.GetSpentPerHour("-1 weeks"), 0);
            Assert.AreEqual(StarshipBusiness.GetSpentPerHour("-1 months"), 0);
            Assert.AreEqual(StarshipBusiness.GetSpentPerHour("-1 years"), 0);

            Assert.AreEqual(StarshipBusiness.GetSpentPerHour("-1 hour"), 0);
            Assert.AreEqual(StarshipBusiness.GetSpentPerHour("-1 day"), 0);
            Assert.AreEqual(StarshipBusiness.GetSpentPerHour("-1 week"), 0);
            Assert.AreEqual(StarshipBusiness.GetSpentPerHour("-1 month"), 0);
            Assert.AreEqual(StarshipBusiness.GetSpentPerHour("-1 year"), 0);
            Assert.Pass("OK for Negative Values test");
        }
Exemplo n.º 15
0
 public void Should_GetSpentPerHour_ReturnDefault_Value_If_Consumables_Is_Empty()
 {
     Assert.AreEqual(StarshipBusiness.GetSpentPerHour(string.Empty), 0);
     Assert.Pass("OK for Empty Values test");
 }
Exemplo n.º 16
0
 public void Should_GetSpentPerHour_Return_Default_Value_If_Consumables_Is_Null()
 {
     Assert.AreEqual(StarshipBusiness.GetSpentPerHour(null), 0);
     Assert.Pass("OK for Null Values test");
 }
Exemplo n.º 17
0
 public void Should_GetSpentPerHour_Return_Default_Value_If_Consumables_Has_Invalid_Values()
 {
     Assert.AreEqual(StarshipBusiness.GetSpentPerHour("invalid invalid"), 0);
     Assert.Pass("OK for Invalid Values test");
 }