コード例 #1
0
        public async Task IsValidYMove_WhenMoveIsValid_ShouldReturnTrue(int plateauY, int yMove)
        {
            _plateauMock.SetupGet(p => p.Y).Returns(plateauY);

            var isValid = await _moveValidator.IsValidYMove(yMove);

            Assert.True(isValid);
        }
コード例 #2
0
        public async Task <MoveResult> Handle(MoveForwardCommand request, CancellationToken cancellationToken)
        {
            int xAfterMoving = request.CurrentPosition.X;
            int yAfterMoving = request.CurrentPosition.Y;

            switch (request.Direction)
            {
            case Direction.North:
                yAfterMoving++;
                break;

            case Direction.East:
                xAfterMoving++;
                break;

            case Direction.South:
                yAfterMoving--;
                break;

            case Direction.West:
                xAfterMoving--;
                break;
            }
            ;

            if (!await _moveValidator.IsValidXMove(xAfterMoving) || !await _moveValidator.IsValidYMove(yAfterMoving))
            {
                return(CreateMoveResult(request.CurrentPosition));
            }

            return(CreateMoveResult(new Point {
                X = xAfterMoving, Y = yAfterMoving
            }));
        }