public void AddShipToBoard_Should_Fail_And_Not_Add_Ship_To_Board_When_Collide_With_Another_Ship_On_Board() { //arrange bool isSuccess = false; StateTrackingManager.ShipsOnBoard = SetupShipsOnBoard(); var shipsOnBoardCount = StateTrackingManager.ShipsOnBoard.Count; var shipModel = GetShipModel(ShipType.Battleship, ShipOrientation.South); var battleShip = Substitute.For <IBattleship>(); _sutBattleShipFactory.GetBattleship(ShipType.Battleship).Returns(battleShip); var pointRequested = Mapper.Map <ShipPoint>(shipModel.StartPoint); var pointOccupied = StateTrackingManager.ShipsOnBoard?.FirstOrDefault().PointsOccupied; battleShip.GetPointsOccupiedOnBoard(Arg.Any <ShipPoint>(), Arg.Any <ShipOrientation>()).Returns(pointOccupied); //act var message = _sutStateTrackingManager.AddShipToBoard(shipModel, out isSuccess); var shipsOnBoardCountAfterPlacingNew = StateTrackingManager.ShipsOnBoard.Count; //assert Assert.False(isSuccess); Assert.Equal("Selected ship position and orientation collectively makes ship collide with another ship on board.", message); Assert.Equal(shipsOnBoardCountAfterPlacingNew, shipsOnBoardCount); }
public IHttpActionResult PlaceShip(ShipModel shipModel) { if (ModelState.IsValid) { bool isSuccessfullyPlaced = false; var result = _stateTrackingManager.AddShipToBoard(shipModel, out isSuccessfullyPlaced); if (isSuccessfullyPlaced) { return(Ok(result)); } else { return(BadRequest(result)); } } return(BadRequest(ModelState)); }