Esempio n. 1
0
        public ServiceResult <Plateau> SendCommandArrayToRover(Rover rover, string command)
        {
            ServiceResult <Plateau> result = new ServiceResult <Plateau>();

            try {
                if (rover == null)
                {
                    result.ErrorMessage = $"Rover not found.";
                    result.ResultStatus = ServiceResultStatus.NotValid;
                    logger.ErrorLog(new NullReferenceException(result.ErrorMessage), result.ErrorMessage);
                }
                else if (String.IsNullOrWhiteSpace(command))
                {
                    result.ErrorMessage = $"Command is null or Empty";
                    result.ResultStatus = ServiceResultStatus.NotValid;
                    logger.ErrorLog(new NullReferenceException(result.ErrorMessage), result.ErrorMessage);
                }
                else
                {
                    Plateau plateau = roverOperations.ExecuteBatchCommand(rover, command);
                    result.Response = plateau;
                }
            }
            catch (Exception ex) {
                result.ResultStatus = ServiceResultStatus.Failed;
                result.ErrorMessage = $"SendCommandArrayToRover function error: Please check your input. Rover Code:{rover.RoverCode} Command:{command}";
                logger.ErrorLog(ex, result.ErrorMessage);
            }
            return(result);
        }
Esempio n. 2
0
        public void ExecuteBatchCommandSuccessTest(int plateauUpperRightX, int plateauUpperRightY, int roverX, int roverY, char roverD, string command, int expectedRoverX, int expectedRoverY, int expectedRoverD)
        {
            Plateau plateau = new Plateau(new Coordinate(plateauUpperRightX, plateauUpperRightY));

            Assert.IsNotNull(plateau);
            Assert.IsNotNull(plateau.Rovers);
            Coordinate coordinate = new Coordinate(roverX, roverY);
            Direction  direction  = DirectionCreator.Create(roverD);

            plateau = plateauOperations.AddNewRover(plateau, coordinate, direction);
            Assert.IsNotNull(plateau);
            Assert.IsNotNull(plateau.SelectedRover);
            Assert.IsNotNull(plateau.SelectedRover.CurrentCoordinate);
            Assert.IsTrue(plateau.SelectedRover.CurrentCoordinate.X >= plateau.MinX && plateau.SelectedRover.CurrentCoordinate.X <= plateau.MaxX);
            Assert.IsTrue(plateau.SelectedRover.CurrentCoordinate.Y >= plateau.MinY && plateau.SelectedRover.CurrentCoordinate.Y <= plateau.MaxY);
            Assert.AreSame(plateau.SelectedRover.CurrentCoordinate, coordinate);
            plateau = roverOperations.ExecuteBatchCommand(plateau.SelectedRover, command);
            Assert.AreEqual(plateau.SelectedRover.CurrentCoordinate.X, expectedRoverX);
            Assert.AreEqual(plateau.SelectedRover.CurrentCoordinate.Y, expectedRoverY);
            Assert.AreEqual(plateau.SelectedRover.Direction, expectedRoverD);
        }