示例#1
0
        public void BattleshipsGameStart_WhenStartingGame_AWinnerIsFoundAndSet()
        {
            //arrange
            var mockSetting = SetupSettings(10);
            var mockInput   = new Mock <IInput>();

            mockInput.Setup(x => x.AskUserForShipPlacementCoordinates())
            .Returns(() => GenerateMockSetUpShipPlacementCoordinates());
            mockInput.Setup(x => x.AskUserForAttackingCoordinates())
            .Returns(() => GenerateMockSetUpAttackingCoordinates());

            var battleships = new Battleships(mockSetting, mockInput.Object);

            const string mockPlayerName   = "Chris";
            const string mockOpponentName = "John";

            battleships.CreatePlayer(mockPlayerName);
            battleships.CreatePlayer(mockOpponentName);

            //act
            var player   = battleships.GetPlayer(mockPlayerName);
            var opponent = battleships.GetPlayer(mockOpponentName);

            player.SetShips();
            opponent.SetShips();
            battleships.StartGame();

            //assert
            battleships.GetWinner().Should().NotBe(null);
            battleships.GetWinner().Should().BeOneOf("Chris", "John", "Draw");
        }
示例#2
0
        BattleshipsPlayerStartGame_WhenInvoked_ShouldThrowExceptionsIfTooMany()
        {
            //arrange
            var mockSetting = SetupSettings(10);
            var mockInput   = new Mock <IInput>();

            mockInput.Setup(x => x.AskUserForShipPlacementCoordinates())
            .Returns(() => GenerateMockSetUpShipPlacementCoordinates());
            var          battleships    = new Battleships(mockSetting, mockInput.Object);
            const string mockPlayerName = "Chris";

            battleships.CreatePlayer(mockPlayerName);

            const string mockPlayerNameTwo = "John";

            battleships.CreatePlayer(mockPlayerNameTwo);

            const string mockPlayerNameThree = "Bill";

            battleships.CreatePlayer(mockPlayerNameThree);

            //act
            Action act = () => battleships.StartGame();

            //assert
            act.Should().Throw <Exception>().WithMessage("Too many players add");
        }
示例#3
0
        public void BattleshipsPlayerBoards_WhenInitialised_ShouldEqualTheSquareOfTheSettingsBoardSizeValue(int boardSize)
        {
            //arrange
            var mockSetting = SetupSettings(boardSize);
            var mockInput   = SetupInput("12V");
            var battleship  = new Battleships(mockSetting, mockInput);

            battleship.CreatePlayer("Chris");

            //act
            var player = battleship.GetPlayer("Chris");

            //assert
            player.Board.Should().HaveCount(boardSize * boardSize);
            player.AttackingBoard.Should().HaveCount(boardSize * boardSize);
        }
示例#4
0
        BattleshipsPlayerStartGame_WhenInvoked_ShouldThrowExceptionsIfOnlyOnePlayerHasBeenCreated()
        {
            //arrange
            var mockSetting = SetupSettings(10);
            var mockInput   = new Mock <IInput>();

            mockInput.Setup(x => x.AskUserForShipPlacementCoordinates())
            .Returns(() => GenerateMockSetUpShipPlacementCoordinates());
            var          battleships    = new Battleships(mockSetting, mockInput.Object);
            const string mockPlayerName = "Chris";

            battleships.CreatePlayer(mockPlayerName);

            //act
            Action act = () => battleships.StartGame();

            //assert
            act.Should().Throw <Exception>().WithMessage("Not enough players created");
        }
示例#5
0
        BattleshipsPlayerShipSetUp_WhenSettingThePlayerShipsOnTheBoard_PlayerShouldHaveMarkersEqualToTheNumberOfShipsAndTheirLength()
        {
            //arrange
            var mockSetting = SetupSettings(10);
            var mockInput   = new Mock <IInput>();

            mockInput.Setup(x => x.AskUserForShipPlacementCoordinates())
            .Returns(() => GenerateMockSetUpShipPlacementCoordinates());
            var          battleships    = new Battleships(mockSetting, mockInput.Object);
            const string mockPlayerName = "Chris";

            battleships.CreatePlayer(mockPlayerName);

            //act
            var player = battleships.GetPlayer(mockPlayerName);

            player.SetShips();
            var result = player.Board.Cast <BoardBlock>().Count(boardBlock => boardBlock.MarkerType == "E");


            //assert
            result.Should().Be(player.Board.Length - CountShips(player));
        }
示例#6
0
        public void BattleshipsPlayerShipSetUp_WhenSettingThePlayerShipsOnTheBoard_MarkTypesCountShouldEqualShipLength
            (string battleshipMarker, int shipLength)
        {
            //arrange
            var mockSetting = SetupSettings(10);
            var mockInput   = new Mock <IInput>();

            mockInput.Setup(x => x.AskUserForShipPlacementCoordinates())
            .Returns(() => GenerateMockSetUpShipPlacementCoordinates());
            var          battleships    = new Battleships(mockSetting, mockInput.Object);
            const string mockPlayerName = "Chris";

            battleships.CreatePlayer(mockPlayerName);

            //act
            var player = battleships.GetPlayer(mockPlayerName);

            player.SetShips();

            //assert
            var result = player.Board.Cast <BoardBlock>().Count(boardBlock => boardBlock.MarkerType == battleshipMarker);

            result.Should().Be(shipLength);
        }