Esempio n. 1
0
        public async Task <IHttpActionResult> BuildSquareMazeAsync(int size)
        {
            if (size <= 1)
            {
                return(BadRequest("Provided size is invalid. The value should be greater or equal to 2"));
            }

            var entryRoomDimension = await _mazeIntegrationService.SetEntranceRoomAsync(size);

            if (entryRoomDimension == null)
            {
                return(BadRequest("Some Error occurred while creating the maze."));
            }

            var(mazeLayout, entryRoomId) = await _mazeIntegrationService.BuildMazeLayoutAsync(size, entryRoomDimension);

            if (mazeLayout == null || entryRoomId == null)
            {
                return(BadRequest("Some Error occurred while creating the maze."));
            }

            var result = await _mazeIntegrationService.SaveMazeAsync(
                new Maze(mazeLayout, Convert.ToInt32(entryRoomId)));

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }
            var mazeResource = _mapper.Map <Maze, MazeResource>(result.Maze);

            return(Ok(mazeResource));
        }
Esempio n. 2
0
        public async Task SetEntranceRoom_WhenNoExceptionOccurs()
        {
            //arrange
            const int size = 3;

            //act
            var entryRoomDimension = await _mazeService.SetEntranceRoomAsync(size);

            //assert
            Assert.IsNotNull(entryRoomDimension);
        }