public void Act_ShouldSelectOtherPlayer()
        {
            //Arrange
            FakeCell fakeCell = new FakeCell.Builder().Build();
            FakeEnumerator <ICell> fakeEnumerator = new FakeEnumerator <ICell> .Builder()
                                                    .MoveNext(true)
                                                    .Current(fakeCell)
                                                    .Build();

            FakeCellCollection fakeCellCollection = new FakeCellCollection.Builder()
                                                    .GetEnumerator(fakeEnumerator)
                                                    .Build();
            FakeBoard fakeBoardClone = new FakeBoard.Builder()
                                       .ClaimEndsGame(Bool.True)
                                       .Build();
            FakeBoard fakeBoard = new FakeBoard.Builder()
                                  .AvailableSpaces(fakeCellCollection)
                                  .Clone(fakeBoardClone)
                                  .Build();
            FakePlayer           fakePlayer            = new FakePlayer.Builder().Build();
            FakeSelectMoveAction fakeSelectMoveAction  = new FakeSelectMoveAction.Builder().Act(null).Build();
            OtherPlayerWinningSelectMoveAction subject = new OtherPlayerWinningSelectMoveAction(fakeSelectMoveAction);

            //Act
            subject.Act(fakeBoard, null, fakePlayer);

            //Assert
            fakeBoardClone.AssertClaimEndsGameInvokedWith(fakeCell, fakePlayer);
        }
示例#2
0
        public void ShouldCreateOnlyHumanPlayerFromInput()
        {
            //Arrange
            FakePlayer fakePlayer = new FakePlayer.Builder().Build();
            FakeValidResponse <IPlayer> fakeValidResponse = new FakeValidResponse <IPlayer> .Builder().Response(fakePlayer).Build();

            OnlyHumanCreation subject = new OnlyHumanCreation(fakeValidResponse);

            //Act
            IPlayer actual = subject.Player("mark");

            //Assert
            actual.Should().Be(fakePlayer);
        }
示例#3
0
        public void ShouldPrintExpected()
        {
            //Arrange
            FakeWriter       fakeWriter = new FakeWriter();
            FakeCell         fakeCell   = new FakeCell.Builder().Value("YEAH").Build();
            FakePlayer       fakePlayer = new FakePlayer.Builder().Cell(fakeCell).Build();
            PlayerWinPrinter subject    = new PlayerWinPrinter(fakePlayer, fakeWriter);

            //Act
            subject.Print();

            //Assert
            fakeWriter.AssertLastLine("Player 'YEAH' has won!");
        }
示例#4
0
        public void ShouldWinPrintActivePlayer()
        {
            //Arrange
            FakePlayerEndsGameAction     fakePlayerEndsGameAction = new FakePlayerEndsGameAction.Builder().Act(Bool.True).Build();
            TakeTurnPlayerEndsGameAction subject = new TakeTurnPlayerEndsGameAction(fakePlayerEndsGameAction);
            FakePlayer fakePlayer = new FakePlayer.Builder().TakeAction().Build();

            //Act
            bool actual = subject.Act(null, fakePlayer, null);

            //Assert
            actual.Should().BeTrue();
            fakePlayer.AssertTakeActionInvoked();
            fakePlayerEndsGameAction.AssertActInvoked();
        }
        public void Act_ShouldCallActWhenCenterNotAvailable()
        {
            //Arrange
            FakeCell                     expectedCell         = new FakeCell.Builder().Build();
            FakeSelectMoveAction         fakeSelectMoveAction = new FakeSelectMoveAction.Builder().Act(expectedCell).Build();
            FakeBoard                    fakeBoard            = new FakeBoard.Builder().Available(Bool.False).Build();
            FakePlayer                   fakePlayerA          = new FakePlayer.Builder().Build();
            FakePlayer                   fakePlayerB          = new FakePlayer.Builder().Build();
            CenterSquareSelectMoveAction subject = new CenterSquareSelectMoveAction(fakeSelectMoveAction);

            //Act
            subject.Act(fakeBoard, fakePlayerA, fakePlayerB);

            //Assert
            fakeSelectMoveAction.AssertActInvokedWith(new Tuple <IBoard, IPlayer, IPlayer>(fakeBoard, fakePlayerA, fakePlayerB));
        }
示例#6
0
        public void ShouldReturnPlayersTurns()
        {
            //Arrange
            FakePlayer                 fakePlayer         = new FakePlayer.Builder().Build();
            FakePlayerCreation         fakePlayerCreation = new FakePlayerCreation.Builder().Player(fakePlayer).Build();
            FakeBoard                  fakeBoard          = new FakeBoard.Builder().Build();
            ComputerVsComputerGameMode subject            = new ComputerVsComputerGameMode(fakePlayerCreation);

            //Act
            IPlayersTurns actual = subject.ConfigurePlayers(fakeBoard);

            //Assert
            actual.Should().BeOfType <PlayersTurns>();
            fakePlayerCreation.PlayerInvokedWith("O");
            fakePlayerCreation.PlayerInvokedWith("X");
        }
示例#7
0
        public void ShouldReturnPlayersTurns()
        {
            //Arrange
            FakeCell             fakeCell           = new FakeCell.Builder().Value("?").Build();
            FakePlayer           fakePlayer         = new FakePlayer.Builder().Cell(fakeCell).Build();
            FakePlayer           fakePlayer2        = new FakePlayer.Builder().Build();
            FakePlayerCreation   fakePlayerCreation = new FakePlayerCreation.Builder().Player(fakePlayer, fakePlayer2).Build();
            FakeBoard            fakeBoard          = new FakeBoard.Builder().Build();
            HumanVsHumanGameMode subject            = new HumanVsHumanGameMode(fakePlayerCreation, fakePlayerCreation);

            //Act
            IPlayersTurns actual = subject.ConfigurePlayers(fakeBoard);

            //Assert
            actual.Should().BeOfType <PlayersTurns>();
            fakePlayerCreation.PlayerInvokedWith("");
            fakePlayerCreation.PlayerInvokedWith("?");
        }
示例#8
0
        public void ClaimEndsGame_ReturnTrueWhenOver()
        {
            //Arrange
            FakePrinter        fakePrinter        = new FakePrinter.Builder().Build();
            FakeCell           fakeCell           = new FakeCell.Builder().Build();
            FakeCellCollection fakeCellCollection = new FakeCellCollection.Builder()
                                                    .UpdateTo()
                                                    .Build();
            FakeGameState fakeGameState = new FakeGameState.Builder().IsGameOver(Bool.True).Build();
            FakePlayer    fakePlayer    = new FakePlayer.Builder().Cell(fakeCell).Build();
            Board         subject       = new Board(fakeCellCollection, fakeGameState, fakePrinter);

            //Act
            Bool actual = subject.ClaimEndsGame(null, fakePlayer);

            //Assert
            ((bool)actual).Should().BeTrue();
        }
示例#9
0
        public void ClaimEndsGame_ShouldClaimCellForPlayer()
        {
            //Arrange
            FakePrinter     fakePrinter      = new FakePrinter.Builder().Build();
            FakeCell        fakeCellBoard    = new FakeCell.Builder().IsSelected(Bool.False).Value("1").Build();
            FakeCell        fakeCellSelected = new FakeCell.Builder().IsSelected(Bool.False).Value("1").Build();
            FakeCell        fakeCellPlayer   = new FakeCell.Builder().AsSelected(fakeCellSelected).Value("1").Build();
            ICellCollection cellCollection   = new CellCollection(new ICell[] { fakeCellBoard });
            FakeGameState   fakeGameState    = new FakeGameState.Builder().IsGameOver(Bool.False).Build();
            FakePlayer      fakePlayer       = new FakePlayer.Builder().Cell(fakeCellPlayer).Build();
            Board           subject          = new Board(cellCollection, fakeGameState, fakePrinter);

            //Act
            subject.ClaimEndsGame(fakeCellBoard, fakePlayer);

            //Assert
            cellCollection.At(new IntOf(0)).Should().NotBe(fakeCellBoard);
        }
        public void Act_ShouldReturnAvailableCell()
        {
            //Arrange
            FakeCell  expected  = new FakeCell.Builder().Value("1").Build();
            FakeBoard fakeBoard = new FakeBoard.Builder()
                                  .Available(Bool.False, Bool.False, Bool.False, Bool.True).Build();
            FakeCell              fakeCell        = new FakeCell.Builder().Build();
            FakePlayer            fakePlayer      = new FakePlayer.Builder().Cell(fakeCell).Build();
            FakePlayer            fakePlayerOther = new FakePlayer.Builder().Build();
            FakeMoveInput         fakeMoveInput   = new FakeMoveInput.Builder().Input(new Glyph('1')).Build();
            HumanSelectMoveAction subject         = new HumanSelectMoveAction(fakeMoveInput);

            //Act
            ICell actual = subject.Act(fakeBoard, fakePlayer, fakePlayerOther);

            //Assert
            actual.Value().Should().Be(expected.Value());
        }
示例#11
0
        public void ShouldReturnPlayersTurnsComputerAsX()
        {
            //Arrange
            FakeCell   fakeCell           = new FakeCell.Builder().Value("O").Build();
            FakePlayer fakePlayer         = new FakePlayer.Builder().Cell(fakeCell).Build();
            FakePlayer fakePlayerComputer = new FakePlayer.Builder().Build();
            FakeValidResponse <IPlayerOrder> fakeValidResponse = new FakeValidResponse <IPlayerOrder> .Builder().Response(new HumanFirstOrder()).Build();

            FakePlayerCreation      fakePlayerCreation = new FakePlayerCreation.Builder().Player(fakePlayer, fakePlayerComputer).Build();
            FakeBoard               fakeBoard          = new FakeBoard.Builder().Build();
            HumanVsComputerGameMode subject            = new HumanVsComputerGameMode(fakeValidResponse, fakePlayerCreation, fakePlayerCreation);

            //Act
            IPlayersTurns actual = subject.ConfigurePlayers(fakeBoard);

            //Assert
            actual.Should().BeOfType <PlayersTurns>();
            fakePlayerCreation.PlayerInvokedWith("");
            fakePlayerCreation.PlayerInvokedWith("X");
        }
        public void ShouldCreateSecondHumanCreationFromInput()
        {
            //Arrange
            FakePlayer fakePlayer = new FakePlayer.Builder().Build();
            FakeValidResponse <IPlayer> fakeValidResponse = new FakeValidResponse <IPlayer> .Builder().Response(fakePlayer).Build();

            FakeFormattedValidInput <IPlayer> fakeFormattedValidInput = new FakeFormattedValidInput <IPlayer> .Builder()
                                                                        .AddPromptArg()
                                                                        .AddPatternArg()
                                                                        .ValidInput(fakeValidResponse)
                                                                        .Build();

            SecondHumanCreation subject = new SecondHumanCreation(fakeFormattedValidInput);

            //Act
            IPlayer actual = subject.Player("mark");

            //Assert
            actual.Should().Be(fakePlayer);
            fakeFormattedValidInput.AssertAddPromptArgInvokedWith("mark");
            fakeFormattedValidInput.AssertAddPatternArgInvokedWith("mark");
        }