예제 #1
0
        public async Task BuildMazeLayout_WhenNoExceptionOccurs()
        {
            //arrange
            const int size      = 3;
            var       dimension = new Dimension(2, 0);
            var       roomTypes = new List <RoomType>()
            {
                new RoomType("Empty Room")
                {
                    Description   = "You see an empty room",
                    BehaviourType = null
                },
                new RoomType("Treasure Room")
                {
                    Description   = "You see the treasure and your eyes light up",
                    BehaviourType = new Behaviour(true)
                },
                new RoomType("Marsh")
                {
                    Description   = "You are looking at a heap of leaves and feel slightly elated.",
                    BehaviourType = new Behaviour(false)
                    {
                        TrapType =
                            new Trap
                            (
                                "marshes", " But you immediately begin to sink", 30
                            )
                    }
                },
                new RoomType("Desert")
                {
                    Description   = "You are looking at a desert with heaps of sands and feel thirsty.",
                    BehaviourType = new Behaviour(false)
                    {
                        TrapType =
                            new Trap
                            (
                                "marshes", " But you immediately begin to dehydrate", 20
                            )
                    }
                }
            };

            _mockRoomTyeRepo.Setup(rep => rep.GetAllRoomTypesAsync()).ReturnsAsync(roomTypes);

            //act
            var(mazeLayout, entryRoomId) = await _mazeService.BuildMazeLayoutAsync(size, dimension);

            //assert
            Assert.IsNotNull(entryRoomId);
            Assert.AreEqual(size, mazeLayout.GetLength(0));
            Assert.AreEqual(size, mazeLayout.GetLength(1));
        }
예제 #2
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));
        }