private void SetRoverCommand(List <ICommand> commands, int index, char rotationCharacter) { switch (rotationCharacter) { case 'L': { ICommand rotatorCommand = new RoverRotatorCommand(Rotation.Left); commands.Add(rotatorCommand); break; } case 'R': { ICommand rotatorCommand = new RoverRotatorCommand(Rotation.Right); commands.Add(rotatorCommand); break; } case 'M': { ICommand moveRoverCommand = new MoveRoverCommand(); commands.Add(moveRoverCommand); break; } default: throw new ArgumentException("input", $"Rover rotation/move line should have either L, R, or M characters on line {index}."); } }
public void Test_Error_Result_When_Rover_Move(Point inPosition, Size Plateau, string inDirection, string inMovementList) { DefineRoverCommand defineRoverCommand = new DefineRoverCommand(inPosition, Plateau, inDirection); MoveRoverCommand moveRoverCommand = new MoveRoverCommand(inMovementList); _commandDispatcher.Handle(defineRoverCommand); Assert.Throws <PlateauException>(() => _commandDispatcher.Handle(moveRoverCommand)); }
static void RoverRunSecond(ICommandDispatcher commandDispatcher, IQueryDispatcher queryDispatcher) { DefineRoverCommand defineRoverCommand = new DefineRoverCommand(new Point(3, 3), new Size(5, 5), "E"); commandDispatcher.Handle(defineRoverCommand); MoveRoverCommand moveRoverCommand = new MoveRoverCommand("MMRMMRMRRM"); commandDispatcher.Handle(moveRoverCommand); LocationInfoQuery locationInfoQuery = new LocationInfoQuery(); string locationInfo = queryDispatcher.Handle <LocationInfoQuery, string>(locationInfoQuery); Console.WriteLine(locationInfo); }
public void Test_Acceptance_Result_When_Rover_Move(Point inPosition, Size Plateau, string inDirection, string inMovementList, Point outPoint, Direction outDirection) { DefineRoverCommand defineRoverCommand = new DefineRoverCommand(inPosition, Plateau, inDirection); _commandDispatcher.Handle(defineRoverCommand); MoveRoverCommand moveRoverCommand = new MoveRoverCommand(inMovementList); _commandDispatcher.Handle(moveRoverCommand); LocationInfoQuery locationInfoQuery = new LocationInfoQuery(); string locationInfo = _queryDispatcher.Handle <LocationInfoQuery, string>(locationInfoQuery); string outputInfo = outPoint.X + " " + outPoint.Y + " " + outDirection.ToString("G"); Assert.Equal(outputInfo, locationInfo); }
public async Task Should_move_rover_to_the_expected_position(int expectedX, int expectedY, params MovementType[] movements) { var rover = new Rover(FacingDirection.N, new Position(0, 0)); var expectedPosition = new Position(expectedX, expectedY); var command = new MoveRoverCommand { Rover = rover, Movements = new List <MovementType>(movements), Plateau = new Plateau(5, 5) }; var commandHandler = new MoveRoverCommandHandler(); await commandHandler.Handle(command, CancellationToken.None); rover.Position.Should().Be(expectedPosition); }
[InlineData(MovementType.Right, MovementType.Forward, MovementType.Forward, MovementType.Right, MovementType.Forward)] //off-grid (2, -1) public async Task Should_stop_moving_if_the_next_movement_is_off_grid(params MovementType[] movements) { var rover = new Rover(FacingDirection.N, new Position(0, 0)); var command = new MoveRoverCommand { Rover = rover, Movements = new List <MovementType>(movements), Plateau = new Plateau(2, 2) }; var commandHandler = new MoveRoverCommandHandler(); Func <Task> commandAct = async() => { await commandHandler.Handle(command, CancellationToken.None); }; await commandAct.Should().ThrowAsync <OffGridMovementException>(); }