public void RecordsLastShotCorrectly(int shipSize, ShotResult expectedShotResult) { var player1 = new Mock <IBattleShipShooter>(); var player2 = new Mock <IBattleShipShooter>(); var ships = new[] { new Ship('A', 1, 'A', 1), new Ship('A', 1, 'A', 2), }; var coordinates = new Coordinates('A', 1); player1.Setup(x => x.Shoot()).Returns(coordinates); player2.Setup(x => x.Shoot()).Returns(coordinates); player1.Setup(x => x.PrepareShipsForNewBattle()).Returns(ships.Where(s => s.Size == shipSize).ToArray); player2.Setup(x => x.PrepareShipsForNewBattle()).Returns(ships.Where(s => s.Size == shipSize).ToArray); var game = new BattleShipGame(player1.Object, player2.Object); game.StarNewGame(); game.Shoot(); if (game.Attacker.Shooter == player1.Object) { player1.Verify(x => x.ReportLastShotResult(coordinates, expectedShotResult)); player2.Verify(x => x.ReportOponentsLastShotResult(coordinates, expectedShotResult)); } else { player2.Verify(x => x.ReportLastShotResult(coordinates, expectedShotResult)); player1.Verify(x => x.ReportOponentsLastShotResult(coordinates, expectedShotResult)); } }
public void ThrowsErrorWhenShotIsOutOfRange() { var player1 = new Mock <IBattleShipShooter>(); player1.Setup(x => x.Shoot()).Returns(() => new Coordinates('W', 3)); var game = new BattleShipGame(player1.Object, player1.Object); game.StarNewGame(); Assert.Throws <ArgumentException>(() => game.Shoot()); }
public void KeepsAttackerAfterHit() { var player1 = new Mock <IBattleShipShooter>(); var player2 = new Mock <IBattleShipShooter>(); var ships = new[] { new Ship('A', 1, 'A', 1) }; var coordinates = new Coordinates('A', 1); player1.Setup(x => x.PrepareShipsForNewBattle()).Returns(ships); player2.Setup(x => x.PrepareShipsForNewBattle()).Returns(ships); player1.Setup(x => x.Shoot()).Returns(coordinates); player2.Setup(x => x.Shoot()).Returns(coordinates); var game = new BattleShipGame(player1.Object, player2.Object); game.StarNewGame(); var attackerBefore = game.Attacker.Shooter; game.Shoot(); Assert.AreEqual(attackerBefore, game.Attacker.Shooter); }