コード例 #1
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);
        }
コード例 #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);
        }