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); }
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); }
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); }
public Result <Exception, RobotAgreggate> Add(RobotAgreggate robot) { var robotId = Guid.NewGuid().ToString("N"); robot.RobotId = robotId; _cache.TryAdd(robotId, robot); return(robot); }
public Result <Exception, RobotAgreggate> Get(string robotId) { RobotAgreggate robot = null; if (_cache.TryGetValue(robotId, out robot)) { return(robot); } return(new NotFoundException()); }
private Result <Exception, int> PersistRobotState(RobotAgreggate robot, int state) { var updateCallback = _repository.Update(robot); if (updateCallback.IsSuccess) { return(state); } return(updateCallback.Failure); }
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); }
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(); }
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}")); }
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); }
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); }
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); }
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); }
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.")); } }
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.")); } }
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); }
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); }
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); }