Пример #1
0
        public void GetPotentialMovesTest()
        {
            // Associate
            PlayerTipsService playerTipsService = new PlayerTipsService();
            GetPlayerTips     getPlayerTips     = new GetPlayerTips
            {
                Board = new Int64[, ]
                {
                    { 0, 2, 0, 2, 0, 2, 0, 2 },
                    { 2, 0, 2, 0, 2, 0, 2, 0 },
                    { 0, 2, 0, 2, 0, 2, 0, 2 },
                    { 5, 0, 5, 0, 5, 0, 5, 0 },
                    { 0, 5, 0, 5, 0, 5, 0, 5 },
                    { 1, 0, 1, 0, 1, 0, 1, 0 },
                    { 0, 1, 0, 1, 0, 1, 0, 1 },
                    { 1, 0, 1, 0, 1, 0, 1, 0 },
                },
                TipFor = 1
            };

            // Act
            List <Piece> pieces = playerTipsService.GetPotentialMoves(getPlayerTips);

            // Assert
            Assert.AreEqual(4, pieces.Count);
        }
        public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req, ILogger log)
        {
            try
            {
                String        requestBody   = await new StreamReader(req.Body).ReadToEndAsync();
                GetPlayerTips getPlayerTips = JObject.Parse(requestBody).ToObject <GetPlayerTips>();

                IPlayerTipsService service        = new PlayerTipsService();
                List <Piece>       potentialMoves = service.GetPotentialMoves(getPlayerTips);

                return(new OkObjectResult(
                           new PlayersTipsResponse
                {
                    Successful = true,
                    PotentialMoves = potentialMoves
                }
                           ));
            }
            catch (Exception ex)
            {
                return(new BadRequestObjectResult(
                           new PlayersTipsResponse
                {
                    Successful = false,
                    ErrorMessage = ex.Message
                }
                           ));
            }
        }