public virtual int GetInput() { int numberOfSticks = 0; bool isInt = int.TryParse(_console.ReadLine(), out numberOfSticks); bool validNumber = numberOfSticks < 4 && numberOfSticks > 0; while (!(isInt && validNumber)) { _console.WriteLine("Please enter a valid number of sticks:"); isInt = int.TryParse(_console.ReadLine(), out numberOfSticks); validNumber = numberOfSticks < 4 && numberOfSticks > 0; } return(numberOfSticks); }
public void ConsoleWrapperShouldReadInput() { using (StringReader sr = new StringReader("1")) { Console.SetIn(sr); string actual = sut.ReadLine(); string expected = string.Format("1"); Assert.Equal(expected, actual); } }