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 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_ShouldThrowExceptionsIfNoPlayersHaveBeenCreated() { //arrange var mockSetting = SetupSettings(10); var mockInput = new Mock <IInput>(); mockInput.Setup(x => x.AskUserForShipPlacementCoordinates()) .Returns(() => GenerateMockSetUpShipPlacementCoordinates()); var battleships = new Battleships(mockSetting, mockInput.Object); //act Action act = () => battleships.StartGame(); //assert act.Should().Throw <Exception>().WithMessage("No players created"); }