Exemplo n.º 1
0
        public void ParseInstructions_GivenASequenceOfInstructions_ParsesEachInstructionInSequence()
        {
            // arrange
            string instructions = "llmmmrmm";
            var    robot        = new Mock <IRobot>();

            robot
            .Setup(r => r.CommandLeft())
            .Verifiable();
            robot
            .Setup(r => r.CommandRight())
            .Verifiable();
            robot
            .Setup(r => r.CommandMove())
            .Verifiable();
            var commandMarshaller = new RobotCommandMarshaller(robot.Object);

            // act
            commandMarshaller.ExecuteInstructions(instructions);

            // assert
            robot.Verify(r => r.CommandLeft(), Times.Exactly(2));
            robot.Verify(r => r.CommandRight(), Times.Exactly(1));
            robot.Verify(r => r.CommandMove(), Times.Exactly(5));
        }
Exemplo n.º 2
0
        public void InvalidCommand_ThrowsException(string invalidInstruction)
        {
            // arrange
            var commandMarshaller = new RobotCommandMarshaller(new Mock <IRobot>().Object);

            // act
            commandMarshaller.ExecuteInstructions(invalidInstruction);
        }
Exemplo n.º 3
0
        public void ExecuteInstructions_RobotEndsUpWhereItShould(string instructions,
                                                                 int expectedX, int expectedY, OrientationEnum expectedOrientation)
        {
            // arrange
            IGrid grid = new Grid(10, 10);
            IRobotCommandMarshaller commandMarshaller = new RobotCommandMarshaller();
            IRobot robot = new Robot(0, 0, OrientationEnum.North, grid, commandMarshaller);

            // act
            robot.ExecuteInstructions(instructions);

            // assert
            Assert.That(robot.X, Is.EqualTo(expectedX));
            Assert.That(robot.Y, Is.EqualTo(expectedY));
            Assert.That(robot.Orientation, Is.EqualTo(expectedOrientation));
        }
Exemplo n.º 4
0
        public void ParseInstructionMove_InvokesCommandMove()
        {
            // arrange
            string        instructions = "M";
            Mock <IRobot> robot        = new Mock <IRobot>();

            robot
            .Setup(r => r.CommandMove())
            .Verifiable();
            IRobotCommandMarshaller commandMarshaller = new RobotCommandMarshaller(robot.Object);

            // act
            commandMarshaller.ExecuteInstructions(instructions);

            // assert
            robot.Verify(r => r.CommandMove(), Times.Once());
        }