public void PlaceShips_FourFieldsShouldHaveValueBattleship() { const int numberOfFieldsTakenByBattleship = 4; const FieldValues fieldValueForBattleship = FieldValues.Battleship; ShipPlaceHelper.PlaceShips(_player); var counter = _board.Fields.Count(field => field.Value == fieldValueForBattleship); Assert.AreEqual(numberOfFieldsTakenByBattleship, counter); }
public void PlaceShips_AllIsHitPropertiesShouldBeSetToFalse() { var allIsHitPropertiesAreSetToFalse = true; ShipPlaceHelper.PlaceShips(_player); foreach (var field in _board.Fields.Where(field => field.IsHit)) { allIsHitPropertiesAreSetToFalse = false; } Assert.True(allIsHitPropertiesAreSetToFalse); }
public async Task <ActionResult <Board> > PutShips([FromRoute] int id, [FromBody] Player player) { var board = await _context.Boards.FindAsync(id); player = await _context.Players.FindAsync(board.PlayerId); player.Board = board; board.Fields = await _context.Fields.Where(f => f.BoardId == board.Id).ToListAsync(); player.Ships = await _context.Ships.Where(s => s.PlayerId == player.Id).ToListAsync(); if (id != board.Id) { return(BadRequest()); } // Select fields to place ship ShipPlaceHelper.PlaceShips(player); _context.Entry(player).State = EntityState.Modified; _context.Entry(board).State = EntityState.Modified; foreach (var field in board.Fields) { _context.Entry(field).State = EntityState.Modified; } foreach (var ship in player.Ships) { _context.Entry(ship).State = EntityState.Modified; } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PlayerExists(id)) { return(NotFound()); } else { throw; } } return(board); }
public void PlaceShips_FieldsShouldChangeValuesForAllShips() { const int numberOfFieldsTakenByShips = 18; var fieldValuesForShips = new[] { FieldValues.Battleship, FieldValues.Carrier, FieldValues.Cruiser, FieldValues.Destroyer, FieldValues.Submarine, FieldValues.PatrolBoat, FieldValues.TacticalBoat }; ShipPlaceHelper.PlaceShips(_player); var counter = _board.Fields.Count(field => fieldValuesForShips.Contains(field.Value)); Assert.AreEqual(numberOfFieldsTakenByShips, counter); }