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 void ShouldCallValid() { var validator = Substitute.For <IValidator>(); validator.Validate(Arg.Any <string>()).Returns(true); var consoleRender = Substitute.For <IScreenManager>(); var inputObservable = Substitute.For <IInputObservable>(); ConsoleKeyInfo[] keys = ckiFactory.GetMultipleLetters("AB"); inputObservable.TakeUntilEnter().Returns(keys.ToObservable()); consoleRender.GetInputObservable().Returns(inputObservable); var input = new PasswordInput("Name", "Message", consoleRender); input.SetValid(validator); input.Ask(); validator.Received().Validate("AB"); }
public void ConsoleOutputShouldBeOnlyAsterisk() { using var consoleOutput = new StringWriter(); var oldOutput = Console.Out; Console.SetOut(consoleOutput); var consoleRender = Substitute.For <IScreenManager>(); var inputObservable = Substitute.For <IInputObservable>(); ConsoleKeyInfo[] keys = ckiFactory.GetMultipleLetters("AB"); inputObservable.TakeUntilEnter().Returns(keys.ToObservable()); consoleRender.GetInputObservable().Returns(inputObservable); var input = new PasswordInput("Name", "Message", consoleRender); input.Ask(); consoleOutput.ToString().Should().Be("**"); Console.SetOut(oldOutput); }
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"); }
public void ShouldCallClean_WhenAnswerIsWrong() { 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"); inputObservable.TakeUntilEnter().Returns(keys.ToObservable(), ckiFactory.GetMultipleLetters("B").ToObservable()); consoleRender.GetInputObservable().Returns(inputObservable); consoleRender.Render(Arg.Is <string[]>( m => m.SequenceEqual(new[] { "Message" })), Arg.Any <string[]>()) .Returns(new[] { 3, 0 }); var input = new PasswordInput("Name", "Message", consoleRender); input.SetValid(validator); input.Ask(); consoleRender.Received().Clean(0, 3); }