Beispiel #1
0
        public void ExecutePlaceCommandSuccessfulTest()
        {
            var subject = new RoboControlCenter(_roboman, _commandResult);

            string[] commandStringInput = { AppTestConstants.PlaceCommandString, AppTestConstants.ValidPlaceCommandStringArgument };

            var expectedActionResult = new MovementActionResult(MovementStatus.RobotPlacementSuccessful);

            _roboman.SetPositionOnBoard(Arg.Any <int>(), Arg.Any <int>(), Arg.Any <FaceDirection>()).ReturnsForAnyArgs(expectedActionResult);

            _controlCenter.ExecuteCommand(commandStringInput);

            // Assert IRobot

            _roboman.DidNotReceive().Move();

            _roboman.DidNotReceive().Left();

            _roboman.DidNotReceive().Right();

            _roboman.DidNotReceive().ReportStatus();

            // Assert roboman is the same with given command string //

            _roboman.Received().SetPositionOnBoard(1, 1, FaceDirection.NORTH);

            // Assert ICommandResult was called with the proper actionResult

            _commandResult.Received().ProcessResult(expectedActionResult);
        }
Beispiel #2
0
        public void ExecuteRightCommandSuccessfulTest()
        {
            var subject = new RoboControlCenter(_roboman, _commandResult);

            string[] commandStringInput = { AppTestConstants.RightCommandString };

            var expectedActionResult = new MovementActionResult(MovementStatus.TurnRightSuccessful);

            _roboman.Right().Returns(expectedActionResult);

            _controlCenter.ExecuteCommand(commandStringInput);

            // Assert IRobot

            _roboman.DidNotReceive().Move();

            _roboman.DidNotReceive().Left();

            _roboman.Received().Right();

            _roboman.DidNotReceive().ReportStatus();

            // Assert ICommandResult was called with the proper actionResult

            _commandResult.Received().ProcessResult(expectedActionResult);
        }
Beispiel #3
0
        public void ExecuteCommand(string[] command)
        {
            MovementActionResult executionResult;

            if (command == null)
            {
                executionResult = new MovementActionResult(MovementStatus.InvalidInstructionGiven);
            }
            else
            {
                var actionResult = CommandLine.Parser.Default.ParseArguments <PlaceOptions, MoveOptions,
                                                                              LeftOptions, RightOptions, ReportOptions>(command)

                                   .MapResult(

                    (PlaceOptions opts) => PlaceRobot(opts),

                    (MoveOptions opts) => Move(opts),

                    (LeftOptions opts) => TurnLeft(opts),

                    (RightOptions opts) => TurnRight(opts),

                    (ReportOptions opts) => ReportStatus(opts),

                    errs => new MovementActionResult(MovementStatus.InvalidInstructionGiven));

                executionResult = actionResult as MovementActionResult;
            }

            _commandResultHandler.ProcessResult(executionResult);
        }
Beispiel #4
0
        public void ExecuteReportCommandSuccessfulTest()
        {
            string[] commandStringInput = { AppTestConstants.ReportCommandString };

            var expectedActionResult = new MovementActionResult(MovementStatus.ReportStatusOk);

            _roboman.ReportStatus().Returns(expectedActionResult);

            _controlCenter.ExecuteCommand(commandStringInput);

            // Assert IRobot

            _roboman.DidNotReceive().Move();

            _roboman.DidNotReceive().Left();

            _roboman.DidNotReceive().Right();

            _roboman.Received().ReportStatus();

            // Assert ICommandResult was called with the proper actionResult

            _commandResult.Received().ProcessResult(Arg.Is <MovementActionResult>(x => x.Status == MovementStatus.ReportStatusOk));
        }
Beispiel #5
0
        public void ProcessResult(MovementActionResult actionResult)
        {
            if (actionResult == null)
            {
                System.Console.WriteLine(Appconstant.InvalidInstructionGiven);
                return;
            }

            switch (actionResult.Status)
            {
            case MovementStatus.RobotNotPlacedOnBoard:
                System.Console.WriteLine(Appconstant.RobotNotPlaced);
                break;

            case MovementStatus.RobotPlacementSuccessful:
                System.Console.WriteLine(Appconstant.RobotPlacementSuccessful);
                break;

            case MovementStatus.RobotPlamentOutOfBoardSize:
                System.Console.WriteLine(Appconstant.RobotPlamentOutOfBoardSize);
                break;

            case MovementStatus.RobotPlaceInvalidCommandParsed:
                System.Console.WriteLine(Appconstant.RobotPlaceInvalidCommandParsed);
                break;

            case MovementStatus.TurnLeftSuccessful:
                System.Console.WriteLine(Appconstant.TurnLeftSuccessful);
                break;

            case MovementStatus.TurnLeftUnable:
                System.Console.WriteLine(Appconstant.TurnLeftUnable);
                break;

            case MovementStatus.TurnRightSuccessful:
                System.Console.WriteLine(Appconstant.TurnRightSuccessful);
                break;

            case MovementStatus.TurnRightFail:
                System.Console.WriteLine(Appconstant.TurnRightFail);
                break;

            case MovementStatus.MoveOk:
                System.Console.WriteLine(Appconstant.MoveOk);
                break;

            case MovementStatus.MoveXOutOfBoardMaxSize:
                System.Console.WriteLine(Appconstant.MoveXOutOfBoardMaxSize);
                break;

            case MovementStatus.MoveXOutOfBoardMinSize:
                System.Console.WriteLine(Appconstant.MoveXOutOfBoardMinSize);
                break;

            case MovementStatus.UnableToMoveToTargetLocation:
                System.Console.WriteLine(Appconstant.UnableToMoveToTargetLocation);
                break;

            case MovementStatus.MoveYOutOfBoardMaxSize:
                System.Console.WriteLine(Appconstant.MoveYOutOfBoardMaxSize);
                break;

            case MovementStatus.MoveYOutOfBoardMinSize:
                System.Console.WriteLine(Appconstant.MoveYOutOfBoardMinSize);
                break;

            case MovementStatus.MoveCannotBeDetermined:
                System.Console.WriteLine(Appconstant.MoveCannotBeDetermined);
                break;

            case MovementStatus.ChangeDirectionOk:
                System.Console.WriteLine(Appconstant.ChangeDirectionOk);
                break;

            case MovementStatus.ChangeDirectionFailed:
                System.Console.WriteLine(Appconstant.ChangeDirectionFailed);
                break;

            case MovementStatus.InvalidInstructionGiven:
                System.Console.WriteLine(Appconstant.InvalidInstructionGiven);
                break;

            case MovementStatus.ReportStatusOk:
                if (actionResult.LocationX.HasValue && actionResult.LocationY.HasValue)
                {
                    System.Console.WriteLine($"Location X:{actionResult.LocationX} " +
                                             $"Y:{actionResult.LocationY} " +
                                             $"Direction:{actionResult.Direction}");
                }
                else
                {
                    System.Console.WriteLine("Robot in steath mode.");
                }
                break;

            case MovementStatus.ReportStatusFailed:
                System.Console.WriteLine(Appconstant.ReportStatusFailed);
                break;

            default:
                break;
            }
        }