예제 #1
0
        public void CreateNewGame_ZeroAmountOfPlayers_ExceptionExpected()
        {
            var input = new BingoGameCreationModel()
            {
                Name    = "Pearl Jam",
                Players = new List <PlayerModel>()
                {
                },
                Size = 3
            };

            Assert.Throws <ArgumentException>(() => _bingoGameLogic.CreateNewGame(input));
        }
예제 #2
0
        public void CreateNewGame_ZeroSize_ExceptionExpected()
        {
            var input = new BingoGameCreationModel()
            {
                Name    = "Pearl Jam",
                Players = new List <PlayerModel>()
                {
                    new PlayerModel()
                    {
                        Name = "Eddie Vedder"
                    },
                    new PlayerModel()
                    {
                        Name = "Mike McCready"
                    }
                },
                Size = 0
            };

            Assert.Throws <ArgumentException>(() => _bingoGameLogic.CreateNewGame(input));
        }
예제 #3
0
        public void CreateNewGame_TwoPlayers_Succeeds()
        {
            var input = new BingoGameCreationModel()
            {
                Name    = "Pearl Jam",
                Players = new List <PlayerModel>()
                {
                    new PlayerModel()
                    {
                        Name = "Eddie Vedder"
                    },
                    new PlayerModel()
                    {
                        Name = "Mike McCready"
                    }
                },
                Size = 3
            };

            _bingoCardLogicMock.Setup(logic => logic.GenerateBingoCard(It.IsAny <BingoCardCreationModel>())).Returns(new BingoCardModel()
            {
                Name = "Pearl Jam",
                Grid = new int?[][]
                {
                    new int?[] { 1, 2, 3 },
                    new int?[] { 4, 5, 6 },
                    new int?[] { 7, 8, 9 }
                }
            });

            _bingoNumberLogicMock.Setup(logic => logic.GetNextNumber()).Returns(1);

            var actual = _bingoGameLogic.CreateNewGame(input);

            Assert.Equal(2, actual.Players.Count());
            Assert.Equal("Eddie Vedder", actual.Players.First().Name);
            Assert.Equal(3, actual.Players.First().BingoCard.Grid.Length);
        }
예제 #4
0
        public BingoGameModel CreateNewGame(BingoGameCreationModel gameCreationModel)
        {
            if (gameCreationModel == null || string.IsNullOrWhiteSpace(gameCreationModel.Name) || gameCreationModel.Players.Count() <= 0 || gameCreationModel.Size <= 0)
            {
                throw new ArgumentException("No name for the game provided or invalid number of players or grid size");
            }

            foreach (var player in gameCreationModel.Players)
            {
                player.BingoCard = _bingoCardLogic.GenerateBingoCard(new BingoCardCreationModel()
                {
                    Name = player.Name,
                    IsCenterSquareFree = true,
                    Size = gameCreationModel.Size
                });
            }

            return(new BingoGameModel()
            {
                DrawnNumber = _bingoNumberLogic.GetNextNumber(),
                Players = gameCreationModel.Players
            });
        }
예제 #5
0
        public ActionResult CreateBingoGame([FromBody] BingoGameCreationModel gameCreationModel)
        {
            var bingoGameModel = _bingoGameLogic.CreateNewGame(gameCreationModel);

            return(Ok(bingoGameModel));
        }