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"); }
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"); }
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); }
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"); }
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)); }
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); }