public void InvalidCommand_ThrowsException(string invalidInstruction) { // arrange var commandMarshaller = new RobotCommandMarshaller(new Mock<IRobot>().Object); // act commandMarshaller.ExecuteInstructions(invalidInstruction); }
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()); }
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)); }
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)); }