public IChessGame Create()
        {
            var piecesFactory   = new PiecesFactory();
            var movementHistory = new MovementHistory();
            var piecePromoter   = new PiecePromoter(movementHistory);
            var castlingMover   = new CastlingMover(movementHistory);
            var enPassantMover  = new EnPassantMover(movementHistory);
            var pieceMover      = new PieceMover(movementHistory, piecePromoter,
                                                 castlingMover, enPassantMover);
            var chessBoard = new ChessBoard(piecesFactory, pieceMover);

            List <IMovement> movements = new();
            var pawnMovement           = new PawnMovement(chessBoard);
            var enPassantMovement      = new EnPassantMovement(chessBoard);
            var kingMovement           = new KingMovement(chessBoard);
            var horizontalMovement     = new HorizontalMovement(chessBoard);
            var verticalMovement       = new VerticalMovement(chessBoard);
            var pdiagonalMovement      = new PositiveDiagonalMovement(chessBoard);
            var ndiagonalMovement      = new NegativeDiagonalMovement(chessBoard);
            var knightMovement         = new KnightMovement(chessBoard);

            movements.Add(pawnMovement);
            movements.Add(enPassantMovement);
            movements.Add(kingMovement);
            movements.Add(horizontalMovement);
            movements.Add(verticalMovement);
            movements.Add(pdiagonalMovement);
            movements.Add(ndiagonalMovement);
            movements.Add(knightMovement);
            var movementComposite = new MovementComposite(movements);

            List <IMovement> movementsWithCastling = new();
            var queensideCastlingMovement          =
                new QueensideCastlingMovement(chessBoard, movementComposite);
            var kingsideCastlingMovement =
                new KingsideCastlingMovement(chessBoard, movementComposite);

            movementsWithCastling.Add(movementComposite);
            movementsWithCastling.Add(queensideCastlingMovement);
            movementsWithCastling.Add(kingsideCastlingMovement);
            var movementCompositeWithCastling = new MovementComposite(movementsWithCastling);

            var promotionDetector = new PromotionDetector(chessBoard);

            var checkDetector = new CheckDetector(chessBoard, movementCompositeWithCastling);

            var legalMovement = new LegalMovement(chessBoard,
                                                  movementCompositeWithCastling, checkDetector);

            var moveValidator = new MoveValidator(chessBoard,
                                                  legalMovement, promotionDetector);

            var gameFinishedDetector = new GameFinishedDetector(checkDetector,
                                                                legalMovement);

            return(new ChessGame(chessBoard, moveValidator,
                                 promotionDetector, gameFinishedDetector, legalMovement));
        }
        public void WhenThereAreLegalMovesAvailableReturnsTrue()
        {
            //WK - white king
            //BR - black rook
            //PM - possible move
            //7
            //6
            //5
            //4
            //3
            //2
            //1                      BR
            //0          PM WK PM
            //  0  1  2  3  4  5  6  7
            var boardMock         = new Mock <IChessBoard>(MockBehavior.Strict);
            var checkDetectorMock = new Mock <ICheckDetector>(MockBehavior.Strict);
            var movementMock      = new Mock <IMovement>(MockBehavior.Strict);
            var kingMock          = new Mock <IReadOnlyChessPiece>(MockBehavior.Strict);

            var kingPosition = new Position(4, 0);

            var legalKingMoves = new List <ChessMove>()
            {
                new ChessMove(kingPosition, new Position(3, 0)),
                new ChessMove(kingPosition, new Position(5, 0))
            };

            var illegalKingMoves = new List <ChessMove>()
            {
                new ChessMove(kingPosition, new Position(3, 1)),
                new ChessMove(kingPosition, new Position(4, 1)),
                new ChessMove(kingPosition, new Position(5, 1))
            };

            bool isChecked = false;

            kingMock
            .SetupGet(p => p.Color)
            .Returns(ChessColor.White);

            boardMock
            .Setup(b => b.Move(It.IsIn <ChessMove>(legalKingMoves)));
            boardMock
            .Setup(b => b.Move(It.IsIn <ChessMove>(illegalKingMoves)))
            .Callback(() => isChecked = true);
            boardMock
            .Setup(b => b.ReverseLastMove())
            .Callback(() => isChecked = false);
            boardMock
            .SetupGet(b => b.Pieces)
            .Returns(new List <IReadOnlyChessPiece>()
            {
                kingMock.Object
            });

            checkDetectorMock
            .Setup(c => c.IsChecked(ChessColor.White))
            .Returns(() => isChecked);

            movementMock
            .Setup(m => m.GetAvailableMoves(kingMock.Object))
            .Returns(legalKingMoves.Union(illegalKingMoves));

            var movement = new LegalMovement(boardMock.Object, movementMock.Object,
                                             checkDetectorMock.Object);
            var canMove = movement.HasAnyLegalMoves(kingMock.Object.Color);

            Assert.IsTrue(canMove);
        }