Ejemplo n.º 1
0
        public void It_Should_ReturnAnEnum_When_GiveAValidString()
        {
            //arrange
            var consoleInputProcessor = new ConsoleInputProcessor();
            var input = "TwoPairs";

            //act
            var scoreCategory = consoleInputProcessor.ConvertToScoreCategory(input, new ScoreCategoryInputValidator());

            //assert
            Assert.Equal(ScoreCategory.TwoPairs, scoreCategory);
        }
Ejemplo n.º 2
0
        public void It_Should_Return_ZeroValuesToHold_When_GiveAnEmptyString()
        {
            //arrange
            var consoleInputProcessor = new ConsoleInputProcessor();
            var input = "";

            //act
            var diceValuesToHold = consoleInputProcessor.ConvertToDiceValues(input, new DiceValuesToHoldValidator());

            //assert
            Assert.Empty(diceValuesToHold);
        }
Ejemplo n.º 3
0
        public void It_Should_Throw_InvalidValueToHoldException_When_GiveAnStringWithValidAndInvalidValues()
        {
            //arrange
            var consoleInputProcessor = new ConsoleInputProcessor();
            var input = "2, 3, 4, 65";

            //act
            Action actual = () => consoleInputProcessor.ConvertToDiceValues(input, new DiceValuesToHoldValidator());

            //assert
            var exception = Assert.Throws <InvalidValuesToHoldException>(actual);

            Assert.Equal("One or more invalid dice values: 2, 3, 4, 65", exception.Message);
        }
Ejemplo n.º 4
0
        public void It_Should_ReturnCorrectDiceValuesToHold_When_GiveAValidString()
        {
            //arrange
            var consoleInputProcessor = new ConsoleInputProcessor();
            var input = "2, 6";

            //act
            var diceValuesToHold = consoleInputProcessor.ConvertToDiceValues(input, new DiceValuesToHoldValidator());

            //assert
            Assert.True(diceValuesToHold.SequenceEqual(new List <int> {
                2, 6
            }));
        }
Ejemplo n.º 5
0
        public void It_Should_Throw_InvalidScoreCategoryException_GiveAnInvalidString()
        {
            //arrange
            var consoleInputProcessor = new ConsoleInputProcessor();
            var input = "Monopoly";

            //act
            Action actual = () => consoleInputProcessor.ConvertToScoreCategory(input, new ScoreCategoryInputValidator());

            //assert
            var exception = Assert.Throws <InvalidScoreCategoryException>(actual);

            Assert.Equal("Monopoly is not a valid score category", exception.Message);
        }
        public void It_Should_Throw_An_InvalidInputException_When_Given_InvalidInput(string input, string errorMessage)
        {
            //arrange
            var config = new MastermindConfig
            {
                [DataConstants.CodeLength] = 4, [DataConstants.NumberOfColours] = 6, [DataConstants.NumberOfTurns] = 8
            };
            var consoleInputProcessor = new ConsoleInputProcessor(config);

            //act
            Action actual = () => consoleInputProcessor.Process(input);


            //assert
            var exception = Assert.Throws <InvalidInputException>(actual);

            Assert.Equal(errorMessage, exception.Message);
        }
        public void It_Should_Process_Input_When_Given_ValidInput()
        {
            //arrange
            var config = new MastermindConfig
            {
                [DataConstants.CodeLength] = 4, [DataConstants.NumberOfColours] = 6, [DataConstants.NumberOfTurns] = 8
            };

            var consoleInputProcessor = new ConsoleInputProcessor(config);

            //act
            var input = "Blue, Red, Green, Red";
            var guess = consoleInputProcessor.Process(input);

            //assert
            var expectedGuess = new List <Peg> {
                Peg.Blue, Peg.Red, Peg.Green, Peg.Red
            };

            Assert.Equal(expectedGuess, guess);
        }