Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public string AddShipToBoard(ShipModel shipToBePlaced, out bool isSuccessfullyPlaced)
        {
            var battleShip   = _battleShipFactory.GetBattleship(shipToBePlaced.Ship);
            var errorMessage = IsValidPosition(battleShip, shipToBePlaced);

            if (string.IsNullOrEmpty(errorMessage) && battleShip.PointsOccupied != null && battleShip.PointsOccupied.Count > 0)
            {
                ShipsOnBoard.Add(battleShip);
                isSuccessfullyPlaced = true;
                return("Ship successfully placed at requested position.");
            }
            isSuccessfullyPlaced = false;
            return(errorMessage);
        }