コード例 #1
0
        public void InvalidCommand_ThrowsException(string invalidInstruction)
        {
            // arrange
            var commandMarshaller = new RobotCommandMarshaller(new Mock<IRobot>().Object);

            // act
            commandMarshaller.ExecuteInstructions(invalidInstruction);
        }
コード例 #2
0
        public void ParseInstructionRight_InvokesCommandRight()
        {
            // arrange
            string instructions = "R";
            Mock<IRobot> robot = new Mock<IRobot>();
            robot
                .Setup(r => r.CommandRight())
                .Verifiable();
            IRobotCommandMarshaller commandMarshaller = new RobotCommandMarshaller(robot.Object);

            // act
            commandMarshaller.ExecuteInstructions(instructions);

            // assert
            robot.Verify(r => r.CommandRight(), Times.Once());
        }
コード例 #3
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));
        }