示例#1
0
        public IActionResult makeMove([FromBody] BoardGameDTO gameDto)
        {
            BoardGame     game    = boardCreationService.createBoardGame(gameDto);
            Player        player  = playerCreationService.createPlayer(gameDto.cur);
            List <Player> players = playerCreationService.createPlayers(gameDto.players);

            return(ExecuteApiAction(() => new ApiResult <BoardGameDTO> {
                Model = gameService.processMove(game, player, players)
            }));
        }
        public void WillCallHandlerForEveryJObjectInTheArray()
        {
            List <JObject> jObjects = new List <JObject>();
            JObject        jObj     = new JObject();

            jObj.Add("type", 1000);
            jObj.Add("name", "");
            jObj.Add("colour", 100);
            jObj.Add("userId", 0);
            jObjects.Add(jObj);
            Mock <PlayerClassHandler> mockHandler = new Mock <PlayerClassHandler>();

            mockHandler.Setup(x => x.createPlayer((PlayerType)1000))
            .Returns(new Mock <Player>().Object)
            .Verifiable();
            service = new PlayerCreationService(mockHandler.Object);
            service.createPlayers(jObjects);
            mockHandler.Verify();
        }
        public void WIllCallTheHandlerOncePerJObject()
        {
            List <JObject> jObjects = new List <JObject>();
            JObject        jObj     = new JObject();

            jObj.Add("type", 1000);
            jObj.Add("name", "");
            jObj.Add("colour", 100);
            jObj.Add("userId", 0);
            jObjects.Add(jObj);
            jObjects.Add(jObj);
            Mock <PlayerClassHandler> mockHandler = new Mock <PlayerClassHandler>();

            mockHandler.Setup(x => x.createPlayer((PlayerType)1000))
            .Returns(new Mock <Player>().Object)
            .Verifiable();
            service = new PlayerCreationService(mockHandler.Object);
            service.createPlayers(jObjects);
            Assert.AreEqual(2, mockHandler.Invocations.Count);
        }
        public void WillSetTheNamesOfThePlayersInTheArray()
        {
            JObject player = new JObject();

            player.Add("type", 1000);
            player.Add("name", "some silly name");
            player.Add("colour", 10);
            player.Add("userId", 0);
            List <JObject> players = new List <JObject>
            {
                player
            };
            Mock <PlayerClassHandler> mockHandler = new Mock <PlayerClassHandler>();
            Mock <Player>             mockPlayer  = new Mock <Player>(MockBehavior.Loose);

            mockPlayer.Setup(x => x.setName("some silly name")).Verifiable();
            mockHandler.Setup(x => x.createPlayer((PlayerType)1000)).Returns(mockPlayer.Object);
            service = new PlayerCreationService(mockHandler.Object);
            service.createPlayers(players);
            mockPlayer.Verify();
        }
        public void WillReturnAnArrayOfWhatWasReturnedByTheHandler()
        {
            JObject player = new JObject();

            player.Add("type", 1000);
            player.Add("name", "");
            player.Add("colour", 100);
            player.Add("userId", 0);
            List <JObject> players = new List <JObject>
            {
                player
            };
            Mock <PlayerClassHandler> mockHandler = new Mock <PlayerClassHandler>();
            Mock <Player>             mockPlayer  = new Mock <Player>();

            mockHandler.Setup(x => x.createPlayer((PlayerType)1000))
            .Returns(mockPlayer.Object);
            service = new PlayerCreationService(mockHandler.Object);
            List <Player> result = service.createPlayers(players);

            Assert.IsTrue(result[0] == mockPlayer.Object);
        }