コード例 #1
0
        private Result <Exception, int> ProcessHeadAlign(HeadAlignCommand command, RobotAgreggate robot)
        {
            Result <Exception, Align> moveCallback;

            switch (command.HeadMove.ToLower())
            {
            case "top":
                moveCallback = robot.MoveHeadForUp();
                break;

            case "down":
                moveCallback = robot.MoveHeadToBelow();
                break;

            default:
                return(new BussinessException(ErrorCodes.BadRequest, "Comando inválido."));
            }

            if (moveCallback.IsSuccess)
            {
                return(PersistRobotState(robot, (int)moveCallback.Success));
            }

            return(moveCallback.Failure);
        }
コード例 #2
0
        private Result <Exception, int> ProcessHeadRotate(HeadRotateCommand command, RobotAgreggate robot)
        {
            Result <Exception, int> rotateCallback;

            switch (command.HeadRotate.ToLower())
            {
            case "left":
                rotateCallback = robot.RotateHeadToTheLeft();
                break;

            case "right":
                rotateCallback = robot.RotateHeadToTheRight();
                break;

            default:
                return(new BussinessException(ErrorCodes.BadRequest, "Comando inválido."));
            }

            // Publish Domain Events
            _mediator.PublishDomainEvents(robot.RaisedEvents());

            if (rotateCallback.IsSuccess)
            {
                return(PersistRobotState(robot, rotateCallback.Success));
            }

            return(rotateCallback.Failure);
        }
コード例 #3
0
        private Result <Exception, int> ProcessWristAction(WristCommand command, RobotAgreggate robot)
        {
            Result <Exception, int> actionCallback;

            switch (command.WristSide.ToLower())
            {
            case "left":
                actionCallback = ExecuteActionInLeftWrist(robot, command.WristRotate);
                break;

            case "right":
                actionCallback = ExecuteActionInRightWrist(robot, command.WristRotate);
                break;

            default:
                return(new BussinessException(ErrorCodes.BadRequest, "WristSide possui comando inválido."));
            }

            if (actionCallback.IsSuccess)
            {
                return(PersistRobotState(robot, actionCallback.Success));
            }

            return(actionCallback.Failure);
        }
コード例 #4
0
        public Result <Exception, RobotAgreggate> Add(RobotAgreggate robot)
        {
            var robotId = Guid.NewGuid().ToString("N");

            robot.RobotId = robotId;
            _cache.TryAdd(robotId, robot);
            return(robot);
        }
コード例 #5
0
        public Result <Exception, RobotAgreggate> Get(string robotId)
        {
            RobotAgreggate robot = null;

            if (_cache.TryGetValue(robotId, out robot))
            {
                return(robot);
            }
            return(new NotFoundException());
        }
コード例 #6
0
        private Result <Exception, int> PersistRobotState(RobotAgreggate robot, int state)
        {
            var updateCallback = _repository.Update(robot);

            if (updateCallback.IsSuccess)
            {
                return(state);
            }

            return(updateCallback.Failure);
        }
コード例 #7
0
        public void RotateHeadToTheRightTest()
        {
            //Arrange
            RobotAgreggate robot = creator.MakeARobot();

            //Action
            var result = robot.RotateHeadToTheRight();

            //Assert
            result.IsSuccess.ShouldBeTrue();
            result.Success.ShouldBe(-45);
            robot.HeadDirection.ShouldBe(-45);
        }
コード例 #8
0
        public void RepositoryAddRobotTest()
        {
            //Arrange
            creator = new MockCreatorRobot();
            RobotAgreggate robot = creator.MakeARobot();

            //Action
            var result = repository.Add(robot);

            //Assert
            result.IsSuccess.ShouldBeTrue();
            result.Success.RobotId.ShouldNotBeNullOrEmpty();
        }
コード例 #9
0
        public Result <Exception, RobotAgreggate> Update(RobotAgreggate robot)
        {
            RobotAgreggate actualRobot = null;

            _cache.TryGetValue(robot.RobotId, out actualRobot);

            if (_cache.TryUpdate(robot.RobotId, robot, actualRobot))
            {
                return(robot);
            }

            return(new InvalidOperationException($"Erro ao atualizar o robo: {robot.RobotId}"));
        }
コード例 #10
0
        public void ExpandRightElbowDenyTest()
        {
            //Arrange
            RobotAgreggate robot = creator.MakeARobot();

            //Action
            var result = robot.RightElbowExpand();

            //Assert
            result.IsFailure.ShouldBeTrue();
            result.Failure.ShouldBeOfType <LimitedElbowExpandException>();
            robot.RightElbowPosition.ShouldBe(180);
        }
コード例 #11
0
        public void MoveHeadToBelowTest()
        {
            //Arrange
            RobotAgreggate robot = creator.MakeARobot();

            //Action
            var result = robot.MoveHeadToBelow();

            //Assert
            result.IsSuccess.ShouldBeTrue();
            result.Success.ShouldBe(Align.Botton);
            robot.HeadAlign.ShouldBe(Align.Botton);
        }
コード例 #12
0
        public void CollapseRightElbowTest()
        {
            //Arrange
            RobotAgreggate robot = creator.MakeARobot();

            //Action
            var result = robot.RightElbowCollapse();

            //Assert
            result.IsSuccess.ShouldBeTrue();
            result.Success.ShouldBe(135);
            robot.RightElbowPosition.ShouldBe(135);
        }
コード例 #13
0
        public void RotateHeadToTheLeftTwoTimesTest()
        {
            //Arrange
            RobotAgreggate robot = creator.MakeARobot();

            //Action
            robot.RotateHeadToTheLeft();
            var result = robot.RotateHeadToTheLeft();

            //Assert
            result.IsSuccess.ShouldBeTrue();
            result.Success.ShouldBe(90);
            robot.HeadDirection.ShouldBe(90);
        }
コード例 #14
0
        private Result <Exception, int> ExecuteActionInRightWrist(RobotAgreggate robot, string action)
        {
            switch (action.ToLower())
            {
            case "left":
                return(robot.RightWristRotateToTheLeft());

            case "right":
                return(robot.RightWristRotateToTheRight());

            default:
                return(new BussinessException(ErrorCodes.BadRequest, "WristRotate possui comando inválido."));
            }
        }
コード例 #15
0
        private Result <Exception, int> ExecuteActionInRightElbow(RobotAgreggate robot, string action)
        {
            switch (action.ToLower())
            {
            case "collapse":
                return(robot.RightElbowCollapse());

            case "expand":
                return(robot.RightElbowExpand());

            default:
                return(new BussinessException(ErrorCodes.BadRequest, "ElbowAction possui comando inválido."));
            }
        }
コード例 #16
0
        public void CollapseLeftElbowTwoTimesTest()
        {
            //Arrange
            RobotAgreggate robot = creator.MakeARobot();

            //Action
            robot.LeftElbowCollapse();
            var result = robot.LeftElbowCollapse();

            //Assert
            result.IsSuccess.ShouldBeTrue();
            result.Success.ShouldBe(90);
            robot.LeftElbowPosition.ShouldBe(90);
        }
コード例 #17
0
        public void RepositoryUpdateRobotTest()
        {
            //Arrange
            RobotAgreggate robot = null;

            robot = repository.Get("099153c2625149bc8ecb3e85e03f0022").Success;

            //Action
            robot.MoveHeadForUp();
            var result = repository.Update(robot);

            //Assert
            result.IsSuccess.ShouldBeTrue();
            result.Success.HeadAlign.ShouldBe(Align.Top);
        }
コード例 #18
0
        public void ARobotCreatedTest()
        {
            RobotAgreggate robot = creator.MakeARobot();

            //head
            //align
            //direction
            robot.HeadAlign.ShouldBe(Align.Normal);
            robot.HeadDirection.ShouldBe(0);
            //elbow
            //leftelbow
            //rightelbow
            robot.LeftElbowPosition.ShouldBe(180);
            robot.RightElbowPosition.ShouldBe(180);
            //wrist
            //leftwrist
            //rightwrist
            robot.LeftWristDirection.ShouldBe(0);
            robot.RightWristDirection.ShouldBe(0);
        }