public static void Run() { var emailInput = new Input("name", "What is your email?"); var passwordInput = new PasswordInput("password", "What is the password?"); var inquirer = new Inquirer(emailInput, passwordInput); inquirer.Ask(); System.Console.WriteLine($@"Your email is {emailInput.Answer()}!"); System.Console.WriteLine($@"Secret password: {passwordInput.Answer()}!"); System.Console.ReadKey(); }
public void AnswerShouldContainUserInput() { var consoleRender = Substitute.For <IScreenManager>(); var inputObservable = Substitute.For <IInputObservable>(); var userInput = ckiFactory.GetMultipleLetters("AB").ToObservable(); inputObservable.TakeUntilEnter().Returns(userInput); consoleRender.GetInputObservable().Returns(inputObservable); var input = new PasswordInput("Name", "Message", consoleRender); input.Ask(); input.Answer().Should().Be("AB"); }
public static void Run() { var numbersOnly = new RegexValidator("^[0-9]*$"); var nameInput = new Input("name", "What is your name?"); var ageInput = new Input("age", "What is your age?"); ageInput.SetValid(numbersOnly); var passwordInput = new PasswordInput("password", "What is the password?"); var inquirer = new Inquirer(nameInput, ageInput, passwordInput); inquirer.Ask(); System.Console.WriteLine($@"Hello {nameInput.Answer()}! Your age is {ageInput.Answer()}"); System.Console.WriteLine($@"Secret password: {passwordInput.Answer()}!"); System.Console.ReadKey(); }
public void AnswerShouldContainsOnlyValidOne() { var validator = Substitute.For <IValidator>(); validator.Validate("A").Returns(false); validator.Validate("B").Returns(true); var consoleRender = Substitute.For <IScreenManager>(); var inputObservable = Substitute.For <IInputObservable>(); ConsoleKeyInfo[] keys = ckiFactory.GetMultipleLetters("A"); consoleRender.Render(Arg.Any <string[]>(), Arg.Any <string[]>()).Returns(new int[2]); inputObservable.TakeUntilEnter().Returns(keys.ToObservable(), ckiFactory.GetMultipleLetters("B").ToObservable()); consoleRender.GetInputObservable().Returns(inputObservable); var input = new PasswordInput("Name", "Message", consoleRender); input.SetValid(validator); input.Ask(); input.Answer().Should().Be("B"); }