コード例 #1
0
        public void CanGenerateObjects()
        {
            var testGenerators = new List <IGameObjectGenerator>()
            {
                new TeleporterGenerator() as IGameObjectGenerator
            };
            var storage   = new MemoryStorage();
            var testBoard = new Board
            {
                Id          = "2",
                Height      = 10,
                Width       = 10,
                GameObjects = new List <BaseGameObject> {
                },
                Bots        = new List <BoardBot> {
                    new BoardBot {
                        Name     = "Jane Jet",
                        Base     = new Position(6, 2),
                        Position = new Position(8, 0),
                        Score    = 5,
                        Diamonds = 0,
                    },
                    new BoardBot {
                        Name     = "indrif",
                        Base     = new Position(5, 8),
                        Position = new Position(0, 0),
                        Score    = 2,
                        Diamonds = 2,
                    },
                },
                Diamonds = new List <DiamondPosition>
                {
                }
            };

            storage.UpdateBoardAsync(testBoard).Wait();
            var generatorService = new GameObjectGeneratorService();

            Assert.NotEmpty(generatorService.getCurrentObjectGenerators());
            var controller = new BoardsController(storage,
                                                  null,
                                                  new DiamondGeneratorService()
                                                  , generatorService);
            //GameObject related tests here. TODO: Break out into separate test-cases.
            var boardResult = controller.GetBoardAsync("2").Result as OkObjectResult;
            var board       = boardResult?.Value as Board;

            Assert.NotEmpty(board.GameObjects);
            Assert.Equal(2,
                         board.GameObjects.Where(go =>
                                                 go.Name.Equals("Teleporter")).Count()
                         );
            Assert.Equal(1,
                         board.GameObjects.Where(go =>
                                                 go.Name.Equals("DiamondButton")).Count()
                         );
            Assert.False(
                board.GameObjects.Where(go =>
                                        go.Name.Equals("DiamondButton")).First().IsBlocking
                );
            List <DiamondPosition> oldDiamonds = new List <DiamondPosition>(board.Diamonds);

            board.GameObjects.Where(go =>
                                    go.Name.Equals("DiamondButton")).First().PerformInteraction(board, board.Bots.First(), Direction.North, new DiamondGeneratorService());
            Assert.False(oldDiamonds.SequenceEqual(board.Diamonds));
            Console.WriteLine("Regeneration in the nation!");
        }