Example #1
0
 public ActionResult PostPlayer([FromBody] PlayerUniqueKey playerUniqueKey)
 {
     try
     {
         _repo.Create(playerUniqueKey);
         return(Ok(playerUniqueKey));
     }
     catch
     {
         return(BadRequest(playerUniqueKey));
     }
 }
Example #2
0
        public void TestPostPlayer()
        {
            PlayerRepository playerRepo       = new PlayerRepository(DatabaseDummy.DatabaseDummyCreate("TestPostPlayer"));
            PlayerController playerController = new PlayerController(playerRepo);
            PlayerUniqueKey  player           = new PlayerUniqueKey
            {
                PlayerName = "Andreea",
                UniqueKey  = 1
            };
            var actionResult = playerController.PostPlayer(player);

            Assert.IsNotType <BadRequestObjectResult>(actionResult);
        }
Example #3
0
        public void TestCreatePlayer()
        {
            PlayerRepository playerRepo = new PlayerRepository(DatabaseDummy.DatabaseDummyCreate("TestCreatePlayer"));
            PlayerUniqueKey  player     = new PlayerUniqueKey
            {
                PlayerName = "Paul",
                UniqueKey  = 1
            };

            try
            {
                playerRepo.Create(player);
                Assert.True(true);
            }
            catch
            {
                Assert.True(false);
            }
        }
Example #4
0
        public void Create(PlayerUniqueKey playerUniqueKey)
        {
            GameRepository gameRepo = new GameRepository(_context);
            Player         player   = new Player
            {
                PlayerName  = playerUniqueKey.PlayerName,
                PlayerScore = 0,
                GameroomId  = gameRepo.GetGameroomIdByUniqueKey(playerUniqueKey.UniqueKey)
            };

            var players = _context.Players.Where(a => a.GameroomId == player.GameroomId).ToList();

            if (Validation.CreatePlayerValidation(players, player))
            {
                _context.Players.Add(player);
                _context.SaveChanges();
            }
            else
            {
                throw new Exception("Nume deja existent!");
            }
        }