static void Main(string[] args) { try { Console.WriteLine("\nWelcome!"); Console.WriteLine("The purpose of this application is to calculate the amount of stops to resupply"); Console.WriteLine("all starships needs to travel some distance in mega lights."); do { Console.WriteLine("\nPlease, type the distance in mega lights!"); double distanceInMGLT = CalculateMGLT.ValidMGLTInput(Console.ReadLine()); Console.WriteLine("\nGood Job! Now I'll get all the starships available..."); Console.WriteLine("=================================================================\n"); System.Threading.Thread.Sleep(1000); List <StarshipModel> starships = Starship.GetStarshipsAsync(); int Id = 1; System.Threading.Thread.Sleep(3000); Console.WriteLine("\n{0,5} | {1,-30}| {2,1}", "Id", "Name", "Amount of Stops"); starships.ForEach((starship) => { if (starship.Consumables != "unknown" && starship.MGLT != "unknown") { if (CalculateMGLT.ValidateConsumable(starship.Consumables)) { starship.ConsumablesInHours = CalculateMGLT.ConsumablesToHours(starship.Consumables); starship.AmountOfStops = CalculateMGLT.CalculateAmountOfStops( distanceInMGLT, Convert.ToInt32(starship.MGLT), starship.ConsumablesInHours); } } System.Threading.Thread.Sleep(300); Console.WriteLine("{0, 5} | {1,-30}| {2,1}", Id++, starship.Name, starship.AmountOfStops != null ? starship.AmountOfStops.ToString() : "unknown"); }); Console.WriteLine("\nThat's all! If you'd like to exit the application, press ESC, or press another key to try again!"); Console.WriteLine("=================================================================\n"); } while (Console.ReadKey(true).Key != ConsoleKey.Escape); Console.WriteLine("\nThanks!"); Console.WriteLine("Closing the application..."); System.Threading.Thread.Sleep(2000); Environment.Exit(0); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine("=================================================================\n"); if (ex is InputNegativeValueException || ex is InputNotANumberException) { Console.WriteLine("Try again!"); System.Threading.Thread.Sleep(2000); Console.Clear(); Main(args); } } }
public void ConsumableNotNumberFirstTest_ShouldThrowConsumableFirstValueNotANumberException() { Assert.Throws <CustomExceptions.ConsumableFirstValueNotANumberException>(() => CalculateMGLT.ValidateConsumable("week 1")); }
public void ConsumableSecondValueNotValidTest_ShouldThrowConsumableSecondValueNotRecognizedException() { Assert.Throws <CustomExceptions.ConsumableSecondValueNotRecognizedException>(() => CalculateMGLT.ValidateConsumable("50 megatons")); }
public void ConsumableWrongFormatTest_ShouldThrowConsumableWrongFormatException() { Assert.Throws <CustomExceptions.ConsumableWrongFormatException>(() => CalculateMGLT.ValidateConsumable("1 test wrong")); }
[InlineData("6 months", 4320)] //Rebel transport public void ConvertConsumablesToHoursTest(string consumables, int?expectedResult) { int?hours = CalculateMGLT.ConsumablesToHours(consumables); Assert.Equal(expectedResult, hours); }
[InlineData(1000000, "50", 1440, 13)] //Imperial shuttle public void CalculateAmountofStopsTest(double distance, string MGLT, int hours, int expectedResult) { double amountOfStops = CalculateMGLT.CalculateAmountOfStops(distance, Convert.ToInt32(MGLT), hours); Assert.Equal(expectedResult, amountOfStops); }
public void InputNegativeTest_ShouldThroewInputNotANumberException() { Assert.Throws <CustomExceptions.InputNotANumberException>(() => CalculateMGLT.ValidMGLTInput("abcd")); }
public void InputNegativeTest_ShouldThrowInputNegativeValueException() { Assert.Throws <CustomExceptions.InputNegativeValueException>(() => CalculateMGLT.ValidMGLTInput("-10")); }