public void RoboHelper_IsCordinateValid_Should_Throw_Correct_Exeption(string command, string exceptionMessage, int height, int width) { var commandSegments = RoboHelper.GetCommandSegments(command); var moveAreaMock = new Mock <IMoveArea <int> >(); moveAreaMock.SetupGet(s => s.Width).Returns(width); moveAreaMock.SetupGet(s => s.Height).Returns(height); Action act = () => RoboHelper.IsCordinateValid <int>(commandSegments, moveAreaMock.Object); act.Should().Throw <ArgumentException>().WithMessage(exceptionMessage); }
private void ProcessInitialPlacement(string command) { var commandSegments = RoboHelper.GetCommandSegments(command); //this will throw exception if the commads are invalid //This is done this way so that the detail error messages are captured for ease of user RoboHelper.IsCommandLineArgumentsValid(commandSegments); //Check if the original cordinate is valid RoboHelper.IsCordinateValid <T>(commandSegments, MoveArea); //set the initial position Position = new Cordinate <T> { X = (T)Convert.ChangeType(commandSegments.X, typeof(T)), Y = (T)Convert.ChangeType(commandSegments.Y, typeof(T)) }; //set the initial direction Direction = DirectionFactory <T, U> .Create(commandSegments.Direction); }
public string ProcessAction(string command) { var commandSegments = RoboHelper.GetCommandSegments(command); //check if (commandSegments != null) { //this will throw exception if the commads are invalid //This is done this way so that the detail error messages are captured for ease of user RoboHelper.IsCommandLineArgumentsValid(commandSegments); //Check if the original cordinate is valid RoboHelper.IsCordinateValid <T>(commandSegments, MoveArea); //set the new position Position = new Cordinate <T> { X = (T)Convert.ChangeType(commandSegments.X, typeof(T)), Y = (T)Convert.ChangeType(commandSegments.Y, typeof(T)) }; //set the new direction Direction = DirectionFactory <T, U> .Create(commandSegments.Direction); } else { if (RoboHelper.IsValidReportAction(command)) { return(new Report <T, U>().GetOutput(Position, Direction)); } if (RoboHelper.IsPlaceExist(new string[] { command })) { throw new ArgumentException($"PLACE command missing arguments"); } if (!RoboHelper.IsValidMoveAction(command)) { throw new ArgumentException($"Invalid command line arguments"); } if (Direction == null) { throw new InvalidOperationException("Robo unable to perform this command without initial direction"); } if (Position == null) { throw new InvalidOperationException("Robo unable to perform this command without initial position"); } //create the action var action = ActionFactory <T, U> .Create(command); //get the new direction Direction = Direction.NextFacing(action); //calculate the new position Position = action.ComputeNewCordinate(Position, Step, MoveArea, Direction); } return(string.Empty); }