public void IsValidHandleRequestShouldRecogniseAnInvalidCommand()
 {
     var testHandler = new IsValidPlayCommandHandler();
     var testBoard = new Board(new EasyBoardSettings(), new List<IBoardObserver>());
     testHandler.HandleRequest(command: "a a", board: testBoard);
     Assert.AreEqual(expected: true, actual: testHandler.IsInvalid);
     Assert.AreEqual(BoardState.Pending, testBoard.BoardState);
 }
 public void IsValidPlayCommandShouldCallItsSuccessorWhenNeeded()
 {
     var testHandler = new IsValidPlayCommandHandler();
     var testBoard = new Board(new EasyBoardSettings(), new List<IBoardObserver>());
     testHandler.SetSuccessor(new IsInsideBoardHandler());
     testBoard.Cells[0, 0] = new CellContext();
     testBoard.Cells[0, 0].Content = new EmptyContent();
     testBoard.Cells[0, 0].Content.Value = 1;
     testHandler.HandleRequest(command: "0 0", board: testBoard);
 }
        /// <summary>
        /// The concrete implementation of the common method Execute setting up all handlers and successors
        /// and calling the first fro their chain
        /// </summary>
        /// <param name="command">The command to be executed</param>
        public void Execute(string command)
        {
            var isValidPlayCommandHandler = new IsValidPlayCommandHandler();
            var isInsideBoardHandler = new IsInsideBoardHandler();
            var isAlreadyShownHandler = new IsAlreadyShownHandler();
            var isBombHandler = new IsBombHandler();
            var revealCellHandler = new RevealCellHandler();

            isValidPlayCommandHandler.SetSuccessor(isInsideBoardHandler);
            isInsideBoardHandler.SetSuccessor(isAlreadyShownHandler);
            isAlreadyShownHandler.SetSuccessor(isBombHandler);
            isBombHandler.SetSuccessor(revealCellHandler);

            isValidPlayCommandHandler.HandleRequest(command, this.board);
        }
 public void IsValidPlayShouldHandleTheRequestIfTheCellIsValid()
 {
     var testHandler = new IsValidPlayCommandHandler();
     var testBoard = new Board(new EasyBoardSettings(), new List<IBoardObserver>());
     testHandler.SetSuccessor(new IsInsideBoardHandler());
     testBoard.Cells[0, 0] = new CellContext();
     testBoard.Cells[0, 0].Content = new EmptyContent();
     testBoard.Cells[0, 0].Content.Value = 0;
     testBoard.Cells[0, 0].State = CellState.Sealed;
     testBoard.Cells[0, 1] = new CellContext();
     testBoard.Cells[0, 1].Content = new EmptyContent();
     testBoard.Cells[0, 1].Content.Value = 1;
     testBoard.Cells[0, 1].State = CellState.Sealed;
     testBoard.Cells[1, 0] = new CellContext();
     testBoard.Cells[1, 0].Content = new EmptyContent();
     testBoard.Cells[1, 0].Content.Value = 1;
     testBoard.Cells[1, 0].State = CellState.Sealed;
     testBoard.Cells[1, 1] = new CellContext();
     testBoard.Cells[1, 1].Content = new EmptyContent();
     testBoard.Cells[1, 1].Content.Value = 2;
     testBoard.Cells[1, 1].State = CellState.Sealed;
     testHandler.HandleRequest(command: "0 0", board: testBoard);
 }
 public void IsValidHandleRequestShouldRecogniseAValidCommand()
 {
     var testHandler = new IsValidPlayCommandHandler();
     testHandler.HandleRequest(command: "1 1", board: new Board(new EasyBoardSettings(), new List<IBoardObserver>()));
     Assert.AreEqual(expected: false, actual: testHandler.IsInvalid);
 }