public void CreateNewSinglePlayerGame_WithGameSettingsProvided_ShouldCreateASinglePlayerGameAndReturnIt() { //Arrange GameSettings settings = new GameSettingsBuilder().Build(); Guid createdGameId = Guid.NewGuid(); var createdGameInfoMock = new Mock <IGameInfo>(); createdGameInfoMock.SetupGet(gi => gi.Id).Returns(createdGameId); _gameServiceMock.Setup(service => service.CreateGameForUser(It.IsAny <GameSettings>(), It.IsAny <User>())) .Returns(createdGameInfoMock.Object); //Act var result = _controller.CreateNewSinglePlayerGame(settings).Result as CreatedAtActionResult; //Assert Assert.That(result, Is.Not.Null, "An instance of 'CreatedAtActionResult' should be returned."); _userManagerMock.Verify(manager => manager.GetUserAsync(It.IsAny <ClaimsPrincipal>()), Times.Once, "The 'GetUserAsync' of the UserManager is not called"); _gameServiceMock.Verify(service => service.CreateGameForUser(settings, _loggedInUser), Times.Once, "The 'CreateGameForUser' method of the IGameService is not called correctly"); Assert.That(result.ActionName, Is.EqualTo(nameof(GameController.GetGameInfo)), "The 'CreatedAtActionResult' does not refer to the right action."); Assert.That(result.RouteValues["id"], Is.EqualTo(createdGameId), "The 'CreatedAtActionResult' does not refer to the right game id."); Assert.That(result.Value, Is.EqualTo(createdGameInfoMock.Object), "The 'CreatedAtActionResult' does not hold the correct gameInfo object."); }
public void EXTRA_CreateFromGame_ShouldNotShowSunkenShipsOfOpponentIfSunkenShipsDoNotNeedToBeReported() { //Arrange IPlayer player = new PlayerBuilder().WithFleetPositionedOnGrid(true).Build(); IPlayer opponent = new PlayerBuilder().WithFleetPositionedOnGrid(true).Build(); var settings = new GameSettingsBuilder().WithMustReportSunkenShip(false).Build(); var game = new GameBuilder().WithPlayers(player, opponent).WithSettings(settings).Build(); IList <IShipInfo> opponentShipInfos = new List <IShipInfo> { new Mock <IShipInfo>().Object }; _shipInfoFactoryMock.Setup(f => f.CreateMultipleFromSunkenShipsOfFleet(It.IsAny <Fleet>())).Returns(opponentShipInfos); //Act IGameInfo gameInfo = _factory.CreateFromGame(game, player.Id); //Assert Assert.That(gameInfo, Is.Not.Null, "No instance of a class that implements IGame is returned."); Assert.That(gameInfo.SunkenOpponentShips, Is.Not.Null, "SunkenOpponentShips must be an empty list."); Assert.That(gameInfo.SunkenOpponentShips.Count, Is.Zero, "SunkenOpponentShips must be an empty list."); _shipInfoFactoryMock.Verify(f => f.CreateMultipleFromSunkenShipsOfFleet(It.IsAny <Fleet>()), Times.Never, "CreateMultipleFromSunkenShipsOfFleet should not be called when sunken ships do not need to be reported."); }
public void MoveTurtle_WhenMoveEmptyTile_ReturnInDanger() { var gameSettings = new GameSettingsBuilder() .Build(); var sut = new BoardController(gameSettings); var result = sut.MoveTurtle(); Assert.Equal(MovesResultPossibilities.InDanger, result); }
private TurtleGame GetTurtleGame(IResultReporter resultReporter) { var gameSettings = new GameSettingsBuilder().Build(); IBoardController boardController = new BoardController(gameSettings); ISequencesRetriever sequencesRetriever = new InMemorySequenceRetriever(); ISequenceController sequenceController = new SequenceController(sequencesRetriever); return(new TurtleGame(boardController, sequenceController, resultReporter)); }
public void Constructor_GivenValidGameSettings_ShouldSetupExit() { var gameSettings = new GameSettingsBuilder().Build(); var sut = new BoardController(gameSettings); var result = sut.GetTiles(); var exitTile = result[(int)gameSettings.ExitPoint.X, (int)gameSettings.ExitPoint.Y]; Assert.IsType <ExitTile>(exitTile); }
public void GetResult_WhenTurtleNotInExit_ShouldReturnInDanger() { var gameSettings = new GameSettingsBuilder() .Build(); var sut = new BoardController(gameSettings); var result = sut.GetResult(); Assert.Equal(MovesResultPossibilities.InDanger, result); }
public void MoveTurtle_WhenMoveToMine_ReturnMineHit() { var gameSettings = new GameSettingsBuilder() .WithStartingPositionDirection(Directions.East) .Build(); var sut = new BoardController(gameSettings); var result = sut.MoveTurtle(); Assert.Equal(MovesResultPossibilities.MineHit, result); }
public void Constructor_GivenValidGameSettings_ShouldCreateTiles() { var gameSettings = new GameSettingsBuilder().Build(); var sut = new BoardController(gameSettings); var result = sut.GetTiles(); Assert.NotNull(result); Assert.Equal(gameSettings.BoardSize.N, result.GetLength(0)); Assert.Equal(gameSettings.BoardSize.M, result.GetLength(1)); }
public void CreateFromGame_UsesAGameToGetTheInfoFromThePerspectiveOfThePlayer() { //Arrange var settings = new GameSettingsBuilder().WithMustReportSunkenShip(true).Build(); Mock <IGame> gameMock = new GameBuilder().WithSettings(settings).BuildMock(); IGame game = gameMock.Object; IGridInfo expectedPlayerGridInfo = new Mock <IGridInfo>().Object; IGridInfo expectedOpponentGridInfo = new Mock <IGridInfo>().Object; _gridInfoFactoryMock.Setup(f => f.CreateFromGrid(game.Player1.Grid)).Returns(expectedPlayerGridInfo); _gridInfoFactoryMock.Setup(f => f.CreateFromGrid(game.Player2.Grid)).Returns(expectedOpponentGridInfo); IList <IShipInfo> expectedPlayerShipInfos = new List <IShipInfo>(); _shipInfoFactoryMock.Setup(f => f.CreateMultipleFromFleet(game.Player1.Fleet)).Returns(expectedPlayerShipInfos); IList <IShipInfo> expectedOpponentShipInfos = new List <IShipInfo>(); _shipInfoFactoryMock.Setup(f => f.CreateMultipleFromSunkenShipsOfFleet(game.Player2.Fleet)).Returns(expectedOpponentShipInfos); //Act IGameInfo gameInfo = _factory.CreateFromGame(game, game.Player1.Id); //Assert Assert.That(gameInfo, Is.Not.Null, "No instance of a class that implements IGame is returned."); Assert.That(gameInfo.Id, Is.EqualTo(game.Id), "The Id should be the Id of the game."); gameMock.Verify(g => g.GetPlayerById(game.Player1.Id), Times.Once, "The player should be retrieved using the GetPlayerById method of the game correctly."); Assert.That(gameInfo.IsReadyToStart, Is.EqualTo(game.Player1.Fleet.IsPositionedOnGrid && game.Player2.Fleet.IsPositionedOnGrid), "IsReadyToStart must be true when both the player fleet as the opponent fleet is positioned on the grid."); Assert.That(gameInfo.HasBombsLoaded, Is.EqualTo(game.Player1.HasBombsLoaded), "HasBombsLoaded should be equal to HasBombsLoaded of the player"); Assert.That(gameInfo.OwnGrid, Is.SameAs(expectedPlayerGridInfo), "The OwnGrid should be the instance returned by the IGridInfoFactory. " + "The IGridInfoFactory should create the info from the Grid of the player."); Assert.That(gameInfo.OwnShips, Is.SameAs(expectedPlayerShipInfos), "The OwnShips should be the list returned by the IShipInfoFactory. " + "The IShipInfoFactory should create the list from all the ships of the player."); gameMock.Verify(g => g.GetOpponent(game.Player1), Times.Once, "The opponent should be retrieved using the GetOpponent method of the game correctly."); Assert.That(gameInfo.OpponentGrid, Is.SameAs(expectedOpponentGridInfo), "The OpponentGrid should be the instance returned by the IGridInfoFactory. " + "The IGridInfoFactory should create the info from the Grid of the opponent."); Assert.That(gameInfo.SunkenOpponentShips, Is.SameAs(expectedOpponentShipInfos), "The SunkenOpponentShips should be the list returned by the IShipInfoFactory. " + "The IShipInfoFactory should create the list from all the sunken ships of the opponent."); }
public void Constructor_ShouldSetupTurtle() { var gameSettings = new GameSettingsBuilder().Build(); var sut = new BoardController(gameSettings); var result = sut.GetTurtle(); var turtlePosition = result.GetPosition(); Assert.NotNull(result); Assert.Equal(gameSettings.StartingPosition.Direction, result.Direction); Assert.Equal(gameSettings.StartingPosition.X, turtlePosition.X); Assert.Equal(gameSettings.StartingPosition.Y, turtlePosition.Y); }
public void Constructor_GivenValidGameSettings_ShouldSetupMines() { var gameSettings = new GameSettingsBuilder().Build(); var sut = new BoardController(gameSettings); var result = sut.GetTiles(); var firstMine = result[(int)gameSettings.Mines[0].X, (int)gameSettings.Mines[0].Y]; var secondMine = result[(int)gameSettings.Mines[1].X, (int)gameSettings.Mines[1].Y]; var thirdMine = result[(int)gameSettings.Mines[2].X, (int)gameSettings.Mines[2].Y]; Assert.IsType <MineTile>(firstMine); Assert.IsType <MineTile>(secondMine); Assert.IsType <MineTile>(thirdMine); }
public void MoveTurtle_ShouldMoveTurtle() { var gameSettings = new GameSettingsBuilder() .Build(); var sut = new BoardController(gameSettings); sut.MoveTurtle(); var result = sut.GetTurtle(); var turtlePosition = result.GetPosition(); Assert.Equal(gameSettings.StartingPosition.Direction, result.Direction); Assert.Equal(gameSettings.StartingPosition.X, turtlePosition.X); Assert.Equal(gameSettings.StartingPosition.Y + 1, turtlePosition.Y); }
public void RotateTurtle_ShouldRotateTurtle() { var initialDirection = Directions.North; var expectedDirection = Directions.East; var gameSettings = new GameSettingsBuilder() .WithStartingPositionDirection(initialDirection) .Build(); var sut = new BoardController(gameSettings); sut.RotateTurtle(); var result = sut.GetTurtle(); Assert.Equal(expectedDirection, result.Direction); }
public void MoveTurtle_WhenMoveToMine_ReturnSuccess() { var exitPoint = new Point { X = 0, Y = 1 }; var gameSettings = new GameSettingsBuilder() .WithStartingPositionDirection(Directions.North) .WithStartingPositionX(0) .WithStartingPositionY(0) .WithExitPoint(exitPoint) .Build(); var sut = new BoardController(gameSettings); var result = sut.MoveTurtle(); Assert.Equal(MovesResultPossibilities.Success, result); }