Пример #1
0
        public void TestAllShipsSink_BoardNotExist_ErrorResponse()
        {
            // Arrange
            var boardsManager        = new GameBoardsManager();
            var battleShipController = new BattleShipController(boardsManager);

            battleShipController.AddBoard();

            // Act
            var allShipsSinkResult = battleShipController.AllShipsSink(new BoardRequest()
            {
                BoardId = "fake id"
            }) as JsonResult;

            // Assert
            Assert.IsNotNull(allShipsSinkResult);
            Assert.AreEqual(StatusCodes.Status400BadRequest, allShipsSinkResult.StatusCode);
            var value = allShipsSinkResult.Value as ErrorResponse;

            Assert.IsNotNull(value);
        }
Пример #2
0
        public void TestAllShipsSink_AllShipsSinkResponse()
        {
            // Arrange
            var boardsManager        = new GameBoardsManager();
            var battleShipController = new BattleShipController(boardsManager);
            var result  = battleShipController.AddBoard() as JsonResult;
            var boardId = (result.Value as BoardResponse).BoardId;

            battleShipController.AddShip(new AddShipRequest()
            {
                BoardId      = boardId,
                HeadPosition =
                    new BattleShipStateTracker.Request.Coordinate()
                {
                    X = 5, Y = 6
                },
                TailPosition =
                    new BattleShipStateTracker.Request.Coordinate()
                {
                    X = 6, Y = 6
                }
            });

            battleShipController.AddShip(new AddShipRequest()
            {
                BoardId      = boardId,
                HeadPosition =
                    new BattleShipStateTracker.Request.Coordinate()
                {
                    X = 7, Y = 7
                },
                TailPosition =
                    new BattleShipStateTracker.Request.Coordinate()
                {
                    X = 7, Y = 6
                }
            });

            battleShipController.Attack(new AttackRequest()
            {
                BoardId  = boardId,
                Position = new BattleShipStateTracker.Request.Coordinate()
                {
                    X = 5, Y = 6
                }
            });

            battleShipController.Attack(new AttackRequest()
            {
                BoardId  = boardId,
                Position = new BattleShipStateTracker.Request.Coordinate()
                {
                    X = 6, Y = 6
                }
            });

            battleShipController.Attack(new AttackRequest()
            {
                BoardId  = boardId,
                Position = new BattleShipStateTracker.Request.Coordinate()
                {
                    X = 7, Y = 7
                }
            });

            battleShipController.Attack(new AttackRequest()
            {
                BoardId  = boardId,
                Position = new BattleShipStateTracker.Request.Coordinate()
                {
                    X = 7, Y = 6
                }
            });

            // Act
            var allShipsSinkResult = battleShipController.AllShipsSink(new BoardRequest()
            {
                BoardId = boardId
            }) as JsonResult;

            // Assert
            Assert.IsNotNull(allShipsSinkResult);
            Assert.AreEqual(StatusCodes.Status200OK, allShipsSinkResult.StatusCode);
            var value = allShipsSinkResult.Value as AllShipsSinkResponse;

            Assert.IsNotNull(value);
            Assert.IsTrue(value.AllShipsSink);
        }