static void Main(string[] args) { string baseString; IntMaker intMaker = new IntMaker(); do { Console.Write("Enter a number (or enter \"exit\" to finish the program): "); baseString = Console.ReadLine(); if (baseString == "exit") { break; } try { Console.WriteLine($"Your number is: {intMaker.ConvertToInt(baseString)}"); } catch (EmptyStringException ex) { Console.WriteLine($"Error: {ex.Message}"); } catch (IncorrectFormatException ex) { Console.WriteLine($"Error: {ex.Message}"); } catch (OverflowException) { Console.WriteLine($"Error: Your number is too big, it must be between -2 147 483 648 and 2 147 483 647"); } } while (true); }
public void ConvertToInt_LessThanMinimumIn_OverflowExceptionOut() { //Arrange string sample = "-2147483650"; //Act IntMaker intMaker = new IntMaker(); //Assert Assert.ThrowsException <System.OverflowException>(() => intMaker.ConvertToInt(sample)); }
public void ConvertToInt_EmptyStringIn_EmptyStringExceptionOut() { //Arrange string sample = string.Empty; //Act IntMaker intMaker = new IntMaker(); //Assert Assert.ThrowsException <EmptyStringException>(() => intMaker.ConvertToInt(sample)); }
public void ConvertToInt_NotNumberIn_IncorrectFormatExceptionOut() { //Arrange string sample = "abcde"; //Act IntMaker intMaker = new IntMaker(); //Assert Assert.ThrowsException <IncorrectFormatException>(() => intMaker.ConvertToInt(sample)); }
public void ConvertToInt_12345AsString_12345AsNumber() { //Arrange string sample = "12345"; int expected = 12345; //Act IntMaker intMaker = new IntMaker(); int actual = intMaker.ConvertToInt(sample); //Assert Assert.AreEqual(expected, actual); }
public void ConvertToInt_MaximumIn_MaximumOut() { //Arrange string sample = "2147483647"; int expected = 2147483647; //Act IntMaker intMaker = new IntMaker(); int actual = intMaker.ConvertToInt(sample); //Assert Assert.AreEqual(expected, actual); }
public void ConvertToInt_NegativeIn_NegativeOut() { //Arrange string sample = "-15"; int expected = -15; //Act IntMaker intMaker = new IntMaker(); int actual = intMaker.ConvertToInt(sample); //Assert Assert.AreEqual(expected, actual); }
public void ConvertToInt_ZeroIn_ZeroOut() { //Arrange string sample = "0"; int expected = 0; //Act IntMaker intMaker = new IntMaker(); int actual = intMaker.ConvertToInt(sample); //Assert Assert.AreEqual(expected, actual); }