public void Play(string[] initialColors) { var thereIsNoWinner = true; while (thereIsNoWinner) { var userColors = _userColorsProvider.ProvideColors(); var hintsProvider = new HintsProvider(); var hints = hintsProvider.GiveHints(userColors, initialColors); _counter++; foreach (var hint in hints) { _communicationOperations.WriteLine(hint); } if (_counter == MaxTries) { _communicationOperations.WriteLine("You lost. Only 60 attempts allowed."); break; } if (hints.Count == 4) { _communicationOperations.WriteLine("You won! Congratulations :)"); thereIsNoWinner = false; } } }
public void User_Provides_5_Colors_And_Is_Asked_To_Provide_New_Colors() { //arrange var consoleOperations = new Mock <ICommunicationOperations>(); var validations = new List <IValidation> { new CorrectColorValidator(), new CorrectColorCountValidator(), new IsNotNullValidator() }; var validator = new UserColorsProvider(validations, consoleOperations.Object); consoleOperations.SetupSequence(s => s.Read()).Returns("Green, Red, Blue, Orange, Purple").Returns(" Red, Blue, Orange, Red"); //act var colors = validator.ProvideColors(); var expectedColors = new [] { "Red", "Blue", "Orange", "Red" }; //assert consoleOperations.Verify( m => m.WriteLine((It.Is <string>(c => c == "Type 4 colors from this range: Red, Blue, Green, Orange, Purple, Yellow, separated with a coma: ','")))); Assert.AreEqual(expectedColors, colors); }
public void User_Provides_Colors_With_Extra_Space_GetValidUserInput_Returns_Chosen_Colors() { //arrange var consoleOperations = new Mock <ICommunicationOperations>(); var validations = new List <IValidation> { new CorrectColorValidator(), new CorrectColorCountValidator(), new IsNotNullValidator() }; var validator = new UserColorsProvider(validations, consoleOperations.Object); consoleOperations.SetupSequence(s => s.Read()).Returns("Green ,Red ,Blue , Orange"); //act var colors = validator.ProvideColors(); var expectedColors = new [] { "Green", "Red", "Blue", "Orange" }; //assert Assert.AreEqual(expectedColors, colors); }
public void User_Provides_Colors_Using_Capital_Letters_Randomly_GetValidUserInput_Returns_Chosen_Colors_Array() { //arrange var consoleOperations = new Mock <ICommunicationOperations>(); var validations = new List <IValidation> { new CorrectColorValidator(), new CorrectColorCountValidator(), new IsNotNullValidator() }; var validator = new UserColorsProvider(validations, consoleOperations.Object); consoleOperations.SetupSequence(s => s.Read()).Returns("GrEEn, REd, blue, bluE"); //act var colors = validator.ProvideColors(); var expectedColors = new [] { "Green", "Red", "Blue", "Blue" }; //assert Assert.AreEqual(expectedColors, colors); }