When_User_Guesses_3_Colors_In_Different_Position_And_1_In_Correct_Position_3_Hints_Saying_White__And_One_Black_Is_Displayed() { //arrange var consoleOperations = new Mock <ICommunicationOperations>(); var initialColors = new[] { "Green", "Red", "Blue", "Orange" }; var validations = new List <IValidation> { new IsNotNullValidator(), new CorrectColorValidator(), new CorrectColorCountValidator() }; var userColorsProvider = new UserColorsProvider(validations, consoleOperations.Object); var game = new Game(consoleOperations.Object, userColorsProvider); consoleOperations.SetupSequence(s => s.Read()).Returns("Blue, Red, Orange, Green") .Returns("Green, Red, Blue, Orange"); //act game.Play(initialColors); //assert consoleOperations.Verify( m => m.WriteLine((It.Is <string>(c => c == "Black")))); consoleOperations.Verify( m => m.WriteLine((It.Is <string>(c => c == "Black")))); consoleOperations.Verify( m => m.WriteLine((It.Is <string>(c => c == "Black")))); consoleOperations.Verify( m => m.WriteLine((It.Is <string>(c => c == "White")))); }
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 When_User_Guesses_All_Colors_Game_Stops_And_Win_Message_Is_Displayed() { //arrange var consoleOperations = new Mock <ICommunicationOperations>(); var initialColors = new[] { "Green", "Red", "Blue", "Orange" }; var validations = new List <IValidation> { new IsNotNullValidator(), new CorrectColorValidator(), new CorrectColorCountValidator() }; var userColorsProvider = new UserColorsProvider(validations, consoleOperations.Object); var game = new Game(consoleOperations.Object, userColorsProvider); consoleOperations.SetupSequence(s => s.Read()).Returns("Green, Red, Blue, Orange"); //act game.Play(initialColors); //assert consoleOperations.Verify( m => m.WriteLine((It.Is <string>(c => c == "You won! Congratulations :)")))); }
The_Game_Ends_after_60_tries() { //arrange var consoleOperations = new Mock <ICommunicationOperations>(); var initialColors = new[] { "Green", "Red", "Blue", "Orange" }; var validations = new List <IValidation> { new IsNotNullValidator(), new CorrectColorValidator(), new CorrectColorCountValidator() }; var userColorsProvider = new UserColorsProvider(validations, consoleOperations.Object); var game = new Game(consoleOperations.Object, userColorsProvider); //act for (int i = 0; i < 61; i++) { consoleOperations.SetupSequence(s => s.Read()).Returns("Blue, Red, Orange, Green") .Returns("Green, Red, Blue, Orange"); game.Play(initialColors); } //assert consoleOperations.Verify( m => m.WriteLine((It.Is <string>(c => c == "You lost. Only 60 attempts allowed.")))); }
static void Main(string[] args) { var communication = new ConsoleOperations(); var validations = new List <IValidation> { new IsNotNullValidator(), new CorrectColorValidator(), new CorrectColorCountValidator() }; var userColorProvider = new UserColorsProvider(validations, communication); var initialColorsProvider = new InitialColorsProvider(new RandomNumberGenerator()); var initialColors = initialColorsProvider.ProvideColors(); var game = new Game(communication, userColorProvider); game.Play(initialColors); }
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); }
public Game(ICommunicationOperations communicationOperations, UserColorsProvider userColorsProvider) { _communicationOperations = communicationOperations; _userColorsProvider = userColorsProvider; }